472,111 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,111 software developers and data experts.

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


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
0 1526

Post your reply

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

Similar topics

4 posts views Thread by dogalacar | last post: by
1 post views Thread by Steve Baer | last post: by
17 posts views Thread by mr.resistor | last post: by
4 posts views Thread by Andreas Reiff | last post: by
17 posts views Thread by =?Utf-8?B?U2hhcm9u?= | last post: by
6 posts views Thread by =?Utf-8?B?QWxleGFuZGVyZmU=?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.