0

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#?

  • You've shown us *no* code - what do you expect us to suggest? – Damien_The_Unbeliever Jul 15 '13 at 06:34
  • Where do you want to Export the List? – Mehrdad Kamelzadeh Jul 15 '13 at 06:41
  • There are allot of question on this issue: [C# exposing class to COM - Generic Collections][1] [What are alternatives to generic collections for COM Interop?][2] [1]: http://stackoverflow.com/questions/1862497/c-sharp-exposing-class-to-com-generic-collections [2]: http://stackoverflow.com/questions/269581/what-are-alternatives-to-generic-collections-for-com-interop – Beno Jul 15 '13 at 06:43
  • @Beno, take a look at my update.Want an insight into the SAFEARRAY thingy – Pratik Pattanayak Jul 15 '13 at 12:47

1 Answers1

2

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

Community
  • 1
  • 1
Kyle
  • 1,366
  • 2
  • 16
  • 28
  • This is precisely what I did! but wanted to know if any other shortcut? cause I am finding difficult in using SAFARRAY(add items,modify items) that gets formed in tlh file. – Pratik Pattanayak Jul 15 '13 at 07:07
  • How to create a SAFEARRAY of objects. I saw the example of SAFEARRAY of primitive datatypes?Any links? – Pratik Pattanayak Jul 15 '13 at 09:12