BOOL WINAPI DllMain(HINSTANCE hinstDL...">

Dllmain not called?

I wrote dllmain as follows:

#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
}

but after the test program uses LoadLibrary (), nothing happened, there is no greeting or hello on the screen. Do you want to find out the problem? Many thanks!

PS I looked at the DllMain question , which does not get called but it still does not help.

PS2: Caller program is similar to

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;
}

The output of the tester program:

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.
+5
source share
4 answers

After some attempts (alot :() I found that I missed

#define DLL_EXPORT extern "C" __declspec(dllexport)

This is the correct function name, and finally, DLLMain is successfully called. Anyway, thanks to all of you!

+8
source

, . - , , ShellExecute() .

+1

, DLLMain. , - -, , -. , main() .

+1

LoadLibrary ( cout<<hinstDLL)?

DLL PATH?

DLL ( vs debug)?

0

All Articles