structure incompatibility between VB and VC++

Discussion in 'C++' started by Mohamed Fysal, Nov 9, 2007.

  1. 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..........
     
    Mohamed Fysal, Nov 9, 2007
    #1
    1. Advertising

  2. Mohamed Fysal

    Ian Collins Guest

    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.
     
    Ian Collins, Nov 9, 2007
    #2
    1. Advertising

  3. On Nov 9, 2:58 am, "Mohamed Fysal" <> 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.
     
    tragomaskhalos, Nov 9, 2007
    #3
  4. Mohamed Fysal

    Jim Langston Guest

    "Mohamed Fysal" <> wrote in message
    news:...
    > 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.
     
    Jim Langston, Nov 9, 2007
    #4
  5. Mohamed Fysal

    Cholo Lennon Guest

    On Nov 9, 3:25 pm, "Jim Langston" <> wrote:
    > "Mohamed Fysal" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > 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/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

    --
    Cholo Lennon
    Bs.As.
    ARG
     
    Cholo Lennon, Nov 9, 2007
    #5
  6. Mohamed Fysal

    Jim Langston Guest

    "Cholo Lennon" <> wrote in message
    news:...
    > On Nov 9, 3:25 pm, "Jim Langston" <> wrote:
    >> "Mohamed Fysal" <> wrote in message
    >>
    >> news:...
    >>
    >>
    >>
    >> > 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/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.
     
    Jim Langston, Nov 10, 2007
    #6
  7. Mohamed Fysal

    Cholo Lennon Guest

    On Nov 10, 11:50 am, "Jim Langston" <> wrote:
    > "Cholo Lennon" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > On Nov 9, 3:25 pm, "Jim Langston" <> wrote:
    > >> "Mohamed Fysal" <> wrote in message

    >
    > >>news:...

    >
    > >> > 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/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=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
     
    Cholo Lennon, Nov 12, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alan Sung
    Replies:
    3
    Views:
    929
    visage
    Aug 6, 2003
  2. David Lees
    Replies:
    1
    Views:
    298
    David Lees
    Mar 7, 2004
  3. Replies:
    9
    Views:
    25,549
    Lal Bahadur Singh
    Nov 11, 2011
  4. Mike Schilling
    Replies:
    2
    Views:
    2,152
    Mike Schilling
    Sep 27, 2009
  5. Eric
    Replies:
    2
    Views:
    134
Loading...

Share This Page