?? subject_36716.htm
字號:
<p>
序號:36716 發(fā)表者:小丫多多 發(fā)表日期:2003-04-17 22:17:44
<br>主題:求教顯式加載DLL文件的問題!!
<br>內(nèi)容:我正在做一個數(shù)據(jù)采集的軟件,使用了一塊pc總線數(shù)據(jù)采集控制卡。<BR>隨該卡僅提供了一個DLL文件及一個在win2000下使用的驅(qū)動程序。<BR>安裝完驅(qū)動之后,dll文件自動考入WINNT\SYSTEM32目錄下。<BR>于是我在程序中顯示加載了該DLL,具體代碼如下:(我使用的是WIN2000系統(tǒng))<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>系統(tǒng)編譯通過,運行時time = GetCounter();能正常運行,但一但運行到<BR> value = ReadChData(768, 0, 150, 30);<BR> OutPort(770, 0);<BR> Delay(10000);<BR><BR>這類帶有參數(shù)的函數(shù)時就會彈出消息框:debug error!<BR>說是函數(shù)調(diào)用方式不合適。<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>回復(fù)者:xiongli 回復(fù)日期:2003-04-17 23:28:38
<br>內(nèi)容:可能是dll里面delay 函數(shù)參數(shù)聲明跟你程序里面的參數(shù)聲明不相同<BR>所以在最后函數(shù)返回的時候堆棧被破壞
<br>
<a href="javascript:history.go(-1)">返回上頁</a><br><a href=http://www.copathway.com/cndevforum/>訪問論壇</a></p></blockquote>
<hr size=1>
<blockquote><p>
回復(fù)者:dr0 回復(fù)日期:2003-04-17 23:40:55
<br>內(nèi)容: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
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -