Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > structure incompatibility between VB and VC++

Reply
Thread Tools

structure incompatibility between VB and VC++

 
 
Mohamed Fysal
Guest
Posts: n/a
 
      11-09-2007
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..........


 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      11-09-2007
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.
 
Reply With Quote
 
 
 
 
tragomaskhalos
Guest
Posts: n/a
 
      11-09-2007
On Nov 9, 2:58 am, "Mohamed Fysal" <(E-Mail Removed)> wrote:
> [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.


 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      11-09-2007
"Mohamed Fysal" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.


 
Reply With Quote
 
Cholo Lennon
Guest
Posts: n/a
 
      11-09-2007
On Nov 9, 3:25 pm, "Jim Langston" <(E-Mail Removed)> wrote:
> "Mohamed Fysal" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> > 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


 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      11-10-2007
"Cholo Lennon" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> On Nov 9, 3:25 pm, "Jim Langston" <(E-Mail Removed)> wrote:
>> "Mohamed Fysal" <(E-Mail Removed)> wrote in message
>>
>> news:(E-Mail Removed)...
>>
>>
>>
>> > 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.


 
Reply With Quote
 
Cholo Lennon
Guest
Posts: n/a
 
      11-12-2007
On Nov 10, 11:50 am, "Jim Langston" <(E-Mail Removed)> wrote:
> "Cholo Lennon" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed) ups.com...
>
>
>
> > On Nov 9, 3:25 pm, "Jim Langston" <(E-Mail Removed)> wrote:
> >> "Mohamed Fysal" <(E-Mail Removed)> wrote in message

>
> >>news:(E-Mail Removed)...

>
> >> > 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




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Incompatibility between JDK 1.4 and JDK 1.6 Mike Schilling Java 2 09-27-2009 10:59 PM
Incompatibility of File Structure with Win XP Home Edition TheArtfulDodger Windows 64bit 10 06-15-2009 05:08 AM
IIS Versions incompatibility between Server and Client Eric ASP .Net Security 2 07-01-2005 12:12 PM
Incompatibility between psyco 1.2 and pythonwin? David Lees Python 1 03-07-2004 07:09 AM
Re: float incompatibility between Windows and UNIX? Alan Sung C++ 3 08-06-2003 12:31 PM



Advertisments