我写的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()之后,什么也没有发生,屏幕上没有hello或hi。你想弄清楚这个问题吗?非常感谢!
附注:我已经看了问题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.发布于 2011-05-29 08:24:54
经过几次尝试(alot :( )),我发现我错过了
#define DLL_EXPORT extern "C" __declspec(dllexport)这使得函数名称正确,最终成功地调用了DLLMain。无论如何,谢谢大家!
发布于 2011-05-28 21:16:02
我怀疑是你的控制台交互代码关闭了。你可以试着做一些不那么微妙的事情,比如打开一个窗口或者ShellExecute()一个声音。
发布于 2011-05-28 21:16:11
您在DLLMain中可以做的事情受到了严重的限制。具体地说,执行任何I/O通常都是禁忌。它的作用是进行一些简单的初始化,而不是像main()那样在可执行文件中执行。
https://stackoverflow.com/questions/6161844
复制相似问题