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