Solved

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

Posted on 2001-06-23
6
449 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

791 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