两种方式:
根据选项Release或Debug,运行完上面的生成解决方案后,会在工程目录下生成x64/Relese/xxx.dll。至此dll生成完成。
注意:_declspec(dllexport)是必须在方法前面,否则c#会调用不到这个方法。
extern "C" 以c的方式去编译也是必要的
先创建DllForUnity.h头文件
#pragma once
#include
#include
#include
#define _DllExport _declspec(dllexport) //使用宏定义缩写下
extern "C"
{
_DllExport float GetDistance(float x, float y);
}
再创建DllForUnity.cpp实现文件。
#include
float GetDistance(float x, float y)
{
return x+y;
}
[DllImport("RoboidS", EntryPoint = "GetDistance")]
private static extern float GetDistance(float x, float y);