我一直在考虑尝试使用 C# 编写一个实现 OPOS 服务对象的 COM 对象。我已经使用自动化和 MFC 在 C++ 中完成了它,这并不太困难。所以我坚持尝试将其转换为一种方法。我将排除界面中的其他方法,因为它们很简单(或者我希望如此)。
[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* 添加什么。在这种情况下我该用什么?
您不需要为 COM 创建托管定义IDispatch
或明确实施其成员。该框架对其有内置支持。只需声明您的OpenService
像这样:
[DispId(6)]
int OpenService(
[In, MarshalAs(UnmanagedType.BStr)] string lpclDevClass,
[In, MarshalAs(UnmanagedType.BStr)] string lpclDevName,
[In, MarshalAs(UnmanagedType.IDispatch] object lpDispatch);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)