📄 subject_36716.htm
字号:
<p>
序号:36716 发表者:小丫多多 发表日期:2003-04-17 22:17:44
<br>主题:求教显式加载DLL文件的问题!!
<br>内容:我正在做一个数据采集的软件,使用了一块pc总线数据采集控制卡。<BR>随该卡仅提供了一个DLL文件及一个在win2000下使用的驱动程序。<BR>安装完驱动之后,dll文件自动考入WINNT\SYSTEM32目录下。<BR>于是我在程序中显示加载了该DLL,具体代码如下:(我使用的是WIN2000系统)<BR>/////////////////////////////////////////////////////////////////////////////<BR> HINSTANCE hInstDll;<BR> unsigned short value;<BR> unsigned long time;<BR><BR> typedef unsigned short (*READCHDATA)(unsigned short, <BR> unsigned char, unsigned long, unsigned long);<BR> typedef unsigned short (*QPCOUNTER)(void);<BR> typedef void (*OUTPORT)(unsigned short, unsigned char);<BR> typedef void (*DELAY)(unsigned long);<BR><BR><BR> READCHDATA ReadChData;<BR> QPCOUNTER GetCounter;<BR> OUTPORT OutPort;<BR> DELAY Delay;<BR><BR><BR> hInstDll = GetModuleHandle("c:\\winnt\\system32\\k800.dll");<BR> if(hInstDll == NULL)<BR> VERIFY(hInstDll = LoadLibrary("c:\\winnt\\system32\\k800.dll"));<BR> <BR> VERIFY(ReadChData =(READCHDATA)GetProcAddress(hInstDll, "read_ch_data"));<BR> VERIFY(GetCounter = (QPCOUNTER)GetProcAddress(hInstDll, "q_p_counter"));<BR> VERIFY(OutPort = (OUTPORT)GetProcAddress(hInstDll, "out_port"));<BR> VERIFY(Delay = (DELAY)GetProcAddress(hInstDll, "adelay"));<BR><BR> time = GetCounter();<BR> value = ReadChData(768, 0, 150, 30);<BR> OutPort(770, 0);<BR> Delay(10000);<BR><BR> VERIFY(FreeLibrary(hInstDll));<BR><BR>/////////////////////////////////////////////////////////////////////////////<BR>系统编译通过,运行时time = GetCounter();能正常运行,但一但运行到<BR> value = ReadChData(768, 0, 150, 30);<BR> OutPort(770, 0);<BR> Delay(10000);<BR><BR>这类带有参数的函数时就会弹出消息框:debug error!<BR>说是函数调用方式不合适。<BR>不知为何?望高手赐教!!!万分感谢!!!!<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:xiongli 回复日期:2003-04-17 23:28:38
<br>内容:可能是dll里面delay 函数参数声明跟你程序里面的参数声明不相同<BR>所以在最后函数返回的时候堆栈被破坏
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:dr0 回复日期:2003-04-17 23:40:55
<br>内容:typedef unsigned short (*READCHDATA)(unsigned short, <BR> unsigned char, unsigned long, unsigned long);<BR> typedef unsigned short (*QPCOUNTER)(void);<BR> typedef void (*OUTPORT)(unsigned short, unsigned char);<BR> typedef void (*DELAY)(unsigned long);<BR><BR>// try : typedef void(__stdcall *delay)(unsigned long);<BR>// I guess your dll will export __stdcall routines to support VB etc <BR>// the compiler will generaet __cdecl call convention if you reserve<BR>// the default settings. have a try ?<BR>2003-4-17 23:41:37
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -