Export generic code (List<T>)to COM [duplicate]

北慕城南 提交于 2020-01-22 02:58:05

问题


COM doesn't support generics?What would be the best way to replicate this List<T> so that it's COM visible in the tlh file. EDIT:: c#::

[ComVisible(true)]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    [Guid("FA677671-5E26-4307-AD2B-19BF1E7AFF8B")]
    public interface IEvents
    {
        IEvents[] CreateListeners();
    }

in C++ i have,

CComSafeArray<CSharp::IEvents> ppSA;
    pInterface->CreateListeners(ppSA->GetSafeArrayPtr());

My question what i should do in this Create instance function so asto replicate this statement List evt=new List(); in the managed c#?


回答1:


Correct, generic types are not supported:

The COM model does not support the concept of generic types. Consequently, generic types cannot be used directly for COM interop.

http://msdn.microsoft.com/en-us/library/ms229590.aspx

Perhaps this is the place to start:

C# exposing class to COM - Generic Collections



来源:https://stackoverflow.com/questions/17648004/export-generic-code-listtto-com

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!