HMODULE glibpid = NULL;
typedef double(*fPID)(double sp, double pv, double Kc, double Ti, double Td, double outputHigh, double outputLow);
if (glibpid != NULL)
{
}
glibpid = LoadLibrary(_T("SharedLib.dll"));
if (glibpid)
{
//功能代碼
}
BOOL bRetFree = FreeLibrary(glibpid);
if (!bRetFree)
{
AfxMessageBox(_T("glibpid卸載失敗"));
}
else
{
glibpid = NULL;
}
呼叫代碼如上,使用完了FreeLibrary dll是成功的。
然后當再次需要加載dll時候,同樣的代碼,glibpid = LoadLibrary(_T("SharedLib.dll"));這一步會卡一會,然后程式直接停止運行了。然后輸出內容如下:
“ZJYTEST.exe”(Win32): 已加載“D:\priject\ZJYTEST\539YDJTEST\SharedLib.dll”。模塊已生成,不包含符號。
First-chance exception at 0x74B456E8 in ZJYTEST.exe: Microsoft C++ exception: LVExcept at memory location 0x0580E8BC.
First-chance exception at 0x74B456E8 in ZJYTEST.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
First-chance exception at 0x74B456E8 in ZJYTEST.exe: Microsoft C++ exception: LVExcept at memory location 0x0580E8B8.
First-chance exception at 0x74B456E8 in ZJYTEST.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
First-chance exception at 0x74B456E8 in ZJYTEST.exe: Microsoft C++ exception: LVExcept at memory location 0x0580E8B8.
First-chance exception at 0x74B456E8 in ZJYTEST.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
First-chance exception at 0x74B456E8 in ZJYTEST.exe: Microsoft C++ exception: LVExcept at memory location 0x0580E8B8.
First-chance exception at 0x74B456E8 in ZJYTEST.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
First-chance exception at 0x74B456E8 in ZJYTEST.exe: Microsoft C++ exception: LVExcept at memory location 0x0580E8B8.
First-chance exception at 0x74B456E8 in ZJYTEST.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
First-chance exception at 0x74B456E8 in ZJYTEST.exe: Microsoft C++ exception: LVExcept at memory location 0x0580E8B8.
First-chance exception at 0x74B456E8 in ZJYTEST.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
First-chance exception at 0x74B456E8 in ZJYTEST.exe: Microsoft C++ exception: LVExcept at memory location 0x0580E89C.
First-chance exception at 0x74B456E8 in ZJYTEST.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
First-chance exception at 0x74B456E8 in ZJYTEST.exe: Microsoft C++ exception: LVExcept at memory location 0x0580E89C.
First-chance exception at 0x74B456E8 in ZJYTEST.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
執行緒 0x6f0 已退出,回傳值為 259 (0x103)。
執行緒 0x25f4 已退出,回傳值為 259 (0x103)。
請教這是什么問題?
uj5u.com熱心網友回復:
程式結束 時 FreeLibrary 一次 不好嗎 ?uj5u.com熱心網友回復:
光重復 LoadLibrary FreeLibrary 有問題嗎?是否中間有什么程序沒有正確釋放記憶體?
https://forums.ni.com/?profile.language=zh-CN
uj5u.com熱心網友回復:
我 記得 系統 為了 防止 dll 反復 load , FreeLibrary dll 后 dll 沒有 立即 free 要 經過 15 分鐘 后 才 真正 freeuj5u.com熱心網友回復:
我在工程路徑下有幾個dll副本,debug路徑下有,原始碼檔案夾下也有。然后我只留下debug檔案夾下的dll再試就好了。我沒想明白什么原因。uj5u.com熱心網友回復:
呼叫完是free了的,free函式回傳值也是成功的。應該沒有15分鐘的限制吧?感覺不合理uj5u.com熱心網友回復:
我又試了別的dll.不是很穩定,有時候重復呼叫沒問題,有時候就調不上程式直接停止運行。然后輸出口就是LVExcept和[rethrow]。
這個問題是不是dll內部問題呢?LVExcept是LabView拋的例外吧
uj5u.com熱心網友回復:
不同環境下的兼容性是比較麻煩的事,可以先試試 try catch __try __except 等捕捉例外
再不行就考慮LabView和MFC做兩個獨立的App,用檔案、socket等進行行程間通信
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/8986.html
標籤:基礎類
