Problem with structure between C++ and .NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I want to call a C++ function in my additional DLL out of my VB.NET code.
Unforunately, this function needs a structure as an argument and here's where
the problems begin:

This is the C/C++ declaration:
typedef struct _MYSTRUCT{
BOOLEAN one;
BOOLEAN two;
UINT anint;
BOOLEAN three;
BOOLEAN four;
}MYSTRUCT;

This is the VB.NET declaration I tried:
<StructLayout(LayoutKind.Sequential)> Public Structure MYSTRUCT
Public one As Boolean
Public two As Boolean
Public anint As UInt16
Public three As Boolean
Public four As Boolean
End Structure

When I pass an instance of the .net declaration to the C function (e.g. void
MyFunction(MYSTRUCT mystr);) the whole data is malformatted. Can anyone help?
How can I marshall this correctly?

Thanks a lot
Peter
 
Peter,

Try adding the attribute [MarshalAs(UnmanagedType.I1)] to all Boolean
members, and change the type of anint to UInt32.



Mattias
 
Back
Top