Skip to content

Instantly share code, notes, and snippets.

@livz
Created Jul 21, 2017
Embed
What would you like to do?
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