错误C2664:无法转换参数(指纹传感器检测)

时间:2014-01-24 09:14:09

标签: c++ parameters

我有这个错误,我找不到如何解决这个问题。我应该更改哪个参数?我有这个错误。

 error C2664: 'WinBioLocateSensorWithCallback' : cannot convert parameter 2 from 'void (__stdcall *)(void)' to 'PWINBIO_LOCATE_SENSOR_CALLBACK'

感谢您的帮助!

这是代码

#include <Windows.h>
#include <Conio.h>
#include <Stdio.h>
#include <WinBio.h>
VOID CALLBACK LocateSensorCallback();

 HRESULT LocateSensorWithCallback(BOOL bCancel)
{
  HRESULT hr = S_OK;
WINBIO_SESSION_HANDLE sessionHandle = NULL;
WINBIO_UNIT_ID unitId = 0;

// Connect to the system pool. 
hr = WinBioOpenSession( 
        WINBIO_TYPE_FINGERPRINT,    // Service provider
        WINBIO_POOL_SYSTEM,         // Pool type
        WINBIO_FLAG_DEFAULT,        // Configuration and access
        NULL,                       // Array of biometric unit IDs
        0,                          // Count of biometric unit IDs
        NULL,                       // Database ID
        &sessionHandle              // [out] Session handle
        );
if (FAILED(hr))
{
    wprintf_s(L"\n WinBioOpenSession failed. hr = 0x%x\n", hr);
    goto e_Exit;
}

wprintf_s(L"\n Calling WinBioLocateSensorWithCallback.");
hr = WinBioLocateSensorWithCallback(
            sessionHandle,          // Open biometric session
            LocateSensorCallback,   // Callback function
            NULL                    // Optional context
            );
if (FAILED(hr))
{
    wprintf_s(L"\n WinBioLocateSensorWithCallback failed.");
    wprintf_s(L"hr = 0x%x\n", hr);
    goto e_Exit;
}
wprintf_s(L"\n Swipe the sensor ...\n");

// Cancel the identification if the bCancel flag is set.
if (bCancel)
{
    wprintf_s(L"\n Starting CANCEL timer...\n");
    Sleep( 7000 );

    wprintf_s(L"\n Calling WinBioCancel\n");
    hr = WinBioCancel( sessionHandle );
    if (FAILED(hr))
    {
        wprintf_s(L"\n WinBioCancel failed. hr = 0x%x\n", hr);
        goto e_Exit;
    }
}

// Wait for the asynchronous identification process to complete 
// or be canceled.
hr = WinBioWait( sessionHandle );
if (FAILED(hr))
{
    wprintf_s(L"\n WinBioWait failed. hr = 0x%x\n", hr);
}

e_Exit:

if (sessionHandle != NULL)
{
   wprintf_s(L"\n Closing the session.\n");

    hr = WinBioCloseSession(sessionHandle);
    if (FAILED(hr))
    {
        wprintf_s(L"\n WinBioCloseSession failed. hr = 0x%x\n", hr);
    }
    sessionHandle = NULL;
}

wprintf_s(L"\n Hit any key to exit...");
_getch();

return hr;
 }

//------------------------------------------------------------------------
// The following function is the callback for 
// WinBioLocateSensorWithCallback. The function filters the response 
// from the biometric subsystem and writes a result to the console window.
// 
VOID CALLBACK LocateSensorCallback(
__in_opt PVOID LocateCallbackContext,
__in HRESULT OperationStatus,
__in WINBIO_UNIT_ID UnitId
)
{
UNREFERENCED_PARAMETER(LocateCallbackContext);

wprintf_s(L"\n LocateSensorCallback executing.");

// A sensor could not be located.
if (FAILED(OperationStatus))
{
    wprintf_s(L"\n LocateSensorCallback failed.");
    wprintf_s(L"OperationStatus = 0x%x\n", OperationStatus);
}
// A sensor was located.
else
{
    wprintf_s(L"\n Selected unit ID: %d\n", UnitId);
}
}



 void main()

 {
 LocateSensorWithCallback(1);
 }

1 个答案:

答案 0 :(得分:0)

您的问题是LocateSensorCallback的定义与WinBioLocateSensorWithCallback函数所期望的签名不匹配。

顶部更改前方声明
VOID CALLBACK LocateSensorCallback();

匹配实际功能:

VOID CALLBACK LocateSensorCallback(
__in_opt PVOID LocateCallbackContext,
__in HRESULT OperationStatus,
__in WINBIO_UNIT_ID UnitId
);