Your problem (besides being able to copy to memory inside _bstr_t) is that you are converting UNICODE BSTR to ANSI char *.
You can use USES_CONVERSION macros that do the conversion on the stack, so they can be faster. Alternatively, save the BSTR value as unicode, if possible.
to convert:
USES_CONVERSION; char* p = strdup(OLE2A(var.bstrVal));
remember - the line returned from OLE2A (and its macros with the sister) returns the line allocated on the stack - returns from the enclosing area, and you have a garbage line if you do not copy it (and, ultimately, free it) p >
source share