Unity3d--DLL
Unity3d--DLL
1 //TestCPPDLL.h 2 3 #define ex __declspec(dllexport) 4 extern "C" ex int Add(int a,int b);
1 //TestCPPDLL.cpp 2 3 #include "TestCPPDLL.h" 4 5 6 extern "C" ex int Add(int a,int b) 7 { 8 return a * b; 9 }
1 //Test.cs 2 3 using UnityEngine; 4 using System.Collections; 5 using System.Runtime.InteropServices; 6 public class Test : MonoBehaviour { 7 8 [DllImport("TestCPPDLL")] 9 private static extern int Add (int a, int b); 10 11 // Use this for initialization 12 void Start () { 13 int i = Add (5, 7); 14 Debug.Log (i); 15 } 16 17 // Update is called once per frame 18 void Update () { 19 20 } 21 }