我一直在考慮嘗試使用實現OPOS服務對象的C#編寫COM對象。我使用Automation和MFC在C++中完成了它,並沒有太困難。所以我被困在試圖轉換它的一種方法上。我會排除接口中的其他方法,因爲它們很簡單(或者我希望)。如何將IDispatch *置於託管代碼
[id(6), helpstring("method OpenService")]
LONG OpenService(BSTR lpclDevClass, BSTR lpclDevName, IDispatch* lpDispatch);
我的C#代碼看起來像這樣到目前爲止,但我堅持在OpenService。
[ComVisible(true)]
[Guid("76F8309C-3837-4065-960F-BE156383896D")]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
public class IErtMSR
{
[DispId(1)]
int COFreezeEvents([MarshalAs(UnmanagedType.VariantBool)] bool Freeze);
[DispId(2)]
int GetPropertyNumber([In] int lPropIndex);
[DispId(3)]
void SetPropertyNumber([In] int lPropIndex, [In] int nNewValue);
[DispId(4), MarshalAs(UnmanagedType.BStr)]
string GetPropertyString([In] int lPropIndex);
[DispId(5)]
void SetPropertyString([In, MarshalAs(UnmanagedType.BStr)] string StringData);
[DispId(6)]
int OpenService([In, MarshalAs(UnmanagedType.BStr)] string lpclDevClass, [In, MarshalAs(UnmanagedType.BStr)] string lpclDevName, IDispatch* lpDispatch);
//...the rest of the 24 methods.
}
正如您所見,我不知道要爲IDispatch *放置什麼。我在這種情況下使用什麼?
我想通了。我不得不創建一個IDispatch方法(我發現Hans Persant有這個可用..)現在我只是要弄清楚如何從它調用一個事件.. :) –