码迷,mamicode.com
首页 > Windows程序 > 详细

c的cl 编译dll,C#调用dll

时间:2015-06-18 01:50:29      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

extern "C" int _declspec(dllexport)testunity(); 
extern "C" int _declspec(dllexport)addT(int a,int b);
int testunity() { return 3;/*这是函数,里面可以写你想要实现的任何功能 */}
int addT(int a,int b){return a*2+b*3;}
set PATH=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin;C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE;
set INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\;
set LIB=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\;C:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\x86\;

cl /c Test.cpp
link /dll Test.obj
pause

 

 

然后编译、组建。就生成了testunity.dll文件。然后再把这个文件放在你的unity工程的assert的Plugins(如果没有这个文件,那你就要新建)。

然后在unity里面新建C#脚本文件dlltest。代码如下

using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class main : MonoBehaviour {
    [DllImport("uDlltest")]
    private static extern int testunity();
    [DllImport("uDlltest")]
    private static extern int addT(int a,int b);
 // Use this for initialization
 void Start () {
        print(testunity().ToString() + "," + addT(2,3).ToString());
 } 
 // Update is called once per frame
 void Update () { 
 }
}

 

c的cl 编译dll,C#调用dll

标签:

原文地址:http://www.cnblogs.com/jiangjieqim/p/4584769.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!