Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working on demo bio metric project in MFC
On msdn we have some callback functions but for use that we need to create pointer to member function how to do it.

Getting this error:

Error 1 error C2440: '=' : cannot convert from 'void (__stdcall CBioMetricApplicationDlg::* )(PVOID,HRESULT,WINBIO_UNIT_ID,PWINBIO_BIR,SIZE_T,WINBIO_REJECT_DETAIL)' to 'void (__thiscall CBioMetricApplicationDlg::* )(PVOID,HRESULT,WINBIO_UNIT_ID,PWINBIO_BIR,SIZE_T,WINBIO_REJECT_DETAIL)'

What I have tried:

// in header file CBioMetricApplicationDlg.h ...

VOID CALLBACK CaptureCallback(
__in_opt PVOID CaptureCallbackContext,
__in HRESULT OperationStatus,
__in WINBIO_UNIT_ID UnitId,
__in_bcount(SampleSize) PWINBIO_BIR Sample,
__in SIZE_T SampleSize,
__in WINBIO_REJECT_DETAIL RejectDetail
);


VOID CALLBACK(CBioMetricApplicationDlg:: *pCaptureCallback) (
__in_opt PVOID CaptureCallbackContext,
__in HRESULT OperationStatus,
__in WINBIO_UNIT_ID UnitId,
__in_bcount(SampleSize) PWINBIO_BIR Sample,
__in SIZE_T SampleSize,
__in WINBIO_REJECT_DETAIL RejectDetail
);


// in cpp file CBioMetricApplicationDlg.cpp
//in the OnInitDialog() 

// TODO: Add extra initialization here
pCaptureCallback = &CBioMetricApplicationDlg::CaptureCallback;
Posted
Updated 19-Apr-17 22:35pm

It is common to use a typedef for such functions because it makes it easier to declare pointers.

For your case see PWINBIO_CAPTURE_CALLBACK function pointer (Windows)[^]:
typedef VOID ( CALLBACK *PWINBIO_CAPTURE_CALLBACK)(
  _In_opt_ PVOID                CaptureCallbackContext,
  _In_     HRESULT              OperationStatus,
  _In_     WINBIO_UNIT_ID       UnitId,
  _In_     PWINBIO_BIR          Sample,
  _In_     SIZE_T               SampleSize,
  _In_     WINBIO_REJECT_DETAIL RejectDetail
);

Then declare the variable as
PWINBIO_CAPTURE_CALLBACK pCaptureCallback;

[EDIT]
I was not sure how CALLBACK is resolved. But it seems that it does not contain static. Because callback functions must be static, the declaration as class member function must be
/* CBioMetricApplicationDlg.h */
static VOID CALLBACK CaptureCallback(
    __in_opt PVOID CaptureCallbackContext,
    __in HRESULT OperationStatus,
    __in WINBIO_UNIT_ID UnitId,
    __in_bcount(SampleSize) PWINBIO_BIR Sample,
    __in SIZE_T SampleSize,
    __in WINBIO_REJECT_DETAIL RejectDetail
    );
To get access to the class within the callback function pass this as context parameter:
/* CBioMetricApplicationDlg.cpp */
hr = WinBioCaptureSampleWithCallback(
    sessionHandle,
    WINBIO_NO_PURPOSE_AVAILABLE,
    WINBIO_DATA_FLAG_RAW,
    CaptureSampleCallback,
    this);
and cast the parameter in the callback function:
/* CBioMetricApplicationDlg.cpp */
VOID CBioMetricApplicationDlg::CaptureCallback(
    __in_opt PVOID CaptureCallbackContext,
    __in HRESULT OperationStatus,
    __in WINBIO_UNIT_ID UnitId,
    __in_bcount(SampleSize) PWINBIO_BIR Sample,
    __in SIZE_T SampleSize,
    __in WINBIO_REJECT_DETAIL RejectDetail
    )
{
    CBioMetricApplicationDlg *pThis = reinterpret_cast<CBioMetricApplicationDlg*>(CaptureCallbackContext);
    // Use pThis to access class members
    // ...
}
[/EDIT]
 
Share this answer
 
v2
Comments
Premnath Mali 20-Apr-17 7:21am    
getting this error while initialization
pCaptureCallback = &CBioMetricApplicationDlg::CaptureCallback;
Jochen Arndt 20-Apr-17 7:28am    
Still the same error?
I can't test it here at the moment.
You can try to simplify the typedef:
typedef VOID (*PWINBIO_CAPTURE_CALLBACK)(
  PVOID                CaptureCallbackContext,
  HRESULT              OperationStatus,
  WINBIO_UNIT_ID       UnitId,
  PWINBIO_BIR          Sample,
  SIZE_T               SampleSize,
  WINBIO_REJECT_DETAIL RejectDetail
);

This assumes that CALLBACK resolves to something containing static.
If not you have to declare the function as static in your header file:
static VOID CALLBACK CaptureCallback(
// ...
Premnath Mali 20-Apr-17 8:10am    
//in header file
VOID CALLBACK CaptureCallback(
__in_opt PVOID CaptureCallbackContext,
__in HRESULT OperationStatus,
__in WINBIO_UNIT_ID UnitId,
__in_bcount(SampleSize) PWINBIO_BIR Sample,
__in SIZE_T SampleSize,
__in WINBIO_REJECT_DETAIL RejectDetail
);

typedef VOID ( CALLBACK *PWINBIO_CAPTURE_CALLBACK)(
  _In_opt_ PVOID                CaptureCallbackContext,
  _In_     HRESULT              OperationStatus,
  _In_     WINBIO_UNIT_ID       UnitId,
  _In_     PWINBIO_BIR          Sample,
  _In_     SIZE_T               SampleSize,
  _In_     WINBIO_REJECT_DETAIL RejectDetail
);

PWINBIO_CAPTURE_CALLBACK pCaptureCallback;


//in onInitDialog()
pCaptureCallback = &CBioMetricApplicationDlg::CaptureCallback;


//in Cpp file Defination of callback method
VOID CALLBACK CBioMetricApplicationDlg::CaptureCallback(PVOID CaptureCallbackContext, 
														HRESULT OperationStatus, 
														WINBIO_UNIT_ID UnitId, 
														PWINBIO_BIR Sample, 
														SIZE_T SampleSize, 
														WINBIO_REJECT_DETAIL RejectDetail)
{
	//defination
}


and the error is...

error C2440: '=' : cannot convert from 'void (__stdcall CBioMetricApplicationDlg::* )(PVOID,HRESULT,WINBIO_UNIT_ID,PWINBIO_BIR,SIZE_T,WINBIO_REJECT_DETAIL)' to 'CBioMetricApplicationDlg::PWINBIO_CAPTURE_CALLBACK'
Jochen Arndt 20-Apr-17 8:16am    
So CALLBACK is not containing static (use follow symbol in the context menu)?

Then you must declare the callback function as static in the header file (2nd option from my previous comment).
Premnath Mali 20-Apr-17 8:20am    
Also this error I'm getting
error C2724: 'CBioMetricApplicationDlg::CaptureCallback' : 'static' should not be used on member functions defined at file scope
The address of the object (this)is the first Implicit parm to any class method. So try declaring pcapturecallback as:
Void callback (cbiometricapplicationdlg::*pcapturecallback)(cbiometricapplicationdlg *thisobj, __in__opt pvoid capturecallbackcontext, <rest of params>);
does it work?
 
Share this answer
 
Comments
Jochen Arndt 20-Apr-17 4:36am    
A callback function is static and has therefore no this pointer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900