Created
October 21, 2020 11:20
-
-
Save paxbun/8e98a6851252efb7d9825d4977e57c1f to your computer and use it in GitHub Desktop.
DLL calls functions in executable
This file contains hidden or 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
| #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(); | |
| } |
This file contains hidden or 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
| #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