View Full Version : Using SetFrameReadyCallback with C Wrapper

May 31, 2013, 19:19:10
I have created a Delphi wrapper for the CWrapper and all of the functions I have tested so far seem to work.
I am trying to get the callback to work but I don't realy understand the example in Ansi.c

Within the callback I would like to hand the raw image data to a display routine.
Should I be using pData and if so do I need to test whether it is valid?
Can you indicate the function call sequence that is needed leading up to SetFrameReadyCallback ()?
Also can you verify the size in bytes of the elements of the ICGrab structure?



Tim Cassens
June 4, 2013, 14:52:43
Lets have a look at the declaration of the functions:

int IC_SetFrameReadyCallback( HGRABBER hGrabber, FRAME_READY_CALLBACK cb, void* user_data);

typedef void (*FRAME_READY_CALLBACK) (HGRABBER hGrabber, unsigned char* pData, unsigned long frameNumber, void* user_data );

The user_data parameter is simply passed to the callback, allowing you to have some context inside the callback function without relying on global data.

It looks like the AnsiC.c example does not do a very good job at demonstrating this. Yon don't need to replicate the SSICGrab structure, unless you have some kind of context to provide to your callback. And if you do, you need to define your own data structure.

I think the example in AnsiC.c shows which other function calls are needed to make IC_SetFrameReadyCallback work:

IC_ShowDeviceSelectionDialog lets you select and configure a device - you definitely need that
IC_SetFormat sets the image format of the data passed to your callback function
IC_SetContinuousMode enabled continuous capture. If this is not enabled, the frameReady event wont be raised for every frame
IC_SetFrameReadyCallback registers the callback function
IC_StartLive starts the camera according to everything configured above

August 13, 2013, 11:12:36
The information above was helpful but I am still unable to get my code working after several days of trying and the example and function descriptions are not quite enough to allow me to debug successfully. I am using the dfg/usb2pro device and if I call StartLive with the parameter set to 1 it successfully shows the camera image. But my problem is in getting the code to work with StartLive parameter set to 0.

Would it be possible to provide a simple piece of verified working code that does the following:
Makes all the necessary initialisation calls including any necessary memory allocation
Calls IC_ContinuousMode
Calls IC_StartLive with parameter set to 0
Uses the pData parameter within the callback
if( pData != NULL )
for( p = 0; p < 15; p++)
printf("%2X ",pData[p]);


August 13, 2013, 19:13:39
OK some progress.

This User Thread is helpful in explaining return values from function calls and the calling convention of the callback function.


I now have a simple piece of code as outlined above working by changing the calling convention from stdcall to cdecl