Problem with structure between C++ and .NET

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
 
M

Mattias Sjögren

Peter,

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



Mattias
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top