|
Subject:
|
Char in VC and String in VB ???
|
|
Posted By:
|
tranhung
|
Post Date:
|
2/14/2004 10:21:22 PM
|
Hi Everybody when i write DLL in VC Code: Void __stdcall WGS84TOVN99( char inStr[100], int j, char outStr[100] ); { // Some command } I call it in VB:  Public Declare Function WGS84TOVN99 Lib Path+"\.dll" (ByRef InputLine As String, ByVal i As Long, outputLine As String) Dim inStr as String instr="My input String" Dim outStr as String Call WGS84TOVN99(inStr,1,outStr) But when I debug in VC inStr not correct, that why program dump. Can you help me Thanks
|
|
Reply By:
|
nikolai
|
Reply Date:
|
2/16/2004 2:19:42 PM
|
I think you need to use the BSTR type for strings in C/C++. BSTR is a Binary-Safe Unicode string. The length of the string is encoded in the first couple bytes of the string. That means that you can't use a fixed-size character array.
chars are 1-byte. Unicode (wide) characters are two bytes.
The string "Hello" as a char array will look like this (byte representation in hex):
48 65 6c 6c 6f 00 00 00 00 ... 00
| | | | | | | | | |
'h' 'e' 'l' 'l' 'o' '\0' '\0' '\0' '\0' ... '\0'
The same string as a BSTR will look like this:
00 00 00 05 00 48 00 65 00 6c 00 6c 00 6f
\_________/ \___/ \___/ \___/ \___/ \___/
(length) 'H' 'e' 'l' 'l' 'o'
Take care,
Nik http://www.bigaction.org/
|