Internal limitation: structure is too complex or too large.

G

Guest

i have a large C++ data structure that i'm trying to interop with... the
structure is 77400 bytes long. i have the structure defined in C#, so i was
trying to just use "ref <structure>" as the method parameter.

if i use this direct approach, i get the error:
Message: Cannot marshal 'parameter #1': Internal limitation: structure is
too complex or too large."

is there a 64k limit on marshalling structures? what workarounds are there
for this?

i've tried a workaround of using:

IntPtr ptr = Marshal.AllocHGlobal(77400);

// call C++ method to initialize structure
init_method(ptr);

<structure> = (<structure type>)Marshal.PtrToStructure(ptr,
typeof(<structure type>);

// fill in data structure fields...

Marshal.StructureToPtr(<structure>, ptr, false);

// call C++ method to open file
err = open_method(ptr);

now... this method completes properly, but with an error code returned from
the method. i've run the exact same code in a native C++ project and it
works fine and returns a success code.

is there anything obviously wrong with this workaround?

thanks,
Kirk
 
Joined
Nov 17, 2005
Messages
1
Reaction score
0
Hi,

I just worked out a solution.

Instead of defining a struct, define a class. When defining the parameter, use [In, Out] attributes according to your needs. Before calling, new an instance and pass in.

The problem might be because of that struct is a value type, there was no sufficient space in the stack.

If you still can not, let me know and I will post my sample, which is successful.
 
Joined
Mar 18, 2010
Messages
1
Reaction score
0
Hi,

Can you Please post your sample code for the same.

Regards
Pavan
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top