Pointers to Pointers to Structs...

Announcements and discussion for PInvoke

Pointers to Pointers to Structs...

Postby AlphaPapa » Fri Jul 09, 2010 6:03 pm

Hi everyone.

I'm experimenting with C# and my goal is to write a small utility that interfaces to a Win32 API.

This API defines some structures that contain pointers to pointers to struct and I'm finding it difficult to understand how to marshal them to and from .Net and the unmanaged code.

Example (1):

my API call is defined as:

void TheAPICall(THESTRUCT**);

TheAPICall allocates the memory for data and passes it out to the consumer; the consumer will release memory using a specific routine.

I suppose that a ref IntPtr will be fine in that case, so I will do Marshal.PtrToStruct(...).

Am I correct in this?

Example (2)

Another API call gives out a struct defined as follows in the .h:

int someValue,
THESTRUCT** someData;

This is where things get bad; depending on the particular struct:

- I can have a ptr to ptr to a fixed number of struct (e.g. someValue tells me that I have n structures, so I can perform a for loop)


- I can have a ptr to a NULL terminated sequence of ptrs to that struct (so in C++ I do a while(*someData != NULL) { Process(someData); *someData++; }).

Help & suggestions are welcome.
Posts: 1
Joined: Thu Jul 08, 2010 12:29 pm
Location: Milan, Italy

Return to PInvoke.Net

Who is online

Users browsing this forum: No registered users and 0 guests