-
-
Save livz/7fb6d6a97ac8719748915f02ea477d14 to your computer and use it in GitHub Desktop.
Dynamic DLL loading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Compile with cl: | |
* cl /nologo /EHsc DllDynamic.c | |
* | |
*/ | |
#include <Windows.h> | |
typedef int (WINAPI * ptrMessageBox)(HWND, LPCTSTR, LPCTSTR, UINT); | |
ptrMessageBox fMessageBox; | |
int main(int argc, char **argv) | |
{ | |
/* Resolve imports */ | |
HMODULE hUser32 = LoadLibraryA("user32.dll"); | |
fMessageBox = (ptrMessageBox) GetProcAddress(hUser32, "MessageBoxA"); | |
if (NULL == fMessageBox) { | |
printf("Error loading function."); | |
return 1; | |
} | |
fMessageBox(NULL, "A process is loading the DLL", "Title", MB_OK); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment