回答編集履歴
2
LayoutKind忘れ
answer
CHANGED
@@ -15,12 +15,14 @@
|
|
15
15
|
{
|
16
16
|
class Program
|
17
17
|
{
|
18
|
+
[StructLayout(LayoutKind.Sequential)]
|
18
19
|
struct A
|
19
20
|
{
|
20
21
|
public int arrayLength;
|
21
22
|
public unsafe DynamicArray* dArray;
|
22
23
|
}
|
23
24
|
|
25
|
+
[StructLayout(LayoutKind.Sequential)]
|
24
26
|
struct DynamicArray
|
25
27
|
{
|
26
28
|
public int arrayId;
|
1
追記
answer
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
正直な所、アンマネージドコードの相互運用に関しては、Microsoft公式のドキュメントが一番詳しく載っているので、最初に読みましょう。
|
2
2
|
[アンマネージ コードとの相互運用](https://docs.microsoft.com/ja-jp/dotnet/framework/interop/)
|
3
3
|
[ネイティブ相互運用性](https://docs.microsoft.com/ja-jp/dotnet/standard/native-interop/)
|
4
|
+
[ネイティブ相互運用性のベスト プラクティス](https://docs.microsoft.com/ja-jp/dotnet/standard/native-interop/best-practices)
|
5
|
+
|
6
|
+
今回の例だと、このへんでしょう。
|
4
7
|
[クラス、構造体、および共用体のマーシャリング](https://docs.microsoft.com/ja-jp/dotnet/framework/interop/marshaling-classes-structures-and-unions)
|
5
8
|
|
6
9
|
matukesoさんがIntPtr使った方法回答してますので、別の方法としてunsafe使った方法を載せておきます。あと、DLL側でnewでメモリ割り当てしてるなら、DLL側にメモリ解放用の関数も用意しておかないとまずいです。
|