Passer Double[][][][][][] de C# a C++
Bonjour
Donc voici mon problème je travaille actuellement sur un programme C# utilisant une dll C++. La dll aurait besoin d'un double[][][][][][] afin de fonctionner mais je ne sais pas comment lui faire passer, j'ai essayer avec un marshaller personnalisé mais je n'ai pas réussi a le faire fonctionner: cf le code ci dessous ou d'aplatir le tableau en un double[] mais cette solution est trop lourde pour le programme. Avez vous des solutions?
Merci d'avance
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| public class JaggedArrayMarshaler : ICustomMarshaler
{
static ICustomMarshaler GetInstance(string cookie)
{
return new JaggedArrayMarshaler();
}
GCHandle[] handles;
GCHandle[] handles2;
GCHandle[] handles3;
GCHandle[] handles4;
GCHandle[] handles5;
GCHandle buffer;
Array[] array;
Array[] array2;
Array[] array3;
Array[] array4;
Array[] array5;
public void CleanUpManagedData(object ManagedObj)
{
}
public void CleanUpNativeData(IntPtr pNativeData)
{
buffer.Free();
foreach (GCHandle handle in handles)
{
handle.Free();
}
foreach (GCHandle handle in handles2)
{
handle.Free();
}
foreach (GCHandle handle in handles3)
{
handle.Free();
}
foreach (GCHandle handle in handles4)
{
handle.Free();
}
foreach (GCHandle handle in handles5)
{
handle.Free();
}
}
public int GetNativeDataSize()
{
return IntPtr.Size;
}
public IntPtr MarshalManagedToNative(object ManagedObj)
{
array = (Array[])ManagedObj;
handles = new GCHandle[array.Length];
for (int i = 0; i < array.Length; i++)
{
array2 = (Array[])array[i];
handles2 = new GCHandle[array2.Length];
for (int j = 0; j < array2.Length; j++)
{
array3 = (Array[])array2[j];
handles3 = new GCHandle[array3.Length];
for (int k = 0; k < array3.Length; k++)
{
array4 = (Array[])array3[k];
handles4 = new GCHandle[array4.Length];
for (int l = 0; l < array4.Length; l++)
{
array5 = (Array[])array4[l];
handles5 = new GCHandle[array5.Length];
for (int m = 0; m < array5.Length; m++)
{
handles5[m] = GCHandle.Alloc(array5[m], GCHandleType.Pinned);
}
IntPtr[] pointers5 = new IntPtr[handles5.Length];
for (int m = 0; m < handles5.Length; m++)
{
pointers5[m] = handles5[m].AddrOfPinnedObject();
}
handles4[l] = GCHandle.Alloc(pointers5, GCHandleType.Pinned);
}
IntPtr[] pointers4 = new IntPtr[handles4.Length];
for (int l = 0; l < handles4.Length; l++)
{
pointers4[l] = handles4[l].AddrOfPinnedObject();
}
handles3[k] = GCHandle.Alloc(pointers4, GCHandleType.Pinned);
}
IntPtr[] pointers3 = new IntPtr[handles3.Length];
for (int k = 0; k < handles3.Length; k++)
{
pointers3[k] = handles3[k].AddrOfPinnedObject();
}
handles2[j] = GCHandle.Alloc(pointers3, GCHandleType.Pinned);
}
IntPtr[] pointers2 = new IntPtr[handles2.Length];
for (int j = 0; j < handles2.Length; j++)
{
pointers2[j] = handles2[j].AddrOfPinnedObject();
}
handles[i] = GCHandle.Alloc(pointers2, GCHandleType.Pinned);
}
IntPtr[] pointers = new IntPtr[handles.Length];
for (int i = 0; i < handles.Length; i++)
{
pointers[i] = handles[i].AddrOfPinnedObject();
}
buffer = GCHandle.Alloc(pointers, GCHandleType.Pinned);
return buffer.AddrOfPinnedObject();
}
public object MarshalNativeToManaged(IntPtr pNativeData)
{
return array;
}
} |