I have a SDK from a third party -- A camera vendor (Hasselblad) that has provided an SDK for interfacing a PC to his camera. The SDK consists of a C++ DLL and an unmanaged C++ sample application that uses the DLL. I am able to get all the methods properly marshalled into my C# code except the CALLBACK. Also, the sample application runs just fine from their unmanaged C++ source code. The DLL header for the C++ CALLBACK looks like this:
#define PHOCUS_API __declspec( dllexport )
#define PHOCUS_API_CALL __stdcall
typedef HRESULT (CALLBACK *STATUS_MESSAGE_CALLBACK )( void* ref, HRESULT hr, LPCWSTR pszMessage );
PHOCUS_API HRESULT PHOCUS_API_CALL SetStatusMessageCallback( HANDLE hClient, STATUS_MESSAGE_CALLBACK pfnCallback, void* ref );
What I have tried:
I have the following import statements at the top of a simple Main entry point as well as the delegate and event definitions.
[DllImport("PhocusApi64.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
public static extern Int32 SetStatusMessageCallback(IntPtr hClient, STATUS_MESSAGE_CALLBACK PhocusMessageCallback, IntPtr refx);
public delegate Int32 STATUS_MESSAGE_CALLBACK(IntPtr refs, Int32 HRESULT, String szMessage);
public static event STATUS_MESSAGE_CALLBACK MessageResponse;
I use other DLL methods to create handles to the installed camera devices (PhocusDevices[0]). I can use these handles to do functions such as setting the aperture, getting the serial number etc. Also, I can command the camera to take a picture. The variable "Result" is returned from the DLL methods and indicate that the methods are working properly. In the sample application that I am replicating in the managed code, the CALLBACK fires properly and I can step into the C++ code. My C# code compiles w/o error and I can step through all the C# statements without exceptions. In the C# case, I cannot get the delegate to fire after commanding a image capture -- although I hear the camera trigger and can access the image. I have the following statements in my C# code.
IntPtr Result = SetStatusMessageCallback(PhocusDevices[0], ResponseAfterImageDownload, (IntPtr)0);
static Int32 ResponseAfterImageDownload(IntPtr refs, Int32 HRESULT, String
MessageResponse += ResponseAfterImageDownload;
static Int32 ResponseAfterImageDownload(IntPtr refs, Int32 HRESULT, String szMessage)
{
int a = 0;
return 0;
}
Your thoughts would be appreciated ...
Jim