首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将IDis修补程序*放入托管代码中

如何将IDis修补程序*放入托管代码中
EN

Stack Overflow用户
提问于 2014-01-31 05:00:10
回答 1查看 1.2K关注 0票数 2

我一直在考虑使用实现的C#来编写COM对象。我在C++中使用自动化和MFC做过这件事,这并不太困难。所以我被困在其中一种方法上,试图把它转换过来。我将排除接口中的其他方法,因为它们是直接向前的(至少我希望如此)。

代码语言:javascript
复制
[id(6), helpstring("method OpenService")]
LONG OpenService(BSTR lpclDevClass, BSTR lpclDevName, IDispatch* lpDispatch);

到目前为止,我的C#代码看起来是这样的,但是我被困在了OpenService上。

代码语言:javascript
复制
[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.
}

正如您所看到的,我不知道该为IDis补丁写什么*。我在这个箱子里用什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-31 06:36:19

您不需要为COM IDispatch创建托管定义或显式实现其成员。该框架对此有内置的支持。只需像这样声明您的OpenService

代码语言:javascript
复制
[DispId(6)]
int OpenService(
    [In, MarshalAs(UnmanagedType.BStr)] string lpclDevClass, 
    [In, MarshalAs(UnmanagedType.BStr)] string lpclDevName, 
    [In, MarshalAs(UnmanagedType.IDispatch] object lpDispatch);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21472700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档