Solved

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

Posted on 2001-06-23
6
438 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
ID: 6222263
Why do you need to work with unicode strings?
0
 
LVL 4

Accepted Solution

by:
mcmahon_s earned 50 total points
ID: 6222289
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
ID: 6222291
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:khampton
ID: 6222416
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
ID: 7139732
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
ID: 7178633
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vb6 programatically bring window to front 8 65
vb6 connector to mongodb 2 53
Please explain "Multi-Tenant Services" 5 65
How do ASP.NET and MVC work together? 4 30
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…

861 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

25 Experts available now in Live!

Get 1:1 Help Now