非托管dll调用

wsw0515 2011-08-08 11:01:06
dll
bp2316.dll


函数
int _VI_FUNC bp2316_init (int COMPort, int baudRate, double timeoutseconds,
int blockCheck, int groupAddress, int userAddress,
int resetDevice, int *instrumentID);
int _VI_FUNC bp2316_meas_start (int instrumentID);
int _VI_FUNC bp2316_meas_read (int instrumentID, double *measuringValue,
char unit[]);
int _VI_FUNC bp2316_meas_stop (int instrumentID);
int _VI_FUNC bp2316_send_scpi (int instrumentID, char sendSCPIMessage[]);
int _VI_FUNC bp2316_receive_scpi (int instrumentID, char sendSCPIMessage[],
char instrumentAnswers[]);
int _VI_FUNC bp2316_close (int instrumentID);

请问高手们C#中如何代码调用?

自己写了一个,但是调用的时候报错“找不到指定模块”。
[DllImport("bp2316.dll")]
public extern static short bp2316_init(short COMPort, short baudRate, double timeoutseconds, short blockCheck, short groupAddress, short userAddress, short resetDevice, ref short instrumentID);
...全文
247 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
wsw0515 2011-08-10
  • 打赏
  • 举报
回复
谢谢各位,找到instrup.dll放到目录就好了
wsw0515 2011-08-09
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 syx151 的回复:]
_VI_FUNC 这个宏展开是什么?
[/Quote]
这个就不知道了,我就一个头文件代码和DLL,其它的什么都没有。
sdl2005lyx 2011-08-09
  • 打赏
  • 举报
回复
“用工具查看了一下函数是有的,但这个DLL还引用了instrup.dll。可能是这个原因报错吧。”
对,所有依赖的动态库都放在同一目录里。。。。
mjp1234airen4385 2011-08-09
  • 打赏
  • 举报
回复
你的推测有可能。
另外看看VI_FUNC 是定义的什么调用约定。你要做相应的修改。
wsw0515 2011-08-09
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 sdl2005lyx 的回复:]
按3楼的办法,先试试:

[DllImport("DLL_MD5.dll", EntryPoint = "bp2316_init")]//显示给出函数名称
public extern static short bp2316_init(short COMPort, short baudRate, double timeoutseconds, short blockCheck, short g……
[/Quote]

用工具查看了一下函数是有的,但这个DLL还引用了instrup.dll。可能是这个原因报错吧。
sdl2005lyx 2011-08-09
  • 打赏
  • 举报
回复
按3楼的办法,先试试:

[DllImport("DLL_MD5.dll", EntryPoint = "bp2316_init")]//显示给出函数名称
public extern static short bp2316_init(short COMPort, short baudRate, double timeoutseconds, short blockCheck, short groupAddress, short userAddress, short resetDevice, ref short instrumentID);

如果还是包这个问题,你用VC6工具,DEPENDS.EXE,打开DLL_MD5.dll,看看这个函数是否真正存在?
wsw0515 2011-08-08
  • 打赏
  • 举报
回复
非托管的不能直接引用
LMAOhuaNL 2011-08-08
  • 打赏
  • 举报
回复
在类库里面写的话,就会生成dll程序集的呀,不是直接引用就行了么?
syx151 2011-08-08
  • 打赏
  • 举报
回复
_VI_FUNC 这个宏展开是什么?
wsw0515 2011-08-08
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 syx151 的回复:]
如果你是Debug模式,要把那个dll文件复制到你的debug目录下
如果是release,那么复制到release目录下.
[/Quote]
这一步没问题
syx151 2011-08-08
  • 打赏
  • 举报
回复
如果你是Debug模式,要把那个dll文件复制到你的debug目录下
如果是release,那么复制到release目录下.
wsw0515 2011-08-08
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 happy09li 的回复:]
[DllImport("DLL_MD5.dll", EntryPoint = "bp2316_init")]
public extern static short bp2316_init(short COMPort, short baudRate, double timeoutseconds, short blockCheck, short groupAddress, short userAd……
[/Quote]
还是“找不到指定模块”,不知道是DLL的问题还是没装驱动的问道
Avoid 2011-08-08
  • 打赏
  • 举报
回复
你把dll复制到你工程文件夹下
熙风 2011-08-08
  • 打赏
  • 举报
回复
[DllImport("DLL_MD5.dll", EntryPoint = "bp2316_init")]
public extern static short bp2316_init(short COMPort, short baudRate, double timeoutseconds, short blockCheck, short groupAddress, short userAddress, short resetDevice, ref short instrumentID);

再调用试一下,,

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧