Creating DLL's
Introduction
I greatly prefer a UNIX development environment, but sometimes It seems I'm almost forced to develop in Visual Studio (I.E building reflective DLLs). Here are some notes on building DLL's with Visual Studio.
Creating a DLL
To create a DLL in Visual Studio click: Create a Project, set the programming language to C++, and select Dynamic Link Library (DLL).

Adding external functions.
To add an external function use the extern keyword
extern __declspec(dllexport) BOOL ReflectiveFunction() {
}
Template
#include <windows.h>
#include <stdio.h>
VOID PayloadFunction() {
MessageBoxA(NULL, "Foo", "Bar", MB_OK | MB_ICONINFORMATION);
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved) {
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
PayloadFunction();
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
extern __declspec(dllexport) BOOL ReflectiveFunction() {
}
Extra
Best Practices
Makefile
I know I'll be looking for this somewhere so here's the Makefile. If developing on linux, it's crucial we compile the DLL correctly.
x86_64-w64-mingw32-gcc LdrDll.c -s -w -Wall -Wextra -masm=intel -shared -fPIC -e DllMain -Os -fno-asynchronous-unwind-tables Source/* -I Include -o Reflective.dll -lntdll -luser32 -DWIN_X64
Last updated