Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2006

Tip: Looking for answers? Try searching our database.

How to marshal an array of structures

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RobinC - 12 Sep 2006 21:02 GMT
Hi,

I'm trying to marshal data from a C API. The struct contains an array of
structs. The Marshal.PtrToStructure call throws a TypeLoadException with the
message - "Can not marshal field struct_arr of type NODE: This type can not
be marshaled as a structure field."

Changing from an array of structs to an array of blittable types works.

Is it possible to marshal an array of structs?

[StructLayout(LayoutKind.Sequential), ComVisible(false)]
public struct NODE
{
   public uint       id;           
   [MarshalAs( UnmanagedType.ByValArray, SizeConst=3 )]
   public byte[]    byte_arr;
   [MarshalAs( UnmanagedType.ByValArray, SizeConst=3 )]
   public FOO[]    struct_arr;
}

[StructLayout(LayoutKind.Sequential), ComVisible(false)]
public struct FOO
{
   public ulong val;
   public byte state;
}

Signature

Thanks,
-Robin

Mattias Sjögren - 13 Sep 2006 05:05 GMT
>I'm trying to marshal data from a C API. The struct contains an array of
>structs. The Marshal.PtrToStructure call throws a TypeLoadException with the
>message - "Can not marshal field struct_arr of type NODE: This type can not
>be marshaled as a structure field."

This should work on .NET Framework 2.0. It wasn't supported in 1.x.

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

RobinC - 13 Sep 2006 16:25 GMT
A good reason to upgrade! Thanks.
Signature

Thanks,
-Robin

> >I'm trying to marshal data from a C API. The struct contains an array of
> >structs. The Marshal.PtrToStructure call throws a TypeLoadException with the
[quoted text clipped - 4 lines]
>
> Mattias

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.