Skip to content

Instantly share code, notes, and snippets.

@henriquerichter
Last active July 29, 2017 18:38
Show Gist options
  • Select an option

  • Save henriquerichter/c21993581413e8e2227bf2d166542563 to your computer and use it in GitHub Desktop.

Select an option

Save henriquerichter/c21993581413e8e2227bf2d166542563 to your computer and use it in GitHub Desktop.
Simple DLL loading example, windows only
#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);
}
#pragma once
#include <stdio.h>
extern "C" {
__declspec (dllexport) int func1();
}
void __declspec (dllexport) func2();
void func3();
char* a = "test test\n";
#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