?
Solved

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

Posted on 2001-06-23
6
Medium Priority
?
469 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 200 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

770 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