問題如下: 我給patchupdate添加殺木馬功能是調用了一個dll內的函數,我是靜態鏈接的(就是include這個函數的頭文件,鏈接了個.lib。patchupdate程序是先更新本身的,它把自己更新完了就重新啟動,這時因為其依賴那個dll,所以報錯“找不到某個dll”,那肯定沒法更新下來那個dll文件了。
經高手指點,用動態鏈接dll的方法成功解決了此問題!故寫此文以記之!
下面把幾個API的使用例子代碼貼出來,方便以后查看,這個代碼可以在msdn里找到的。
#include <windows.h>
typedef int (*MYPROC)(LPTSTR);
int _tmain(int argc, _TCHAR* argv[])
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
hinstLib = ::LoadLibrary(TEXT("myputs.dll"));
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) ::GetProcAddress(hinstLib, "PatchUpdate"); /// 函數 PatchUpdate();
// If the function address is valid, call the function.
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
(ProcAdd) (TEXT("Message via DLL function\n"));
}
// Free the DLL module.
fFreeResult = ::FreeLibrary(hinstLib);
}
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess)
printf("Message via alternative method\n");
return 0;
}
typedef int (*MYPROC)(LPTSTR);
int _tmain(int argc, _TCHAR* argv[])
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
hinstLib = ::LoadLibrary(TEXT("myputs.dll"));
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) ::GetProcAddress(hinstLib, "PatchUpdate"); /// 函數 PatchUpdate();
// If the function address is valid, call the function.
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
(ProcAdd) (TEXT("Message via DLL function\n"));
}
// Free the DLL module.
fFreeResult = ::FreeLibrary(hinstLib);
}
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess)
printf("Message via alternative method\n");
return 0;
}
2007-10-23
現在又改成靜態鏈接的了,因為動態鏈接的話,只要把殺木馬的dll干掉就沒作用了。這樣子沒了這個dll就得重新安裝客戶端或者從別的地方拖這個dll過來,patchupdate才能啟動起來。
要把patchupdate用QT寫的話,如果要玩家不用重新下載客戶端的話,就得:
1.把Qt編譯成靜態庫,patchupdate鏈接用到的靜態庫。
or
2.改變更新次序,讓patchupdate先更新下Qt的dll下來(指定這個更新順序不能寫在patchupdate自身里面,得靠srvflist.xml),這樣子的好處是patchupdate本身不會很大,其他用到Qt的東西也可以與其共享Qt的dll,比如獨立于客戶端的聊天軟件
ps:剛才看了下,更新順序是寫在patchupdate里面的。所以否定2方法。