c++ - Dllmain 没有被调用?

标签 c++

我正在写这样一个 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/

相关文章:

c++ - 使用VSCode中的MSVS编译器构建OpenCV应用程序

c++ - 调试断言失败

c++ - 以 std::out_of_range: basic_string 类型的未捕获异常终止

c++ - 在构造函数中混合可变参数模板和初始化列表

c++ - C 库 - 在 C++ 中使用 : redefinition, 不同的类型修饰符

c++ - 创建具有该名称的变量后调用 native C 函数

c++ - 模板化类构造函数的模板实例化

c++ - 组合 C++ 有问题

c++ - 派生类的 vptr 何时初始化?

c++ - 导入位图使我的窗口滞后