extern "C" int_declspec (dllexport) testunity ();extern "C" int_declspec (dllexport) AddT (intAintb);intTestunity () {return 3;/*This is a function that can write any function you want to implement.*/}intAddT (intAintb) {returnA *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.cpplink /dll Test.objpause
Then compile, build. The Testunity.dll file is generated. Then put this file in your Unity project's assert plugins (if you don't have this file, you'll need to create a new one).
Then create a new C # script file Dlltest inside unity. The code is as follows
usingUnityengine;usingSystem.Collections;usingSystem.Runtime.InteropServices; Public classMain:monobehaviour {[DllImport ("udlltest")] Private Static extern inttestunity (); [DllImport ("udlltest")] Private Static extern intAddT (intAintb); //Use this for initialization voidStart () {print (Testunity (). ToString ()+","+ AddT (2,3). ToString ()); } //Update is called once per frame voidUpdate () {}}
C's CL compile dll,c# call DLL