I have been coding in C# for many years. My experience in C++ is limited.
BACKGROUND: I have a C++ project in VS 2017 that is almost complete. My project employs the use of a Contour Shuttle device. To receive event notifications in my project from the device, I have to register for device event notifications by way of a windows style CALLBACK function. The SDK provided with the device has all the methods and definitions required to communicate with the device (I have already created a similar project in C# using the same SDK using multicast delegates, and it works excellent).
MY PROBLEM: I know that I have to use pointers to my methods to get the CALLBACK to work. I have been trying for 4 WEEKS to get my code to run. No success. The only success I have had is if I use a global static void. I can then register and receive events perfectly fine, BUT since it is a static global void I cannot access the methods and variables in my class.
I just do not understand how to do it properly. Here is my code:
Header File: (provided with SDK)
#ifndef _SHUTTLESDK_LIB_
#define _SHUTTLESDK_LIB_
#ifdef __cplusplus
#define SHUTTLESDK_API extern "C"
#else
#define SHUTTLESDK_API
#endif
typedef void (CALLBACK *SHUTTLEEVENTPROC)(DWORD event, UCHAR status, WORD type, WORD devno);
SHUTTLESDK_API int WINAPI Shuttle_Register_Callback_Global(SHUTTLEEVENTPROC shuttleproc, WORD type, WORD devno);
SHUTTLESDK_API int WINAPI Shuttle_Unregister_Callback(WORD type, WORD devno);
code file (only relevant code included):
...//
Shuttle_Plugin::void Start()
{
if (Shuttle_Register_Callback_Global(*ShuttleCallback, 3, 1) != SHUTTLESDK_OK)
{
//Handle the error here...
return;
}
}
Shuttle_Plugin::void CALLBACK ShuttleCallback(DWORD event, UCHAR status, WORD type, WORD devno)
{
//Events from callback should emit values here...
}
//...
This will ONLY work if I declare the CALLBACK ShuttleCallback method in the global scope.
I understand that I am supposed to supply a pointer to my CALLBACK function, but I do not understand pointers that well yet.
Can someone please kindly show me the correct way to implement this in my project?
I have basically been thinking about / working on / testing code on this for 4 weeks, and I cannot explain to you the frustration I am having.
Foot Note: Yes, I have searched StackOverflow, Google, all the usual go-to forums. There are none that I can relate back to my specific case. Everyone uses ''FOO BAR notation'' and describes and debates the best way to do it, or the better way to do it, but I can't seem to find a simple, contextual example to help me out.