Yep.. That's exactly what fixed the problem -----Original Message----- From: Unmoderated discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Paul Brissenden Hemstock Sent: Tuesday, July 06, 2004 5:44 PM To: [EMAIL PROTECTED] Subject: Re: [ADVANCED-DOTNET] Marshal Embedded arrays in structure
I think you need the Pack attribute set to 2; IIRC there are complex rules re packing for different types, but normally packing is on a 4 byte boundary. eg [StructLayout(LayoutKind.Sequential,Pack=2)] Paul -----Original Message----- From: Unmoderated discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Kohli, Naveen Sent: 06 July 2004 22:17 To: [EMAIL PROTECTED] Subject: Re: [ADVANCED-DOTNET] Marshal Embedded arrays in structure Thanks for the link. I was trying to avoid the manual marshalling of the data. Now I have run into a different problem. Here is what the prototype looks like. [StructLayout(LayoutKind.Sequential)] internal class MY_DATA { internal UInt16 usData1; internal UInt32 uiSize; internal IntPtr usValues; } Now I try to get the values out.. IntPtr pData = ...< this I got from C DLL > ... UInt16 usData1 = Marshal.ReadInt16(pData); ---> This returns the correct value Now I want to read uiSize member, UInt32 uiSize = Marshal.ReadInt32(pData, 2); --> This gives wrong value. UInt32 uiSize = Marshal.ReadInt32(pData, 4); --> This is OK.. Isn't the offset for UInt16 2bytes.. or I am totally mistaken. -----Original Message----- From: Unmoderated discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Mattias Sj�gren Sent: Tuesday, July 06, 2004 10:47 AM To: [EMAIL PROTECTED] Subject: Re: [ADVANCED-DOTNET] Marshal Embedded arrays in structure >How do you implement the marshalling code to get all the elements in >the returned array inside this structure? See if this helps http://www.dotnetinterop.com/faq/?q=VariableLengthStruct Mattias -- Mattias Sj�gren [EMAIL PROTECTED] =================================== This list is hosted by DevelopMentor� http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentor� http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentor� http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentor� http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com
