CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2001
    Posts
    14

    URGENT :: Passing UNION type from VB to C++

    Hi,

    I have the following problem passing parameters from VB to C++.

    I have the following declaration in C++



    typedef union
    {
    UCHAR mrn [MRNlen + 1];
    UCHAR isn [ISNlen + 1];
    NETWORK msgnet;
    USHORT msglen;
    UCHAR msgok [OKlen + 1];
    UCHAR msgack [ACKlen + 1];
    UCHAR msgroute [ROUTlen + 1];
    UCHAR msgcomment [CMTlen + 1];
    TX_HEADER txhead;
    UCHAR msguser [UIDlen + 1];
    UCHAR msgtrusr [UIDlen + 1];
    TX_INFO txinfo;
    UCHAR msgmac [MSGMAClen + 1];
    UCHAR msgpac [MSGPAClen + 1];
    } FIELD;
    typedef FIELD *PFIELD;
    typedef PFIELD *PPFIELD;




    .

    My entry point for my DLL is as follows :


    USHORT _stdcall VBENMWriteField(FIELDTYPE VBFieldType, PFIELD VBField)
    {
    USHORT ENMrc;


    ENMrc = ENMWriteField(VBFieldType, VBField);

    return ENMrc;
    }



    .

    I have tried the following declaration in my VB but it only works for numeric values...


    Declare Function VBENMWriteField Lib "enmvbapi" (byval FieldType as Long, byref VBField as Any) as Integer



    .
    This declaration does not work with STRINGS because a VB string is not the same as a C string and when passed By Ref, you receive rubbish in the pointer...

    HOW CAN I declare my function in VB or how can I solve this problem so I can pass STRINGS as well as integers !!!

    PS : This is quit urgent because I have a deadline by the end of the week !!!



  2. #2
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: URGENT :: Passing UNION type from VB to C++

    In VB5 and beyond, fixed length strings in structures are replaced by 0-based arrays of bytes thus:


    public Type PField
    mrn(MRNLen + 1) as Byte
    isn(ISNLen + 1) as Byte
    '...etc...
    End Type




    You can then pass this by aliasing the dll call thus:


    Declare Function VBENMWriteFieldByPointer Lib "enmvbapi" Alias "VBENMWriteField" (byval FieldType as Long, byval VBField as Long) as Integer

    Declare Function VBENMWriteFieldByStruct Lib "enmvbapi" Alias "VBENMWriteField" (byval FieldType as Long, VBField as PField) as Integer





    HTH,
    D.

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  3. #3
    Join Date
    Jun 2001
    Posts
    14

    Re: URGENT :: Passing UNION type from VB to C++

    Thx!
    I thought it was something like that....
    I aliased the function and passed a STRING byval.
    My C++ DLL receives the parameter correctly !

    Thx again !

    Tom



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured