前提
UnityにC++を導入しようとしています。
実現したいこと
-UnityにC++を導入したい
発生している問題・エラーメッセージ
CS0246:型または名前空間の名前'IntPtr'が見つかりませんでした。(usingディレクティブまたはアセンブリ参照が指定されていることを確認してください) CS0103:現在のコンテキストに'IntPtr'という名前は存在しません
該当のソースコード
C#
1using System.Collections; 2using System.Runtime.InteropServices; 3using System.Collections.Generic; 4using UnityEngine; 5 6public class CPlusSc : MonoBehaviour 7{ 8 [DllImport("Dll1")] 9 private static extern void get_array(ref IntPtr array, ref int count); 10 11 private void Awake() 12 { 13 var array = IntPtr.Zero; 14 var count = 0; 15 16 get_array(ref array, ref count); 17 var result = new int[count]; 18 Marshal.Copy(array, result, 0, count); 19 20 Debug.Log($"count: {count}"); 21 22 for (var i = 0; i < result.Length; i++) 23 { 24 var value = result[i]; 25 Debug.Log($"index {i}: {value}"); 26 } 27 } 28}
DLL
1// dllmain.cpp : DLL アプリケーションのエントリ ポイントを定義します。 2#include "pch.h" 3 4#define DLLEXPORT extern "C" __declspec(dllexport) 5 6static int array[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; 7 8DLLEXPORT void __stdcall get_array(int** result, int* count) 9{ 10 *result = array; 11 *count = 10; 12}
補足情報(FW/ツールのバージョンなど)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。