本文共 1302 字,大约阅读时间需要 4 分钟。
*********************************************************************************************************** C++部分 //MyTest.h#ifdef _WIN32_#ifdef MY_TEST_EXPORTS#define MY_TEST_API __declspec(dllexport)#define API_STDCALL __stdcall#else#define MY_TEST_API __declspec(dllimport)#endif#else#define MY_TEST_API#define CALLBACK#define API_STDCALL#endif#ifndef _MY_TEST_H_#define _MY_TEST_H_#endif//MyTest.cpp
#include "MyTest.h"#include*********************************************************************************************************** C#部分typedef void (CALLBACK *MyTestCallBack)(char *szBuffer);MyTestCallBack m_myTestCallBack;extern "C" MY_TEST_API void TestApi(const char* str,MyTestCallBack callback){ callback("hello,I recv your str:"+str);}
using System.Collections;using System.Runtime.InteropServices;using System;using System.Collections.Generic;using UnityEngine;public class CSTest{public delegate void Cpp2CsCallBack(string str);#if UNITY_ANDROID[DllImport("u3dmydll")]public static extern void CallCppDllApi(string str,Cpp2CsCallBack cb);#else[DllImport("u3dmydll.dll")]public static extern void CallCppDllApi(string str,Cpp2CsCallBack cb);#endifpublic static void onDllCallBack(string str){Debug.Log(str);}}调用: CSTest.CallCppDllApi("hello dll",CSTest.onDllCallBack);
转载地址:http://fgzvf.baihongyu.com/