P / Invoke is only supported for C. YMMV interfaces if you are trying to get it to talk to C ++ constructs. In this case, you will need to find out what exactly the C ++ compiler translated the link to, since C ++ compilers can implement this in any way.
If you want to be able to P / Invoke this, but don’t want to use pointer semantics on the call site, you can do something like:
int Activation::Activate(int *p_NumActivated, char **p_EventsActivated) { return Activate(p_NumActivated, *p_EventsActivated); } int Activation::Activate(int *p_NumActivated, char *&p_EventsActivated) { char *pTemp = "Hello"; p_EventsActivated = pTemp; *p_NumActivated = 1; return 0; }
which provides a simple pointer, you should be able to more simply P / Invoke.
Please note, however, that any line you marshal it will probably not be modified by the corresponding function. This is because .NET strings are UTF-16 strings, and the C ++ function uses ASCII strings that are not fully compatible with each other. You may have to convert the .NET string to ASCII, marshal it, marshal it back, and then convert it back to UTF-16.
Oh, the last: as it is written, you will need to pass a reference to the Activation object for this function to work. The position of this argument will depend on the C ++ compiler.
source share