Are you using a C++ dll with a declare statement? (not as a com object).

I don't think you can return a unicode string . VB converts the string to ASCIIZ going into the C++ dll and expects an ASCIIZ string coming back.

The way I have resolved similar issues in the past was to pass the string as a BYTE array..but that was using non-unicode. I used chr() to rebuld the string, but that does not handle unicode (I don't think). Maybe you can try an Integer array.

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Visual Basic works with BSTR types. You must declare this type in your c++ program if you want to pass byref. Note: there are rules regarding BSTR types -- you could produce memory leaks or worse if you don't implement them correctly.

BUT -- if you declare your c++ routine in your VB program, (ie: just like an API routine) you can use byval and the string will be sent as a char type. Your C++ program can work with it and return it and VB will convert it back to BSTR.

You can also use variants in your c++ routine and pass it your string. Its slower but easy. Read the rules.