DLL.h
#pragma once #ifdef _WIN32 # ifdef BUILDING_MY_LIB # define MY_EXPORT __declspec(dllexport) # else # define MY_EXPORT __declspec(dllimport) # endif #else # define MY_EXPORT __attribute__ ((visibility ("default"))) #endif // declare as dll method MY_EXPORT void passDTMFToClient(int id, DTMF_01 packet);
Ensure that header is included by both you dll.cpp and exe.cpp. Ensure in your dll build you define 'BUILDING_MY_LIB' when compiling on windows. When compiling the dll you should also get a link library (e.g. you'll have mydll.dll and mydll.lib on windows).
Your exe now just need to include the dll.h, and link to the mydll.lib (or mydll.so on linux). If your app can find the dll, it will automatically be loaded.
If you wish to go one step further and load the dll on the fly into your exe, you'll probably want to change the function prototype to:
MY_EXPORT extern "C" void passDTMFToClient(int id, DTMF_01 packet);
Which will disable name mangling. You should be able to open the DLL using LoadLibrary on windows, or dlopen on linux. e.g.
// on windows HMODULE dllHandle = LoadLibrary("mydll.dll"); // on linux void* dllHandle = dlopen("mydll.dll", RTLD_NOW);
You will need a function pointer, e.g.
// typedef func type typedef void (*passDTMFToClient_func)(int, DTMF_01); // the function pointer passDTMFToClient_func passDTMFToClient = 0;
You should then just need to get the symbol address, which you do like so on windows:
passDTMFToClient = (passDTMFToClient_func)GetProcAddress(dllHandle, "passDTMFToClient");
And like so on linux:
passDTMFToClient = (passDTMFToClient_func)dlsym(dllHandle, "passDTMFToClient");
And when you're done with the DLL, you can close it again:
// windows FreeModule(dllHandle); // linux dlclose(dllHandle);