injecting dll not working?

1.1k views Asked by At

i have created a simple dll. I am injecting it in a process but it not showing message box.The code for mesg box is written in dll.

dll code:

//DLL TEST
#include <windows.h>

BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved) {
     if(callReason == DLL_PROCESS_ATTACH)
                   MessageBox(0, "Dll Injection Successful! ", "Dll Injector", MB_ICONEXCLAMATION | MB_OK);
     return TRUE;
}
1

There are 1 answers

0
Oleg On

First of all you don't posted the code which you use to inject the DLL or at least not described ich which way you do the injection.

Nevertheless your code have a large problem. You try to call MessageBox inside of DllMain. It is safe to use only functions from the Kernel32.dll and not form User32.dll which can not be initialized. On the MSDN you can read

Calling functions that require DLLs other than Kernel32.dll may result in problems that are difficult to diagnose. For example, calling User, Shell, and COM functions can cause access violation errors, because some functions load other system components.