Red Gate forums :: View topic - Pointers to Pointers to Structs...
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
PInvoke.Net
PInvoke.Net forum

Pointers to Pointers to Structs...

Search in PInvoke.Net forum
Post new topic   Reply to topic
Jump to:  
Author Message
AlphaPapa



Joined: 08 Jul 2010
Posts: 1
Location: Milan, Italy

PostPosted: Fri Jul 09, 2010 7:03 pm    Post subject: Pointers to Pointers to Structs... Reply with quote

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:

myStruct
{
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)

or

- 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.
_________________
Andrea.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group