std::string to SAFEARRAY*

in C#, I wrote doSomething(char[] zzz){/*...*/}

From C++, I am trying to call C#.

How to convert std::string and char* to SAFEARRAY*?
look up what SAFEARRAY really is and re-create it.

it looks like this, according to google:

typedef struct tagSAFEARRAY {
USHORT cDims;
USHORT fFeatures;
ULONG cbElements;
ULONG cLocks;
PVOID pvData;
SAFEARRAYBOUND rgsabound[1];
} SAFEARRAY, *LPSAFEARRAY;

so you need to build a class like that in c++
you will have to figure out what pvoid is (void* probably) and whatever a safearraybound thing is... (could be anything from another struct of more structs to just an int)
(ironically, it looks like the C# object was written in C).

at an educated guess, you would shovel the char* data from string or char* into the pvoid and fill out the rest according to the documentation.

that could be a lot of trouble; talking between the programs you have to make sure the objects align exactly in size etc. (don't forget endian as well if crossing OS/machine types).

it may be much easier to just pass the char* data across and let the C# code build the safe array itself, or pull the pvoid /data out of the safearray and send just that (and maybe the length?) to the C++ code.
Last edited on
Topic archived. No new replies allowed.