How to deal with special types ( Enums,Pointers,etc. ) when using ActiveX COM?

-1

Ok let's say I have a C++ application which use a dotNet COM library. My function body is like :

bool ACSharpFunction(SomeEnum enumData, IntPtr ptrData){...}

Then in C++ side I create my values like :

    auto FuncArgs = SafeArrayCreateVector(VT_VARIANT, 0, 2);

    LONG indexPtr1= 0;
    LONG indexPtr2= 1;

    variant_t   dataEnum = variant_t(myenumvalue::showinleft); // type is regular C enum
    variant_t   d_type = variant_t(mypointervalue); // type is intptr_t


    hr = SafeArrayPutElement(FuncArgs , &indexPtr1, &dataEnum );
    hr = SafeArrayPutElement(FuncArgs , &indexPtr2, &d_type );

    ...

Then i use pass FuncArgs to ActiveX object and I get parameter missing member error (HRESULT : 0x80131512).

There's a hack to fix this issue by changing C# function body to :

bool ACSharpFunction(int enumData, long ptrData){...}

And then recover enum and pointer from int and long, it works fine but I prefer to do it in a proper and standard way.

The Question is : How can I make it work with Enum and IntPtr without changing my function body?

c#
c++
com
activex
asked on Stack Overflow Jun 26, 2020 by PinnedObject

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0