I am trying to load a .dll
file and have it display a message box when loaded. From my understanding, once a .dll
is loaded, it makes a call to dllmain()
and switches to the DLL_PROCESS_ATTACH
option. I have written the code for both the .dll
and the .exe
which loads it. The .exe
can load it correctly and print out the address in which the dll has been loaded, but I do not see a message box being displayed. I read somewhere on Microsoft.com that the dll enters a "lock" when loaded as to prevent certain functions or code from being executed for security purposes. Is this feature blocking a message box from being displayed? Is there a work around such as elevated privileges, system, etc...? I am not sure if DEP has any effect either, I have it set to only protect critical Windows processes.
The calling process:
#include <iostream>
#include <windows.h>
int main()
{
HMODULE hDll = LoadLibraryA("dll.dll");
if (hDll == NULL)
std::cerr << "Unable to load dll";
else
std::cout << "Dll loaded @ " << hDll;
FreeLibrary(hDll);
}
The dll file:
#include <windows.h>
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
MessageBox(NULL, "Dll has been loaded.", "Loaded", MB_OK);
break;
}
return TRUE;
}
I think it might help me if I had a way to run the .dll
though a debugger and see what MessageBox()
returned, but I am not sure how to do that. Thanks!