Re: Japanese strings get mangled when sent from VB6 to VC++ dll
- From: Sinna <news4sinna_NOSPAM@xxxxxxxxxx>
- Date: Fri, 27 Jul 2007 08:36:30 +0200
deveasy wrote:
My VB6 program sends some strings to a VC++ dll. The program works fine for English, German et al. But it has problems with *some* Japanese characters. Please see two examples below:VB will convert any String parameter from Unicode to ANSI before passing it to an external function. When you call StrConv(...) you convert a Unicode String to a 'UniUniCode' String causing each character takes 4 bytes. No wonder then that the conversion fails.
Strings input from VB
ドラマに期待
を配布中
Strings obtained by C++ dll
ド䖁マに期䖁
䖁腍幅中
Here is the listing of the VB and C++ code. I'd appreciate any pointers to fix this problem.
Thanks,
V.
VB code:
Declare Function DoStuff Lib "Test.dll" (ByVal strName As String) As Double
Public Function SendToDll(strName As String) As Double
SendToDll = DoStuff(StrConv(strName, vbUnicode))
End Function
C++ code:
Declaration:
double __stdcall DoStuff(TCHAR* name);
Definition:
double __stdcall DoStuff(TCHAR* name)
{
AfxMessageBox(name);
return 1;
}
In the def file, the DoStuff function is exported
To avoid VB converting strings to ANSI, you have to pass the StringPointer to the function: read ByVal StrPtr(strName).
Then your C++ function must accept a pointer to a BSTR. I can't give you code for this as I'm not an very experienced C++ programmer.
Tip: Google for 'pass string to DLL'
Sinna
.
- Follow-Ups:
- Re: Japanese strings get mangled when sent from VB6 to VC++ dll
- From: Tony Proctor
- Re: Japanese strings get mangled when sent from VB6 to VC++ dll
- Prev by Date: Re: Strange problem with PDW
- Next by Date: Re: Package and deploy
- Previous by thread: Re: Japanese strings get mangled when sent from VB6 to VC++ dll
- Next by thread: Re: Japanese strings get mangled when sent from VB6 to VC++ dll
- Index(es):
Relevant Pages
|