Thread: Asynchronous Operation In Main

  1. #1
    Registered User
    Join Date
    Aug 2008

    Asynchronous Operation In Main

    Hi everyone,

    I'm testing an optical fingerprint device which has an asynchronous operation with a flow like the following:

    1) LoadFG() - This will initialize device, camera, etc

    2) SetProp() - Set frame grabber properties like LED, capture modes, etc

    3) StartCapture() - This functions returns immediately but it triggers asynchrounous operation capturing images at intervals "in the background" untill StopCapture() is called.

    StartCapture() takes the following callback functions as parameters

    1) OnImage

    2) OnFinger

    3) OnError

    I just want to write a simple test in my main function. How do I handle the async operations so that my main doesn't terminate before I stop the async operation properly.

    I'm using Visual Studio 2008.

    #include "stdafx.h"
    #include <iostream>
    #include <Windows.h>
    //This header defines all the data structures
    #include "Devicevcdefs.h"
    //The DLL header
    #include "Devicevc.h"
    #pragma comment(lib, "Device.lib")
    using namespace std;
    /////////////////////////Callback Functions //////////////////////////
    // The Image Event
    void OnImage( int nFGHandle, unsigned int nChannel, DRM_VC_BYTE* pImage, void* pClientData )
    	cout<< "OnImage" << endl;
    // The finger event
    void OnFinger( int nFGHandle, unsigned int nChannelNo, int nType, DRM_VC_BYTE* pImage, void* pClientData )
    	cout << "OnFinger" <<  endl;	
    // The error event
    void OnError( int nFGHandle, unsigned int nChannel, const char* szErrMsg, void* pClientData )
    	 cout << "Error: " << szErrMsg <<  endl;
    // The warning event
    void OnWarning( int nFGHandle, unsigned int nChannel, const char* szWarningMsg, void* pClientData )
    	 cout << "Warning: " << szWarningMsg <<  endl;
    //////////////////////////End Callback Functions///////////////////////
    int _tmain(int argc, _TCHAR* argv[])
    	int nFGHandle;
    	// Load the frame grabber from the dl which in turns initialize the device
    	//FG_PLS1 is device type enum
    	loadFGStatus = LoadFG(FG_PLS1, nFGHandle);
    	if(loadFGStatus == DEVICE_NOERROR){
    		//Output 0 which is OK
    		cout << loadFGStatus << endl;
    		//Output 1 which is OK
    		cout << nFGHandle << endl;
    		//Set The device LED to green
    		SetFGProperty (nFGHandle, FG_GREEN_LED, 1);	
    		//I'm stuck here!
    		//The asynchrounous operation, this method returns immediately but 
    		//triggers image capture intervals in the background
    		//Will only stop after issuing StopCapture()
    		StartCapture( nFGHandle, 1, PLAIN_FINGER , OnImage , OnFinger , OnError , OnWarning , NULL );
    		//Next Steps here....
    	return 0;
    Pardon my noob question, I'm not a professional, just a lone business operator trying to get things done within budget and without going out of business. Any tips?

    Thank you in advanced!

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    you need to add some waiting loop. Example of the loop could be found here Named Pipe Server Using Completion Routines (Windows)

    if you do not have any event you want to wait (which will be signaled when processing is done)

    you can wait for the current thread handle - this wait will exit only due to messages to be processed, you will need to use some boolean flag indicating that the loop should be broken
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  3. #3
    Registered User
    Join Date
    Aug 2008
    Thanks Vart, that is a good example.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. loading vectors and data before main
    By lawrenced in forum C++ Programming
    Replies: 8
    Last Post: 07-30-2009, 01:42 PM
  2. Return Statement
    By Daveo in forum C Programming
    Replies: 21
    Last Post: 11-09-2004, 05:14 AM
  3. int main (), main (), main (void), int main (void) HELP!!!
    By SmokingMonkey in forum C++ Programming
    Replies: 7
    Last Post: 05-31-2003, 09:46 PM
  4. Help w/ program
    By Newbie96 in forum C++ Programming
    Replies: 3
    Last Post: 02-24-2003, 02:55 PM
  5. void or int for main?:)
    By bigtamscot in forum C Programming
    Replies: 13
    Last Post: 09-27-2001, 03:11 AM