DllMain没有执行
我是DLL编程新手,刚才试了一下,发现DllMain没有执行,但是却可以执行DllMain所在的DLL的其他函数,这是怎么回事啊?
DLL里面试这样的:
- C/C++ code
#include <Windows.h>#include <iostream>int WINAPI DLLMain ( HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved ){ switch(fdwReason) { case DLL_PROCESS_ATTACH: std::cout<<"DLL is attached!"<<std::endl; break; case DLL_PROCESS_DETACH: std::cout<<"DLL is detached!"<<std::endl; break; } return true;}void FuncInDll(void){ std::cout<<"FuncInDll is called!"<<std::endl;}主函数则是:
- C/C++ code
#include<Windows.h>#include <iostream>using namespace std;int main(){ typedef void (*DLLWITHLIB)(void); DLLWITHLIB pfFuncInDll = NULL; HINSTANCE hinst = ::LoadLibraryA("myHook.dll"); if(NULL != hinst) { cout<<"DLL loaded~"<<endl; } pfFuncInDll = (DLLWITHLIB)GetProcAddress(hinst, "FuncInDll"); if(pfFuncInDll) { (*pfFuncInDll)(); } return 0;}本来应该输出:
DLL is attached!
DLL loaded~
FuncInDll is called!
DLL is detached!
但是只输出了:
DLL loaded~
FuncInDll is called!
感觉好像DLLMain没有进入?
这么回事啊。。求大侠!!
[解决办法]
DLLMain -> DllMain 鉴定完毕