Click to See Complete Forum and Search --> : URGENT :: Passing UNION type from VB to C++


Tom Verbruggen
June 26th, 2001, 07:11 AM
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 !!!

Clearcode
June 26th, 2001, 07:26 AM
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

Tom Verbruggen
June 26th, 2001, 08:18 AM
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