标签:
#include <stdio.h> #include <string.h> extern "C" __declspec(dllexport)int TCharParm(char* in,int len,char* out){ memset(out,0,4); memcpy(out,in,len); return 0; } extern "C" __declspec(dllexport)int tl_add(int a,int b){return a+b;}
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\; del Test.dll cl /c Test.cpp link /dll Test.obj del Test.obj,Test.exp,Test.lib pause
C#
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Sockets; using System.Runtime.InteropServices; using System.ComponentModel; using System.Data; using System.Drawing; public class M{ [DllImport("Test.dll")] public static extern int TCharParm(String iin, int len, StringBuilder oout); [DllImport("Test.dll")] public static extern int tl_add(int a,int b); static void Main(string[] args){ StringBuilder b = new StringBuilder(4); TCharParm("CDE",3,b); Console.WriteLine(b.ToString()); Console.WriteLine(tl_add(1,2).ToString()); } }
set fileName=M.exe set cscFile=C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe if exist %fileName% del %fileName% @rem pause %cscFile% /out:M.exe /recurse:*.cs /platform:x86 M.exe pause
标签:
原文地址:http://www.cnblogs.com/jiangjieqim/p/4585709.html