I am trying to write a class in a dll that uses a callback function from another dll. currently i can get the callback to work when i am calling it in a main function but i am having problems integrating it in my own dll.
I am using Hinstance in the regular project and the dll im compiling. This works in a regular project:
void mycallback(float values[], __int64 timestamp, int status) {
//stuff
globalval[0]=values[0];
...
}
void main(){
...
void(*_callback)(float[], __int64, int);
_callback = &mycallback;
API_CALLBACK finalCallBack = (API_CALLBACK)_callback;
....
//I pass this callback in another function that the api uses later
}
However this fails when I try to port it in the initialise function in a class that I am compiling as a dll (I was trying to use bind function but #include was giving me errors (using visual studios 2015)
void MyClass::mycallback(float values[], __int64 timestamp, int status){
//stuff
myClassval[0]=values[0];
...
}
MyClass::Init(){
void(*_callback)(float[], __int64, int);=
_callback = &MyClass::mycallback;<---This line is giving me error
API_CALLBACK finalCallBack = (API_CALLBACK)_callback;
}
The error i get is "assigning to ' void(*)(float *,long long, int)' from incompaible type 'void(MyClass::*)(float *,long long,int)"
Is there a different way I should approach this? I am not sure how to handle this as I have only access to the function callbacks but not the source.
edit: I realise that casting mycallback as static would solve the problem but then I would run into the problem of being unable to store the value somewhere. or is there a good way to do this?
full code for further reference:
void main() {
//declare dll handler
HINSTANCE hinstLib;
FCALL _InitDevices,_ReleaseDevices;
FCALL_GETHMDINFO _getHMDinfo;
FCALL_HMDPRESENT _HMDPresent;
FCALL_STARTTRACKING _StartTracking;
BOOL fFreeResult;
//Load dll
hinstLib = LoadLibrary(TEXT("thirdparty.dll"));
bool* isHMDpresent = new bool;
void(*_hmdcallback)(float[], __int64, int);
_hmdcallback = &hmdcallback;
HMD_TRACK_CALLBACK hmdCallBack = (HMD_TRACK_CALLBACK)_hmdcallback;
//float handle = (float)hmdCallBack;
//if dll present
if (hinstLib != NULL)
{
//initialise devices
_InitDevices = (FCALL)GetProcAddress(hinstLib, "InitDevices");
if (NULL != _InitDevices)
{
std::cout<<(_InitDevices)()<<std::endl;
}
//start tracking
_StartTracking = (FCALL_STARTTRACKING)GetProcAddress(hinstLib, "StartTracking");
if (NULL != _StartTracking)
{
std::cout << (_StartTracking)(hmdCallBack,nullptr,nullptr,nullptr) << std::endl;
}
this is the function from the 3rd party dll
DLL_EXPORT typedef void(__stdcall *HMD_TRACK_CALLBACK)(float values[], __int64 timestamp, int status );
I am trying to convert the above and package it in another dll(a driver) with other functions from multiple dlls. The specific task i am trying to do now is to store an array from the callback of the dll i am using. In this case, one of the things im storing is values[]