Its was 4 byte alignment that was creating problem. I had to change the prototype to use 2 byte alignment.
-----Original Message----- From: Unmoderated discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of William Bartholomew Sent: Tuesday, July 06, 2004 5:30 PM To: [EMAIL PROTECTED] Subject: Re: [ADVANCED-DOTNET] Marshal Embedded arrays in structure Try using Marshall.SizeOf to get the size. Regards, William D. Bartholomew http://blog.bartholomew.id.au/ Kohli, Naveen wrote: > 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 > --- avast! Antivirus: Outbound message clean. Virus Database (VPS): 0427-2, 04/07/2004 Tested on: 7/07/2004 7:30:08 AM avast! - copyright (c) 2000-2004 ALWIL Software. http://www.avast.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
