I am trying to integrate a native C++ DLL (used to drive a video camera) into a C++/CLI project.
So I wrote a wrapper class for this DLL in order to have managed-compatible types for my DLL function calls.
Most of the class-content is about importing the functions in the following way:
[ DllImport("camera.dll") ]
static System::IntPtr CameraOpen(unsigned long index);//C++/CLI
//HANDLE CAM_EXPORT CameraOpen(unsigned long index); //C++
Then I create an instance of that class in my main project class and call the functions. That works fine.
Now I am getting very frustrated trying to import a function from the DLL which takes a pointer to a global callback function (this callback is called when a new video frame is available).
In C++, the prototype of that function is the following:
static LONG CAM_EXPORT CameraAddStreamingCallback(HANDLE hCamera, VOID (__stdcall *VideoFilter)(VOID *pContext, BYTE *pData, ULONG dataLength), VOID *pCBContext);
and the declaration of the prototype callback function (VideoFilter) is the following:
// Callback function prototype void __stdcall VideoFilter(VOID *pContext, BYTE *pData, ULONG dataLength);
From spending days browsing the net for a solution I figured that I need to use a delegate function (please refrain from applausing) in order to do this but I miserably failed to implement it.
What I have done so far is the following:
Inside my wrapper class:
static long CameraAddStreamingCallback(System::IntPtr hCamera, System::Void (*VideoFilter)(System::Void *pContext, System::Byte *pData, unsigned long dataLength), System::Void *pCBContext);
Then I have a global declaration of the delegate:
delegate System::Void VideoFilter(System::Void *pContext, System::Byte *pData, unsigned long dataLength);
That compiles fine. But then I am stuck on how to use this delegate with the function.
I tried to call it in one function of my wrapper class the following way:
m_lSnapCallbackRegistration = CameraAddStreamingCallback(m_hCamera, VideoFilter, this);
But I get the following compile error:
error C2275: 'VideoFilter' : illegal use of this type as an expression
see declaration of VideoFilter
Ca anyone point me to the solution....?
Thanks in advance and sorry for the long post.