Device Application in C# Marshalling Exception

Apr 22 2009 6:01 AM
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.