Solved

How to pass a unicode string from a c++ dll to Visual basic .

Posted on 2001-06-23
6
432 Views
Last Modified: 2013-11-25

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?


0
Comment
Question by:ShailendraSingh
6 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Why do you need to work with unicode strings?
0
 
LVL 4

Accepted Solution

by:
mcmahon_s earned 50 total points
Comment Utility
You could convert the string back to UNICODE by using

StrConv(YourString, vbUnicode)

I have seen it done as a byte array (but can't place my hands on it) good luck.
0
 
LVL 3

Expert Comment

by:rmichels
Comment Utility
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.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 1

Expert Comment

by:khampton
Comment Utility
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!
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
0
 
LVL 1

Expert Comment

by:Computer101
Comment Utility
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now