Re: Japanese strings get mangled when sent from VB6 to VC++ dll

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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:

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

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.

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

.



Relevant Pages

  • still working with utf8
    ... OK, I sorted out what the deal is with charsets, Encode, utf8 and other goodies. ... After I decode_base64 them and decodethem I can print out something that looks exactly like japanese characters. ... But I guess this string of spaghetti is actually a language where one character as represented in a unicode terminal is actually one 'word' according to the perl definition of a word... ... I guess my question is, for CJK languages, should I expect the notion of using a regex like \w+ to pick up entire strings of text instead of discrete words like latin based languages? ...
    (perl.beginners)
  • Re: parse a textfile containing japanese characters
    ... tej wrote: ... i ve to parse all japanese characters of a text file ... I am not able to search occurence of any japanese character in given ... couldn't you write a Japanese search string in your ...
    (comp.lang.java.programmer)
  • convert string from Unicode to ISO-2022-JP
    ... converting the string from Unicode to ISO-2022-JP. ... ISO-2022-JP a subset of Unicode? ... Someone told me that some common Japanese characters would become? ...
    (comp.software.international)
  • Re: parse a textfile containing japanese characters
    ... i ve to parse all japanese characters of a text file ... I am not able to search occurence of any japanese character in given ... string. ...
    (comp.lang.java.programmer)
  • Re: Did Borland doing well in Q4? Listen to the Earning CC
    ... AS an ANSI application you will need to change all "String" ... declarations to "ANSIString" (and Char to ANSIChar and PChar to ... Only THEN can you start thinking about how Unicode is best ... Even the specifically "ANSI" FS routines do not use ...
    (borland.public.delphi.non-technical)