473,325 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

structure incompatibility between VB and VC++

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..........
Nov 9 '07 #1
6 1395
Mohamed Fysal wrote:
Hi,

I have a major problem.
Indeed you have, you've asked in the wrong place!

Try a windows programming group.

--
Ian Collins.
Nov 9 '07 #2
On Nov 9, 2:58 am, "Mohamed Fysal" <fy...@bokia.netwrote:
[snip]
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.
Nov 9 '07 #3
"Mohamed Fysal" <fy***@bokia.netwrote in message
news:47********@news.tm.net.my...
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.
Nov 9 '07 #4
On Nov 9, 3:25 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
"Mohamed Fysal" <fy...@bokia.netwrote in message

news:47********@news.tm.net.my...
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.

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

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

--
Cholo Lennon
Bs.As.
ARG
Nov 9 '07 #5
"Cholo Lennon" <ch*********@hotmail.comwrote in message
news:11**********************@22g2000hsm.googlegro ups.com...
On Nov 9, 3:25 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
>"Mohamed Fysal" <fy...@bokia.netwrote in message

news:47********@news.tm.net.my...
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.

Check this for more details:
http://blogs.msdn.com/ericlippert/ar.../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/bs...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.
Nov 10 '07 #6
On Nov 10, 11:50 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
"Cholo Lennon" <chololen...@hotmail.comwrote in message

news:11**********************@22g2000hsm.googlegro ups.com...
On Nov 9, 3:25 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
"Mohamed Fysal" <fy...@bokia.netwrote in message
>news:47********@news.tm.net.my...
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.
Check this for more details:
http://blogs.msdn.com/ericlippert/ar.../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/bs...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

--
Cholo Lennon
Bs.As.
ARG


Nov 12 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Zoran Stipanicev | last post by:
Hi! I've declared structure in function and inside it template structure.It was all great untile i presed build. I'm using vc++ .net 2003 the error was something like: You can't declare template...
4
by: Zoran Stipanicev | last post by:
Hi! I have a code that looks some thing like this void function() { struct st1 { template<...> struct st2 {
3
by: Ben Terry | last post by:
Can anyone tell me how to get data from a byte array into the following structure? public struct MESSAGE_LOG_HEADER_STRUCT2 { public DateTime dtTimeStamp; public Int32 dSerialNumber;
2
by: Michael Chong | last post by:
Another same issue on "NullReferenceException" :- I have an (exe) executable program created in VB.NET 2003 that calls to a MFC DLL written in VC++.NET 2003. I always get an error msg...
2
by: Doug Lind | last post by:
Hi all, I have seen a number of posts re: the BinaryFormatter version incompatibility but nothing on how to recover from it. In my case, I want the exception to trigger an alternate behaviour...
3
by: project | last post by:
Hi every body, Any body can help me the following doubts? 1. what is constructor? 2. what is destructor? 3. what is overriding function. 4. different between structure and array 5. what is...
2
by: meisterbartsch | last post by:
Hi NG, I want to load a structure from a matlab file (*.mat) into vc++. In the best case I would have a matching structure in vc++ to acces the data of the loaded matlab structure. ...
2
by: Phoenix | last post by:
Hi Friends , Could anyone please help me to resolve the following issue : I pass an array of structures to a dll written in VC++ 6.0 whih fills it with data . The following works well for VB...
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.