Reputation: 303
I need to modify application that is written on Delphi and C++ and uses COM. And I've seen quite often that COM wrappers always use WideString and BSTR, even though in the end dll that is used works with plain char*. So it's impossible to communicate between COM objects without unicode strings? Some links for further reading on the topic is very appreciated.
Upvotes: 1
Views: 146
Reputation: 598434
To pass around an 8-bit char
string in COM, you can either:
use SysAllocStringByteLen()
to create a binary BSTR
that holds the raw char
characters as-is. The receiver can then copy the char
characters as-is from the BSTR
.
use SafeArrayCreate()
/SafeArrayCreateVector()
to create a SAFEARRAY
holding VT_UI8
elements, and then you can copy the char
characters as-is into the array. You can put the SAFEARRAY
inside of a VARIANT
, if needed.
wrap the char
characters inside of an IStream
, such as from CreateStreamOnHGlobal()
or SHCreateMemStream()
.
Upvotes: 5