By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,184 Members | 1,397 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,184 IT Pros & Developers. It's quick & easy.

Passing a pointer to a pointer array to unmanaged C++ code

P: 3
Hi!

I've been working with DLLimports passing structs and various other parameters to unmanaged code. I had problems earlier sending pointer to structs to the unmanaged code, and this forum solved it for me (using the ref keyword etc).

I now encountered a function that takes a pointer to an array as a parameter, and this array consists of other pointers, to structs. Horrible isn't it?

I have no way of modifying the unmanaged code, I have to deal with it. Right now I have used a shortcut with nested fixed statements:

GK_a is a struct. cs_a is an array of such structs. I want pointerArray to contain pointers to the structs in cs_a.

fixed(GK_a* tempPointer = &(cs_a[0]))
{
pointerArray[0] = tempPointer; //one down

fixed (GK_a* tempPointer2 = &(cs_a[1]))
{
if (NUMBER > 1)
pointerArray[1] = tempPointer2; //two down
and so on.

I will then call my function

DLLHandler.myFunction(ref pointerArray);

and I have declared this function like this:

[DllImport("myDLL.dll", EntryPoint = "myFunction")]
public static extern byte myFunction(ref GK_a* pointerArray);

(myFunction actually wants GK_a ** pointer, but the ref should take care of it?)

I havent gotten far enough to test. But is there an easier way?

I would greatly appreciate any help!

Bendik Mjaaland
Jul 9 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.