Solved

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

Posted on 2001-06-23
6
454 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
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…

726 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