all groups > dotnet interop > december 2006 >
You're in the

dotnet interop

group:

Send Structur with byte array from C# to C


Send Structur with byte array from C# to C julienboys85
12/15/2006 2:48:54 AM
dotnet interop:
hi,

i have a structure :
------------------------------------------------------------------------------
[StructLayout(LayoutKind.Sequential)]
public struct DRVBINFO
{
public UInt16 wCardsNumber;
public UInt16 wChannelsNumber;
[MarshalAs(UnmanagedType.LPArray)]
public byte[] myIntArray ;
}
------------------------------------------------------------------------------

i want to send this structure from a C# to a C function
------------------------------------------------------------------------------
[DllImport("LightMng.dll", SetLastError = true)]
static extern uint
LightMngInit([MarshalAs(UnmanagedType.Struct)]DRVBINFO DRVBinfo);
------------------------------------------------------------------------------

I use this function
------------------------------------------------------------------------------
public uint OpenDevice()
{
DRVBINFO DRVBinfo;
DRVBinfo = new DRVBINFO();

DRVBinfo.wCardsNumber = 3;
DRVBinfo.wChannelsNumber = 12;
DRVBinfo.myIntArray = new Byte[3];
DRVBinfo.myIntArray[0] = 0x00;
DRVBinfo.myIntArray[1] = 0x51;
DRVBinfo.myIntArray[2] = 0x00;
uint Return;

Return = LightMngInit(DRVBinfo);
Return = 1;
if (Return == 0) return 0;

return 1;
}
------------------------------------------------------------------------------

when i use this, i get an exception : "NotSupportedException"
Re: Send Structur with byte array from C# to C Michael C
12/15/2006 11:39:18 PM
[quoted text, click to view]

Try either changing the struct to a class (I almost always use classes for
interop) or pass the struct in as ref. Not sure if that will fix the problem
but worth a try.

[quoted text, click to view]

AddThis Social Bookmark Button