Accessing fields in a C structure via C#

T

Ted Sung

Hi,

I'm using P/Invoke to call some C functions from a DLL.
My C function returns a pointer to a large C structure. I store this
returned pointer in an IntPtr C# variable. I would now like
to access the data in this structure.

What is the best way to do this? The structure is so large that I can't
lay it out as a C# struct. What else could I do?

Thanks,

Ted
 
M

Mattias Sjögren

What is the best way to do this? The structure is so large that I can't
lay it out as a C# struct. What else could I do?

Really? I didn't know there was any size limitation on structs? So
exactly how large is it?

I guess you could use unsafe code, cast to a pointer of the
appropriate type and then use that to read/write members in the
struct.



Mattias
 
E

Eric Gunnerson [MS]

There is no limit on the struct size.

Your best bet is to post with the C++ function header. the framework.interop
newgroup is a good one to ask this sort of question on.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://weblogs.asp.net/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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