新建控制台工程:
点击工程,右键添加新项,添加一个类,例如:LangRec.cs
文件代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace CshConsole_02_langrecdll_01
{
class LangRec
{
//导入dll文件
[DllImport("LangRecDll.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
public extern static void StartLangRec();
}
}
program.cs代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CshConsole_02_langrecdll_01
{
class Program
{
static void Main(string[] args)
{
LangRec.StartLangRec();
Console.WriteLine("You have call dll file!");
}
}
}
dll 文件需要放在工程下的bin/debug文件夹里面。