Skip to content

Instantly share code, notes, and snippets.

@livz
Created July 21, 2017 15:24
Show Gist options
  • Save livz/7fb6d6a97ac8719748915f02ea477d14 to your computer and use it in GitHub Desktop.
Save livz/7fb6d6a97ac8719748915f02ea477d14 to your computer and use it in GitHub Desktop.
Dynamic DLL loading
/*
* 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