I'm writing a C++ programm that dynamically loads a dll at runtime and calls a function within that dll. Thats working fine but now i want to call a function defined in my C++ programm from within the dll.
My main.cpp looks like this:
#include <Windows.h>
#include <iostream>
typedef void(*callC)(int);
int main()
{
HINSTANCE dllHandle = LoadLibrary("D:\Libraries\lib.dll");
callC func = (callC)GetProcAddress(dllHandle, "callC");
func(42);
FreeLibrary(dllHandle);
}
// I want to call this function from my dll
void callableFromDll(){
}
The part of the dll thats accessed is writtin in C and looks like as follows:
#include <stdio.h>
void callC(int);
void callC(int i){
print(i);
// Call the C++ function
//callableFromDll();
}
I've read about the __declspec(dllimport)
and __declspec(dllexport)
attributes but im really new to C++ and not sure if these are the right thing to use and if so, how to use them.