mh
10/10/2007 11:47:00 AM
Marshal.StructureToPtr(device, DeviceList, true);
iReturnValue = EnumerateDevice(ref DeviceList);
DEVICE retdevice = (DEVICE)Marshal.PtrToStructure(DeviceList,
typeof(DEVICE))
MH
On Oct 8, 10:18 pm, Treadstone <u.bhar...@gmail.com> wrote:
> Nicholas,
>
> I defined the structure in the manner suggested by you, along with the
> DllImport declaration.
> However, the moment I called either Marshal.AllocCoTaskMem or
> Marshal.AllocHGlobal or Marshal.PtrToStructure, I am getting a
> System.NotSupported exception.
>
> My code inside my function is as follows:
>
> //BEGINNING OF CODE SNIPPET
>
> IntPtr DeviceList = IntPtr.Zero;
> DEVICE device = new DEVICE( ); //The DEVICE structure has been defined
> already.
>
> Marshal.AllocHGlobal(Marshal.SizeOf(device); //This gives me a
> System.NotSupportedException
>
> //My function call
> iReturnValue = EnumerateDevice(ref DeviceList);
>
> Marshal.PtrToStructure(DeviceList, device) //If I do not invoke the
> Marshal.AllocHGlobal call, then
> the //
> System.NotSupportedException occurs here.
>
> //END OF CODE SNIPPET
>
> I tried the Marshal.PtrToStructure with all possible combinations of
> the overloaded methods, but ended up with the same result.
> Am I making some mistake while calling the methods of Marshal (such as
> AllocHGlobal/ AllocCoTaskMem/PtrToStrucuture)? Or does it have
> something to do with the version of VS2005?
>
> Thanks in Advance.
>
> Christof: Thanks for the pointer to the website. It has been of great
> help to me.
>
> Regards,
> Treadstone