前提:QT寫的界面,轉換成VC可調用的dll。
問題1:編譯通過,但出現dll裝載句柄爲NULL,GetLastError()返回126,代碼如下:
SetCurrentDirectory("E:\\"); //ABC.dll目錄爲E:\ABC.
HMODULE handle = LoadLibrary("ABC.dll"); //ABC.dll爲QT生成的庫
int m=0;
if (handle == NULL){
m=GetLastError(); //m=126
if(m)
return ;
}
經查:如果遇到LoadLibray,返回錯誤代碼爲126的時候,要考慮缺少調用庫的依賴庫,於是將QT的依賴庫都拷貝到E:\下後。
問題2:出現窗口:This application failed to start because it could not find or load the Qt platform plugin "windows".
reinstalling the application may fix this problem.
m=998
將代碼改爲:
HMODULE handle = LoadLibrary("ABC.dll"); //ABC.dll爲QT生成的庫
int m=0;
if (handle == NULL){
m=GetLastError();
if(m)
return ;
}
將所有的庫都放到VC debug下exe同一目錄下,程序運行正常。
總結:調用QTdll後,生成的exe與QT 所有依賴庫都得一個目錄下才能正確運行。