我正在写这样一个 dllmain:
#include "main.h"
#include "init.h"
#include <iostream>
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
//std::cout<<"hi\n"; //only for debug. did not shown.
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
// attach to process
// return FALSE to fail DLL load
//std::cout<<"hello\n"; //only for debug. did not shown.
init(); //did not run :(
break;
case DLL_PROCESS_DETACH:
// detach from process
break;
case DLL_THREAD_ATTACH:
// attach to thread
break;
case DLL_THREAD_DETACH:
// detach from thread
break;
}
return TRUE; // succesful
}
但是在一个测试程序使用LoadLibrary()之后,没有任何反应, 屏幕上没有你好或嗨。 你想弄清楚这个问题吗?非常感谢!
附言我看过问题DllMain not being called 但它仍然无济于事。
PS2:调用程序是这样的
int main()
{
cout<<"This is a test program to test.\n";
HINSTANCE hinstDLL;
hinstDLL=LoadLibrary("ijl15.dll");
cout<<"Look like everything goes well.\n";
cout<<hinstDLL;
return 0;
}
测试程序输出:
This is a test program to test.
Look like everything goes well.
0x6a980000
Process returned 0 (0x0) execution time : 0.007 s
Press any key to continue.
最佳答案
经过一些尝试(很多 :( ) 我发现我错过了
#define DLL_EXPORT extern "C" __declspec(dllexport)
这使得函数名正确,最终成功调用了DLLMain。总之谢谢大家!
关于c++ - Dllmain 没有被调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6161844/