Last active
July 29, 2017 18:38
-
-
Save henriquerichter/c21993581413e8e2227bf2d166542563 to your computer and use it in GitHub Desktop.
Simple DLL loading example, windows only
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 "DLLLoad.h" | |
| int func1() { | |
| printf("func1\n"); | |
| func2(); | |
| printf("done\n"); | |
| return 132; | |
| } | |
| void func2() { | |
| printf("func2\n"); func3(); } | |
| void func3() { | |
| printf("func3\n"); | |
| printf("hey\n"); | |
| printf(a); | |
| } |
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
| #pragma once | |
| #include <stdio.h> | |
| extern "C" { | |
| __declspec (dllexport) int func1(); | |
| } | |
| void __declspec (dllexport) func2(); | |
| void func3(); | |
| char* a = "test test\n"; |
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 <iostream> | |
| typedef int(*func_ptr_t) (); | |
| int main(int args, char **argc){ | |
| HINSTANCE dll = LoadLibrary("DLLTest.dll"); | |
| if (dll) { | |
| func_ptr_t a = (func_ptr_t) GetProcAddress(dll, "func1"); | |
| if (!a) { | |
| printf("Function not found"); | |
| } | |
| else { | |
| int n = a(); | |
| std::cout << n << std::endl; | |
| } | |
| } | |
| else { | |
| printf("dll not found"); | |
| } | |
| system("pause"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment