I have a com objects function having a C# return type of string
string getData();
In my C++ code I have
cpi->getData();
where cpi is a pointer to an instance of com object.
How do I get this returned data in a C++ variable?
—edit—
I also have another function called handlepacket(char* data).
How do I pass this cpi->getData returned string data to this function?
A C++ code piece will be very helpful.
The COM string type is
BSTR. It has non-trivial memory-management rules. Luckily, the_bstr_tC++ class wrapsBSTRand gives you reasonable semantics. So,_bstr_t foo = cpi->getData();is the easiest way.You can pass this string to a
handlepacket(wchar_t* data). The COM string type is Unicode text, not 8 bits data. If yourgetDatafunction returns 8 bits data, it should have returned an array of bytes.