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 / October 2005

Tip: Looking for answers? Try searching our database.

Interop System.TypeLoadException  (PINVOKE)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Javier Jaen - 26 Oct 2005 15:44 GMT
Hello,
I need to interop from C# with a native method and pass an array of structs.
I have done it as follows:

[StructLayout(LayoutKind.Sequential,Pack=4)]
public struct ISD_STATION_STATE_TYPE
{... //struct fields};

[StructLayout(LayoutKind.Sequential,Pack=4)]
public struct ISD_TRACKER_DATA_TYPE{

[ MarshalAs( UnmanagedType.ByValArray, SizeConst=ISD_MAX_STATIONS)]
public ISD_STATION_STATE_TYPE [] Station;

};

[DllImport("isense.dll")]
public static extern int ISD_GetData (int handle, ref ISD_TRACKER_DATA_TYPE
Data);

but when I call this function:

ISD_TRACKER_DATA_TYPE data= new ISD_TRACKER_DATA_TYPE();
ISD_GetData( handle, ref data );

I obtain a runtime System.TypeLoadException  saying that

Can not marshal field Station of type ... : This type can not be marshaled
as a structure field.
Does anybody know where the problem is and how to solve it?

Many thanks in advance for your help
Javier
Mattias Sjögren - 26 Oct 2005 17:37 GMT
>[ MarshalAs( UnmanagedType.ByValArray, SizeConst=ISD_MAX_STATIONS)]
>public ISD_STATION_STATE_TYPE [] Station;

Here's your problem. Nested struct arrays isn't supported by the v1.x
marshaler.

Mattias

Signature

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

Javier Jaen - 26 Oct 2005 17:56 GMT
yes Mattias this was the problem.
I solved it by making the structure flat (removing the array declaration)
thanks for your help.

> >[ MarshalAs( UnmanagedType.ByValArray, SizeConst=ISD_MAX_STATIONS)]
>>public ISD_STATION_STATE_TYPE [] Station;
[quoted text clipped - 3 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.