怎么在vs2010中用c#调用c++的.dll文件

如题所述

添加
namespace

using
System.Runtime.InteropServices;
在调用dll的类里面添加
[
DllImport
("
dll文件
名",
EntryPoint

=
"
接口函数
名",
CallingConvention
=
CallingConvention.StdCall)]
public
static
extern
接口函数
返回值

接口函数名(接口函数参数);
如:
[DllImport("mydll.dll",
EntryPoint
=
"WriteInfo",
CallingConvention
=
CallingConvention.StdCall)]
public
static
extern
int
WriteInfo(string
PLCIp,
int
nPort,
int
ip,
int
dmAddress,
int
value);
dll文件需要放在你程序目录下
温馨提示:内容为网友见解,仅供参考
无其他回答