C dyna.c文件编译 CBDyna.dll
#ifndef __CBD__
#define CBDyna __declspec(dllexport)
#else
#define CBDyna __declspec(dllimport)
#endif // !__CBD__
CBDyna void ExecuteRepeat(int (*callback)(int)) {
int i = 0;
for (;;) {
i++;
int _out = callback(i);
if (_out > 10000)
break;
}
}
Unity C# 调用
using UnityEngine;
using System.Runtime.InteropServices;
public class TestDll : MonoBehaviour
{
public delegate int RepeatEvt(int c);
int AskMore(int x)
{
int _rst = 2 * x;
Debug.Log("input " + x + ",output " + _rst);
return _rst;
}
// Start is called before the first frame update
void Start()
{
RepeatEvt _p = AskMore;
ExecuteRepeat(_p);
}
// Update is called once per frame
void Update()
{
}
[DllImport("CBDyna")]//, true, CallingConvention.Cdecl, CharSet.Ansi, "ExecuteRepeat",true,true,true,true)]
extern static void ExecuteRepeat(RepeatEvt _cb);
}