structure incompatibility between VB and VC++

M

Mohamed Fysal

Hi,

I have a major problem.

I am using a VB exe which is having a structure declared and it looks like
below


Public Type SCANNEDIBUTTNO
IButtonUserNumber As String * 32
End Type

Public Type BOOKINGIDPARAM
bkidno(14) As SCANNEDIBUTTNO
End Type

Public Type TRACKERMESSAGEINFO
bkidp As BOOKINGIDPARAM
End Type

And I have declared a varaible for TRACKERMESSAGEINFO as tmi

and the value for IButtonUserNumber is a Hex value which is stored as
follows:

textValue1 = 'EFABCD12'
textValue2 = 'EFABCD13'
textValue3 = 'EFABCD14'

Mid$(tmi.bkidp.bkidno(0).IButtonUserNumber, 1, Len(textValue1)) = textValue1
Mid$(tmi.bkidp.bkidno(1).IButtonUserNumber, 1, Len(textValue2)) = textValue2
Mid$(tmi.bkidp.bkidno(2).IButtonUserNumber, 1, Len(textValue3)) = textValue3
and so on.....

When the above structure variable tmi is passed to a VC++ Win 32 DLL, the
string value is stored in a different way.


whereby I have declared the structure in VC++ DLL as follows:

typedef struct tagSCANNEDIBUTTONNO
{
char IButtonUserNumber[32];
} SCANNEDIBUTTNO, FAR * LPSCANNEDIBUTTNO;
typedef struct tagBOOKINGIDPARAM
{
SCANNEDIBUTTNO bkidno[15];
} BOOKINGIDPARAM, FAR * LPBOOKINGIDPARAM;

typedef struct tagTRACKERMESSAGEINFO
{
BOOKINGIDPARAM bkidp;
} TRACKERMESSAGEINFO, FAR * LPTRACKERMESSAGEINFO;

When the value is passed to the VC++ dll i get the value as follows

LPTRACKERMESSAGEINFO lptmi

lptmi->bkidp.bkidno(0).IButtonUserNumber[0] = ''
lptmi->bkidp.bkidno(0).IButtonUserNumber[1] = ''
lptmi->bkidp.bkidno(0).IButtonUserNumber[2] = 'E'
lptmi->bkidp.bkidno(0).IButtonUserNumber[3] = 'F'
lptmi->bkidp.bkidno(0).IButtonUserNumber[4] = 'A'
lptmi->bkidp.bkidno(0).IButtonUserNumber[5] = 'B'
lptmi->bkidp.bkidno(0).IButtonUserNumber[6] = 'C'
lptmi->bkidp.bkidno(0).IButtonUserNumber[7] = 'D'
lptmi->bkidp.bkidno(0).IButtonUserNumber[8] = '1'
lptmi->bkidp.bkidno(0).IButtonUserNumber[9] = '2'
lptmi->bkidp.bkidno(0).IButtonUserNumber[10] = ''
lptmi->bkidp.bkidno(0).IButtonUserNumber[11] = ''
....
....
...
lptmi->bkidp.bkidno(0).IButtonUserNumber[31] = ''

and

lptmi->bkidp.bkidno(1).IButtonUserNumber[0] = ''
lptmi->bkidp.bkidno(1).IButtonUserNumber[1] = ''
lptmi->bkidp.bkidno(1).IButtonUserNumber[2] = 'E'
lptmi->bkidp.bkidno(1).IButtonUserNumber[3] = 'F'
lptmi->bkidp.bkidno(1).IButtonUserNumber[4] = 'A'
lptmi->bkidp.bkidno(1).IButtonUserNumber[5] = 'B'
lptmi->bkidp.bkidno(1).IButtonUserNumber[6] = 'C'
lptmi->bkidp.bkidno(1).IButtonUserNumber[7] = 'D'
lptmi->bkidp.bkidno(1).IButtonUserNumber[8] = '1'
lptmi->bkidp.bkidno(1).IButtonUserNumber[9] = '3
lptmi->bkidp.bkidno(1).IButtonUserNumber[10] = ''
lptmi->bkidp.bkidno(1).IButtonUserNumber[11] = ''
....
....
...
lptmi->bkidp.bkidno(1).IButtonUserNumber[31] = ''

and


lptmi->bkidp.bkidno(2).IButtonUserNumber[0] = ''
lptmi->bkidp.bkidno(2).IButtonUserNumber[1] = ''
lptmi->bkidp.bkidno(2).IButtonUserNumber[2] = 'E'
lptmi->bkidp.bkidno(2).IButtonUserNumber[3] = 'F'
lptmi->bkidp.bkidno(2).IButtonUserNumber[4] = 'A'
lptmi->bkidp.bkidno(2).IButtonUserNumber[5] = 'B'
lptmi->bkidp.bkidno(2).IButtonUserNumber[6] = 'C'
lptmi->bkidp.bkidno(2).IButtonUserNumber[7] = 'D'
lptmi->bkidp.bkidno(2).IButtonUserNumber[8] = '1'
lptmi->bkidp.bkidno(2).IButtonUserNumber[9] = '4'
lptmi->bkidp.bkidno(2).IButtonUserNumber[10] = ''
lptmi->bkidp.bkidno(2).IButtonUserNumber[11] = ''
....
....
...
lptmi->bkidp.bkidno(2).IButtonUserNumber[31] = ''

So i do not know why there is an empty space of two bytes before the actual
values (EFABCD12) , (EFABCD13) , and (EFABCD14) ?????????????


Please help me in this regard..........
 
T

tragomaskhalos


You don't really give enough info, but VB strings are
COM BSTRs, which store the length in the first two bytes.
I suspect this is the root of you problem, but try an
on-topic NG or google for help.
 
J

Jim Langston

Mohamed Fysal said:
Hi,

I have a major problem.

I am using a VB exe which is having a structure declared and it looks like
below


Public Type SCANNEDIBUTTNO
IButtonUserNumber As String * 32
End Type

Public Type BOOKINGIDPARAM
bkidno(14) As SCANNEDIBUTTNO
End Type

Public Type TRACKERMESSAGEINFO
bkidp As BOOKINGIDPARAM
End Type

And I have declared a varaible for TRACKERMESSAGEINFO as tmi

and the value for IButtonUserNumber is a Hex value which is stored as
follows:

textValue1 = 'EFABCD12'
textValue2 = 'EFABCD13'
textValue3 = 'EFABCD14'

Mid$(tmi.bkidp.bkidno(0).IButtonUserNumber, 1, Len(textValue1)) =
textValue1
Mid$(tmi.bkidp.bkidno(1).IButtonUserNumber, 1, Len(textValue2)) =
textValue2
Mid$(tmi.bkidp.bkidno(2).IButtonUserNumber, 1, Len(textValue3)) =
textValue3
and so on.....

When the above structure variable tmi is passed to a VC++ Win 32 DLL, the
string value is stored in a different way.


whereby I have declared the structure in VC++ DLL as follows:

typedef struct tagSCANNEDIBUTTONNO
{
char IButtonUserNumber[32];
} SCANNEDIBUTTNO, FAR * LPSCANNEDIBUTTNO;
typedef struct tagBOOKINGIDPARAM
{
SCANNEDIBUTTNO bkidno[15];
} BOOKINGIDPARAM, FAR * LPBOOKINGIDPARAM;

typedef struct tagTRACKERMESSAGEINFO
{
BOOKINGIDPARAM bkidp;
} TRACKERMESSAGEINFO, FAR * LPTRACKERMESSAGEINFO;

When the value is passed to the VC++ dll i get the value as follows

LPTRACKERMESSAGEINFO lptmi

lptmi->bkidp.bkidno(0).IButtonUserNumber[0] = ''
lptmi->bkidp.bkidno(0).IButtonUserNumber[1] = ''
lptmi->bkidp.bkidno(0).IButtonUserNumber[2] = 'E'
lptmi->bkidp.bkidno(0).IButtonUserNumber[3] = 'F'
lptmi->bkidp.bkidno(0).IButtonUserNumber[4] = 'A'
lptmi->bkidp.bkidno(0).IButtonUserNumber[5] = 'B'
lptmi->bkidp.bkidno(0).IButtonUserNumber[6] = 'C'
lptmi->bkidp.bkidno(0).IButtonUserNumber[7] = 'D'
lptmi->bkidp.bkidno(0).IButtonUserNumber[8] = '1'
lptmi->bkidp.bkidno(0).IButtonUserNumber[9] = '2'
lptmi->bkidp.bkidno(0).IButtonUserNumber[10] = ''
lptmi->bkidp.bkidno(0).IButtonUserNumber[11] = ''
...
...
..
lptmi->bkidp.bkidno(0).IButtonUserNumber[31] = ''

and

lptmi->bkidp.bkidno(1).IButtonUserNumber[0] = ''
lptmi->bkidp.bkidno(1).IButtonUserNumber[1] = ''
lptmi->bkidp.bkidno(1).IButtonUserNumber[2] = 'E'
lptmi->bkidp.bkidno(1).IButtonUserNumber[3] = 'F'
lptmi->bkidp.bkidno(1).IButtonUserNumber[4] = 'A'
lptmi->bkidp.bkidno(1).IButtonUserNumber[5] = 'B'
lptmi->bkidp.bkidno(1).IButtonUserNumber[6] = 'C'
lptmi->bkidp.bkidno(1).IButtonUserNumber[7] = 'D'
lptmi->bkidp.bkidno(1).IButtonUserNumber[8] = '1'
lptmi->bkidp.bkidno(1).IButtonUserNumber[9] = '3
lptmi->bkidp.bkidno(1).IButtonUserNumber[10] = ''
lptmi->bkidp.bkidno(1).IButtonUserNumber[11] = ''
...
...
..
lptmi->bkidp.bkidno(1).IButtonUserNumber[31] = ''

and


lptmi->bkidp.bkidno(2).IButtonUserNumber[0] = ''
lptmi->bkidp.bkidno(2).IButtonUserNumber[1] = ''
lptmi->bkidp.bkidno(2).IButtonUserNumber[2] = 'E'
lptmi->bkidp.bkidno(2).IButtonUserNumber[3] = 'F'
lptmi->bkidp.bkidno(2).IButtonUserNumber[4] = 'A'
lptmi->bkidp.bkidno(2).IButtonUserNumber[5] = 'B'
lptmi->bkidp.bkidno(2).IButtonUserNumber[6] = 'C'
lptmi->bkidp.bkidno(2).IButtonUserNumber[7] = 'D'
lptmi->bkidp.bkidno(2).IButtonUserNumber[8] = '1'
lptmi->bkidp.bkidno(2).IButtonUserNumber[9] = '4'
lptmi->bkidp.bkidno(2).IButtonUserNumber[10] = ''
lptmi->bkidp.bkidno(2).IButtonUserNumber[11] = ''
...
...
..
lptmi->bkidp.bkidno(2).IButtonUserNumber[31] = ''

So i do not know why there is an empty space of two bytes before the
actual values (EFABCD12) , (EFABCD13) , and (EFABCD14) ?????????????


Please help me in this regard..........

As Tragomaskhalos says, basic strings use the first two bytes as the length
of the strings. They are not null terminated as c-style strings are.

Since the length of the strings are 8 one of those bytes is an 8 which is an
unprintable character which is why you don't see anything. I'm not sure if
[0] or [1] would be the 8, you'll have to check.
 
C

Cholo Lennon

I have a major problem.
I am using a VB exe which is having a structure declared and it looks like
below
Public Type SCANNEDIBUTTNO
IButtonUserNumber As String * 32
End Type
Public Type BOOKINGIDPARAM
bkidno(14) As SCANNEDIBUTTNO
End Type
Public Type TRACKERMESSAGEINFO
bkidp As BOOKINGIDPARAM
End Type
And I have declared a varaible for TRACKERMESSAGEINFO as tmi
and the value for IButtonUserNumber is a Hex value which is stored as
follows:
textValue1 = 'EFABCD12'
textValue2 = 'EFABCD13'
textValue3 = 'EFABCD14'
Mid$(tmi.bkidp.bkidno(0).IButtonUserNumber, 1, Len(textValue1)) =
textValue1
Mid$(tmi.bkidp.bkidno(1).IButtonUserNumber, 1, Len(textValue2)) =
textValue2
Mid$(tmi.bkidp.bkidno(2).IButtonUserNumber, 1, Len(textValue3)) =
textValue3
and so on.....
When the above structure variable tmi is passed to a VC++ Win 32 DLL, the
string value is stored in a different way.
whereby I have declared the structure in VC++ DLL as follows:
typedef struct tagSCANNEDIBUTTONNO
{
char IButtonUserNumber[32];
} SCANNEDIBUTTNO, FAR * LPSCANNEDIBUTTNO;
typedef struct tagBOOKINGIDPARAM
{
SCANNEDIBUTTNO bkidno[15];
} BOOKINGIDPARAM, FAR * LPBOOKINGIDPARAM;
typedef struct tagTRACKERMESSAGEINFO
{
BOOKINGIDPARAM bkidp;
} TRACKERMESSAGEINFO, FAR * LPTRACKERMESSAGEINFO;
When the value is passed to the VC++ dll i get the value as follows
LPTRACKERMESSAGEINFO lptmi
lptmi->bkidp.bkidno(0).IButtonUserNumber[0] = ''
lptmi->bkidp.bkidno(0).IButtonUserNumber[1] = ''
lptmi->bkidp.bkidno(0).IButtonUserNumber[2] = 'E'
lptmi->bkidp.bkidno(0).IButtonUserNumber[3] = 'F'
lptmi->bkidp.bkidno(0).IButtonUserNumber[4] = 'A'
lptmi->bkidp.bkidno(0).IButtonUserNumber[5] = 'B'
lptmi->bkidp.bkidno(0).IButtonUserNumber[6] = 'C'
lptmi->bkidp.bkidno(0).IButtonUserNumber[7] = 'D'
lptmi->bkidp.bkidno(0).IButtonUserNumber[8] = '1'
lptmi->bkidp.bkidno(0).IButtonUserNumber[9] = '2'
lptmi->bkidp.bkidno(0).IButtonUserNumber[10] = ''
lptmi->bkidp.bkidno(0).IButtonUserNumber[11] = ''
...
...
..
lptmi->bkidp.bkidno(0).IButtonUserNumber[31] = ''

lptmi->bkidp.bkidno(1).IButtonUserNumber[0] = ''
lptmi->bkidp.bkidno(1).IButtonUserNumber[1] = ''
lptmi->bkidp.bkidno(1).IButtonUserNumber[2] = 'E'
lptmi->bkidp.bkidno(1).IButtonUserNumber[3] = 'F'
lptmi->bkidp.bkidno(1).IButtonUserNumber[4] = 'A'
lptmi->bkidp.bkidno(1).IButtonUserNumber[5] = 'B'
lptmi->bkidp.bkidno(1).IButtonUserNumber[6] = 'C'
lptmi->bkidp.bkidno(1).IButtonUserNumber[7] = 'D'
lptmi->bkidp.bkidno(1).IButtonUserNumber[8] = '1'
lptmi->bkidp.bkidno(1).IButtonUserNumber[9] = '3
lptmi->bkidp.bkidno(1).IButtonUserNumber[10] = ''
lptmi->bkidp.bkidno(1).IButtonUserNumber[11] = ''
...
...
..
lptmi->bkidp.bkidno(1).IButtonUserNumber[31] = ''

lptmi->bkidp.bkidno(2).IButtonUserNumber[0] = ''
lptmi->bkidp.bkidno(2).IButtonUserNumber[1] = ''
lptmi->bkidp.bkidno(2).IButtonUserNumber[2] = 'E'
lptmi->bkidp.bkidno(2).IButtonUserNumber[3] = 'F'
lptmi->bkidp.bkidno(2).IButtonUserNumber[4] = 'A'
lptmi->bkidp.bkidno(2).IButtonUserNumber[5] = 'B'
lptmi->bkidp.bkidno(2).IButtonUserNumber[6] = 'C'
lptmi->bkidp.bkidno(2).IButtonUserNumber[7] = 'D'
lptmi->bkidp.bkidno(2).IButtonUserNumber[8] = '1'
lptmi->bkidp.bkidno(2).IButtonUserNumber[9] = '4'
lptmi->bkidp.bkidno(2).IButtonUserNumber[10] = ''
lptmi->bkidp.bkidno(2).IButtonUserNumber[11] = ''
...
...
..
lptmi->bkidp.bkidno(2).IButtonUserNumber[31] = ''
So i do not know why there is an empty space of two bytes before the
actual values (EFABCD12) , (EFABCD13) , and (EFABCD14) ?????????????
Please help me in this regard..........

As Tragomaskhalos says, basic strings use the first two bytes as the length
of the strings. They are not null terminated as c-style strings are.

Since the length of the strings are 8 one of those bytes is an 8 which is an
unprintable character which is why you don't see anything. I'm not sure if
[0] or [1] would be the 8, you'll have to check.

Correction: BSTR string are null terminated.

Check this for more details:
http://blogs.msdn.com/ericlippert/archive/2003/09/12/52976.aspx

Be warned that BSTR strings are wide strings (2 bytes per character).
That would be the reason of the problem.


Regards
 
J

Jim Langston

Cholo Lennon said:
I have a major problem.
I am using a VB exe which is having a structure declared and it looks
like
below
Public Type SCANNEDIBUTTNO
IButtonUserNumber As String * 32
End Type
Public Type BOOKINGIDPARAM
bkidno(14) As SCANNEDIBUTTNO
End Type
Public Type TRACKERMESSAGEINFO
bkidp As BOOKINGIDPARAM
End Type
And I have declared a varaible for TRACKERMESSAGEINFO as tmi
and the value for IButtonUserNumber is a Hex value which is stored as
follows:
textValue1 = 'EFABCD12'
textValue2 = 'EFABCD13'
textValue3 = 'EFABCD14'
Mid$(tmi.bkidp.bkidno(0).IButtonUserNumber, 1, Len(textValue1)) =
textValue1
Mid$(tmi.bkidp.bkidno(1).IButtonUserNumber, 1, Len(textValue2)) =
textValue2
Mid$(tmi.bkidp.bkidno(2).IButtonUserNumber, 1, Len(textValue3)) =
textValue3
and so on.....
When the above structure variable tmi is passed to a VC++ Win 32 DLL,
the
string value is stored in a different way.
whereby I have declared the structure in VC++ DLL as follows:
typedef struct tagSCANNEDIBUTTONNO
{
char IButtonUserNumber[32];
} SCANNEDIBUTTNO, FAR * LPSCANNEDIBUTTNO;
typedef struct tagBOOKINGIDPARAM
{
SCANNEDIBUTTNO bkidno[15];
} BOOKINGIDPARAM, FAR * LPBOOKINGIDPARAM;
typedef struct tagTRACKERMESSAGEINFO
{
BOOKINGIDPARAM bkidp;
} TRACKERMESSAGEINFO, FAR * LPTRACKERMESSAGEINFO;
When the value is passed to the VC++ dll i get the value as follows
LPTRACKERMESSAGEINFO lptmi
lptmi->bkidp.bkidno(0).IButtonUserNumber[0] = ''
lptmi->bkidp.bkidno(0).IButtonUserNumber[1] = ''
lptmi->bkidp.bkidno(0).IButtonUserNumber[2] = 'E'
lptmi->bkidp.bkidno(0).IButtonUserNumber[3] = 'F'
lptmi->bkidp.bkidno(0).IButtonUserNumber[4] = 'A'
lptmi->bkidp.bkidno(0).IButtonUserNumber[5] = 'B'
lptmi->bkidp.bkidno(0).IButtonUserNumber[6] = 'C'
lptmi->bkidp.bkidno(0).IButtonUserNumber[7] = 'D'
lptmi->bkidp.bkidno(0).IButtonUserNumber[8] = '1'
lptmi->bkidp.bkidno(0).IButtonUserNumber[9] = '2'
lptmi->bkidp.bkidno(0).IButtonUserNumber[10] = ''
lptmi->bkidp.bkidno(0).IButtonUserNumber[11] = ''
...
...
..
lptmi->bkidp.bkidno(0).IButtonUserNumber[31] = ''

lptmi->bkidp.bkidno(1).IButtonUserNumber[0] = ''
lptmi->bkidp.bkidno(1).IButtonUserNumber[1] = ''
lptmi->bkidp.bkidno(1).IButtonUserNumber[2] = 'E'
lptmi->bkidp.bkidno(1).IButtonUserNumber[3] = 'F'
lptmi->bkidp.bkidno(1).IButtonUserNumber[4] = 'A'
lptmi->bkidp.bkidno(1).IButtonUserNumber[5] = 'B'
lptmi->bkidp.bkidno(1).IButtonUserNumber[6] = 'C'
lptmi->bkidp.bkidno(1).IButtonUserNumber[7] = 'D'
lptmi->bkidp.bkidno(1).IButtonUserNumber[8] = '1'
lptmi->bkidp.bkidno(1).IButtonUserNumber[9] = '3
lptmi->bkidp.bkidno(1).IButtonUserNumber[10] = ''
lptmi->bkidp.bkidno(1).IButtonUserNumber[11] = ''
...
...
..
lptmi->bkidp.bkidno(1).IButtonUserNumber[31] = ''

lptmi->bkidp.bkidno(2).IButtonUserNumber[0] = ''
lptmi->bkidp.bkidno(2).IButtonUserNumber[1] = ''
lptmi->bkidp.bkidno(2).IButtonUserNumber[2] = 'E'
lptmi->bkidp.bkidno(2).IButtonUserNumber[3] = 'F'
lptmi->bkidp.bkidno(2).IButtonUserNumber[4] = 'A'
lptmi->bkidp.bkidno(2).IButtonUserNumber[5] = 'B'
lptmi->bkidp.bkidno(2).IButtonUserNumber[6] = 'C'
lptmi->bkidp.bkidno(2).IButtonUserNumber[7] = 'D'
lptmi->bkidp.bkidno(2).IButtonUserNumber[8] = '1'
lptmi->bkidp.bkidno(2).IButtonUserNumber[9] = '4'
lptmi->bkidp.bkidno(2).IButtonUserNumber[10] = ''
lptmi->bkidp.bkidno(2).IButtonUserNumber[11] = ''
...
...
..
lptmi->bkidp.bkidno(2).IButtonUserNumber[31] = ''
So i do not know why there is an empty space of two bytes before the
actual values (EFABCD12) , (EFABCD13) , and (EFABCD14) ?????????????
Please help me in this regard..........

As Tragomaskhalos says, basic strings use the first two bytes as the
length
of the strings. They are not null terminated as c-style strings are.

Since the length of the strings are 8 one of those bytes is an 8 which is
an
unprintable character which is why you don't see anything. I'm not sure
if
[0] or [1] would be the 8, you'll have to check.

Correction: BSTR string are null terminated.

Check this for more details:
http://blogs.msdn.com/ericlippert/archive/2003/09/12/52976.aspx

Be warned that BSTR strings are wide strings (2 bytes per character).
That would be the reason of the problem.

According to MSDN they contain the length of the string in front of the
characters.
http://www.codeproject.com/string/bstrsproject1.asp?df=100&forumid=16579&exp=0&select=1122506

Quote: "C strings are arrays of characters terminated by a NULL character.
Visual Basic strings differ in that the length of the string preceded the
characters in the string. So a VB string knows it's own length. In
addition, all VB strings are Unicode (16 bits per character)."

Interesting that we can see the 2 bytes for the length of the string in
front, but each character seems to be fitting in one byte.
 
C

Cholo Lennon

Hi,
I have a major problem.
I am using a VB exe which is having a structure declared and it looks
like
below
Public Type SCANNEDIBUTTNO
IButtonUserNumber As String * 32
End Type
Public Type BOOKINGIDPARAM
bkidno(14) As SCANNEDIBUTTNO
End Type
Public Type TRACKERMESSAGEINFO
bkidp As BOOKINGIDPARAM
End Type
And I have declared a varaible for TRACKERMESSAGEINFO as tmi
and the value for IButtonUserNumber is a Hex value which is stored as
follows:
textValue1 = 'EFABCD12'
textValue2 = 'EFABCD13'
textValue3 = 'EFABCD14'
Mid$(tmi.bkidp.bkidno(0).IButtonUserNumber, 1, Len(textValue1)) =
textValue1
Mid$(tmi.bkidp.bkidno(1).IButtonUserNumber, 1, Len(textValue2)) =
textValue2
Mid$(tmi.bkidp.bkidno(2).IButtonUserNumber, 1, Len(textValue3)) =
textValue3
and so on.....
When the above structure variable tmi is passed to a VC++ Win 32 DLL,
the
string value is stored in a different way.
whereby I have declared the structure in VC++ DLL as follows:
typedef struct tagSCANNEDIBUTTONNO
{
char IButtonUserNumber[32];
} SCANNEDIBUTTNO, FAR * LPSCANNEDIBUTTNO;
typedef struct tagBOOKINGIDPARAM
{
SCANNEDIBUTTNO bkidno[15];
} BOOKINGIDPARAM, FAR * LPBOOKINGIDPARAM;
typedef struct tagTRACKERMESSAGEINFO
{
BOOKINGIDPARAM bkidp;
} TRACKERMESSAGEINFO, FAR * LPTRACKERMESSAGEINFO;
When the value is passed to the VC++ dll i get the value as follows
LPTRACKERMESSAGEINFO lptmi
lptmi->bkidp.bkidno(0).IButtonUserNumber[0] = ''
lptmi->bkidp.bkidno(0).IButtonUserNumber[1] = ''
lptmi->bkidp.bkidno(0).IButtonUserNumber[2] = 'E'
lptmi->bkidp.bkidno(0).IButtonUserNumber[3] = 'F'
lptmi->bkidp.bkidno(0).IButtonUserNumber[4] = 'A'
lptmi->bkidp.bkidno(0).IButtonUserNumber[5] = 'B'
lptmi->bkidp.bkidno(0).IButtonUserNumber[6] = 'C'
lptmi->bkidp.bkidno(0).IButtonUserNumber[7] = 'D'
lptmi->bkidp.bkidno(0).IButtonUserNumber[8] = '1'
lptmi->bkidp.bkidno(0).IButtonUserNumber[9] = '2'
lptmi->bkidp.bkidno(0).IButtonUserNumber[10] = ''
lptmi->bkidp.bkidno(0).IButtonUserNumber[11] = ''
...
...
..
lptmi->bkidp.bkidno(0).IButtonUserNumber[31] = ''
and
lptmi->bkidp.bkidno(1).IButtonUserNumber[0] = ''
lptmi->bkidp.bkidno(1).IButtonUserNumber[1] = ''
lptmi->bkidp.bkidno(1).IButtonUserNumber[2] = 'E'
lptmi->bkidp.bkidno(1).IButtonUserNumber[3] = 'F'
lptmi->bkidp.bkidno(1).IButtonUserNumber[4] = 'A'
lptmi->bkidp.bkidno(1).IButtonUserNumber[5] = 'B'
lptmi->bkidp.bkidno(1).IButtonUserNumber[6] = 'C'
lptmi->bkidp.bkidno(1).IButtonUserNumber[7] = 'D'
lptmi->bkidp.bkidno(1).IButtonUserNumber[8] = '1'
lptmi->bkidp.bkidno(1).IButtonUserNumber[9] = '3
lptmi->bkidp.bkidno(1).IButtonUserNumber[10] = ''
lptmi->bkidp.bkidno(1).IButtonUserNumber[11] = ''
...
...
..
lptmi->bkidp.bkidno(1).IButtonUserNumber[31] = ''
and
lptmi->bkidp.bkidno(2).IButtonUserNumber[0] = ''
lptmi->bkidp.bkidno(2).IButtonUserNumber[1] = ''
lptmi->bkidp.bkidno(2).IButtonUserNumber[2] = 'E'
lptmi->bkidp.bkidno(2).IButtonUserNumber[3] = 'F'
lptmi->bkidp.bkidno(2).IButtonUserNumber[4] = 'A'
lptmi->bkidp.bkidno(2).IButtonUserNumber[5] = 'B'
lptmi->bkidp.bkidno(2).IButtonUserNumber[6] = 'C'
lptmi->bkidp.bkidno(2).IButtonUserNumber[7] = 'D'
lptmi->bkidp.bkidno(2).IButtonUserNumber[8] = '1'
lptmi->bkidp.bkidno(2).IButtonUserNumber[9] = '4'
lptmi->bkidp.bkidno(2).IButtonUserNumber[10] = ''
lptmi->bkidp.bkidno(2).IButtonUserNumber[11] = ''
...
...
..
lptmi->bkidp.bkidno(2).IButtonUserNumber[31] = ''
So i do not know why there is an empty space of two bytes before the
actual values (EFABCD12) , (EFABCD13) , and (EFABCD14) ?????????????
Please help me in this regard..........
As Tragomaskhalos says, basic strings use the first two bytes as the
length
of the strings. They are not null terminated as c-style strings are.
Since the length of the strings are 8 one of those bytes is an 8 which is
an
unprintable character which is why you don't see anything. I'm not sure
if
[0] or [1] would be the 8, you'll have to check.
Correction: BSTR string are null terminated.
Be warned that BSTR strings are wide strings (2 bytes per character).
That would be the reason of the problem.

According to MSDN they contain the length of the string in front of the
characters.http://www.codeproject.com/string/bstrsproject1.asp?df=100&forumid=16...

Quote: "C strings are arrays of characters terminated by a NULL character.
Visual Basic strings differ in that the length of the string preceded the
characters in the string. So a VB string knows it's own length. In
addition, all VB strings are Unicode (16 bits per character)."

Interesting that we can see the 2 bytes for the length of the string in
front, but each character seems to be fitting in one byte.

I never said that BSTR string hasn't its length at the front. I only
said that they are NULL terminated (to provide C/Win API
compatibility).
You can see the memory layout of BSTR strings in the chapter 2, topic
"Dealing with String / Strings Inside Out" from the book "Hardcore
Visual Basic" (Bruce McKinney 1997). Online version at http://vb.mvps.org/hardcore/

Best Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top