0
Answer

Device Application in C# Marshalling Exception

Sangeetha

Sangeetha

15y
3.2k
1
Hi,

I am developing a Smart device Application which is communicating with a driver written C using DeviceIOControl().

My structure is as follows
struct IPOD_OUT_GET_ALL_NAMES
{
public UInt32 dwStatus;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public string []sNamesOfItems;
}

Code is as follows.
IPOD_OUT_GET_ALL_NAMES IPodOutGetAllNames = new IPOD_OUT_GET_ALL_NAMES();
int size = Marshal.SizeOf(typeof(IPOD_OUT_GET_ALL_NAMES));
IntPtr pEvent = IntPtr.Zero;
pEvent = Marshal.AllocHGlobal(size); System.Runtime.InteropServices.Marshal.StructureToPtr(
IPodOutGetAllNames,
pEvent,
false);

At the invocation of Marshal.SizeOf(typeof(IPOD_OUT_GET_ALL_NAMES));
Exception is thrown
system.runtime.interopservices.marshal.SizeOf Internal() exception for the structure which contains 2dimentional string array.

Plese help.