ShailendraSingh
asked on
How to pass a unicode string from a c++ dll to Visual basic .
i m able to pass a string(char*) from a c++ dll to visual basic but unable to pass a unicode string(wchar_t *).
when i m passing a wchar_t* to visual basic it is converting it into a simple string type not as unicode string.
how do i resolve this issue?
Why do you need to work with unicode strings?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
In COM land, you pass strings via BSTRINGs..they handle unicode.
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.
In COM land, you pass strings via BSTRINGs..they handle unicode.
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.
Good luck!
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.
Good luck!
Hi ShailendraSingh,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:
Accept mcmahon_s@devx's comment(s) as an answer.
ShailendraSingh, if you think your question was not answered at all or if you need help, you can simply post a new comment here. Community Support moderators will follow up.
EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:
Accept mcmahon_s@devx's comment(s) as an answer.
ShailendraSingh, if you think your question was not answered at all or if you need help, you can simply post a new comment here. Community Support moderators will follow up.
EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
Comment from expert accepted as answer
Computer101
E-E Moderator
Computer101
E-E Moderator