Skip to content

Instantly share code, notes, and snippets.

@paxbun
Created October 21, 2020 11:20
Show Gist options
  • Select an option

  • Save paxbun/8e98a6851252efb7d9825d4977e57c1f to your computer and use it in GitHub Desktop.

Select an option

Save paxbun/8e98a6851252efb7d9825d4977e57c1f to your computer and use it in GitHub Desktop.
DLL calls functions in executable
#include <Windows.h>
#include <stdio.h>
extern "C" __declspec(dllexport) void ExportedFunction(char const* msg)
{
for (int i = 0; i < 5; ++i) printf("%s\n", msg);
}
int main()
{
HMODULE dll = LoadLibrary("module.dll");
void(*module_init)() = (void(*)())GetProcAddress(dll, "ModuleInit");
module_init();
}
#include <Windows.h>
#include <stdio.h>
extern "C" __declspec(dllexport) void ModuleInit()
{
HMODULE curr_proc = GetModuleHandle(NULL);
void(*exported_fn)(char*) = (void(*)(char*))GetProcAddress(curr_proc, "ExportedFunction");
exported_fn("Hello, world!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment