WinBioCaptureSampleWithCallback failed. OperationStatus = 0x80004001 - c++

I am trying to read fingerprints and save them using WBF.
I tried the sample code, however, I get an error code back. I am able to use the fingerprint reader to log into windows, but am unable to capture samples from it.
I am running Windows 10 on a Lenovo Yoga system, and VS 2015 Community.
This is what I get when I run my code:
Calling WinBioCaptureSampleWithCallback
Swipe the sensor ...
CaptureSampleCallback executing
Swipe processed - Unit ID: 0
WinBioCaptureSampleWithCallback failed. OperationStatus = 0x80004001
Press any key to exit...
Thank you!
Sample code:
HRESULT CaptureSampleWithCallback(BOOL bCancel)
{
HRESULT hr = S_OK;
WINBIO_SESSION_HANDLE sessionHandle = NULL;
// Connect to the system pool.
hr = WinBioOpenSession(
WINBIO_TYPE_FINGERPRINT, // Service provider
WINBIO_POOL_SYSTEM, // Pool type
WINBIO_FLAG_RAW, // Raw access
NULL, // Array of biometric unit IDs
0, // Count of biometric unit IDs
WINBIO_DB_DEFAULT, // Default database
&sessionHandle // [out] Session handle
);
if (FAILED(hr))
{
wprintf_s(L"\n WinBioOpenSession failed. hr = 0x%x\n", hr);
goto e_Exit;
}
// Capture a biometric sample asynchronously.
wprintf_s(L"\n Calling WinBioCaptureSampleWithCallback ");
hr = WinBioCaptureSampleWithCallback(
sessionHandle, // Open session handle
WINBIO_NO_PURPOSE_AVAILABLE, // Intended use of the sample
WINBIO_DATA_FLAG_RAW, // Sample format
CaptureSampleCallback, // Callback function
NULL // Optional context
);
if (FAILED(hr))
{
wprintf_s(L"\n WinBioCaptureSampleWithCallback failed. ");
wprintf_s(L"hr = 0x%x\n", hr);
goto e_Exit;
}
wprintf_s(L"\n Swipe the sensor ...\n");
// Cancel the capture process if the bCancel flag is set.
if (bCancel)
{
wprintf_s(L"\n Starting CANCEL timer...");
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 capture 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)
{
WinBioCloseSession(sessionHandle);
sessionHandle = NULL;
}
wprintf_s(L"\n Press any key to exit...");
_getch();
return hr;
}
//------------------------------------------------------------------------
// The following function is the callback for WinBioCaptureSampleWithCallback.
// The function filters the response from the biometric subsystem and
// writes a result to the console window.
//
VOID CALLBACK CaptureSampleCallback(
__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
)
{
UNREFERENCED_PARAMETER(CaptureCallbackContext);
wprintf_s(L"\n CaptureSampleCallback executing");
wprintf_s(L"\n Swipe processed - Unit ID: %d", UnitId);
if (FAILED(OperationStatus))
{
if (OperationStatus == WINBIO_E_BAD_CAPTURE)
{
wprintf_s(L"\n Bad capture; reason: %d\n", RejectDetail);
}
else
{
wprintf_s(L"\n WinBioCaptureSampleWithCallback failed. ");
wprintf_s(L" OperationStatus = 0x%x\n", OperationStatus);
}
goto e_Exit;
}
wprintf_s(L"\n Captured %d bytes.\n", SampleSize);
e_Exit:
if (Sample != NULL)
{
WinBioFree(Sample);
Sample = NULL;
}
}

Have you checked on google or with the SDK documentation what OperationStatus = 0x80004001 translates to? I am thinking you need to stop the windows service for the fingerprint before you embark on trying out the project you are developing on Visual Studio 2015.

Related

Video Processor MFT causes error 'The request is invalid in the current state'

I am using Media Foundation to create a webcam viewer.
Critical to this application is that the webcam stream is horizontally mirrored.
I am using the Video Processor MFT
to achieve this.
Here's the relevant code to add the MFT:
void tryMirror(IMFPMediaPlayer* pPlayer) {
IMFTransform* pMFT = NULL;
IMFVideoProcessorControl* pVPC = NULL;
HRESULT hr = CoCreateInstance(CLSID_VideoProcessorMFT, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pMFT));
if (FAILED(hr)) {
ShowHResultErrorMessage(L"CoCreateInstance(CLSID_VideoProcessorMFT, ...) failed", hr);
goto done;
}
hr = pMFT->QueryInterface(&pVPC);
if (FAILED(hr)) {
ShowHResultErrorMessage(L"pMFT->QueryInterface(&pVPC) failed", hr);
goto done;
}
hr = pVPC->SetMirror(MIRROR_HORIZONTAL);
if (FAILED(hr)) {
ShowHResultErrorMessage(L"pVPC->SetMirror(MIRROR_HORIZONTAL) failed", hr);
goto done;
}
hr = pPlayer->InsertEffect(pMFT, FALSE); // Not optional - critical functionality
if (FAILED(hr)) {
ShowHResultErrorMessage(L"m_pPlayer->InsertEffect(CLSID_VideoProcessorMFT) failed", hr);
goto done;
}
done:
SafeRelease(&pMFT);
SafeRelease(&pVPC);
}
// class CPreview implements IMFPMediaPlayerCallback as follows
void STDMETHODCALLTYPE CPreview::OnMediaPlayerEvent(MFP_EVENT_HEADER* pEventHeader) {
switch (pEventHeader->eEventType)
{
//...
case MFP_EVENT_TYPE_MEDIAITEM_SET:
OnMediaItemSet(MFP_GET_MEDIAITEM_SET_EVENT(pEventHeader));
break;
case MFP_EVENT_TYPE_PLAY:
OnMfpPlay(MFP_GET_PLAY_EVENT(pEventHeader));
break;
}
}
// Called after I set the webcam media source
void CPreview::OnMediaItemSet(MFP_MEDIAITEM_SET_EVENT* /*pEvent*/)
{
HRESULT hr = m_pPlayer->Play();
if (FAILED(hr)) {
ShowHResultErrorMessage(L"m_pPlayer->Play() failed", hr);
}
}
void CPreview::OnMfpPlay(MFP_PLAY_EVENT* pEvent) {
if (FAILED(pEvent->header.hrEvent)) {
ShowHResultErrorMessage(L"OnMfpPlay failed", pEvent->header.hrEvent);
WCHAR msg[1000];
HRESULT hr = StringCbPrintf(msg, sizeof(msg), L"Event type: 0x%X", pEvent->header.eEventType);
ShowErrorMessage(msg);
return;
}
}
void ShowHResultErrorMessage(PCWSTR errContext, HRESULT hrErr) {
_com_error err(hrErr);
LPCTSTR hrErrMsg = err.ErrorMessage();
WCHAR msg[1000];
HRESULT hr = StringCbPrintf(msg, sizeof(msg), L"%s (HRESULT=0x%X, %s)", errContext, hrErr, hrErrMsg);
if (SUCCEEDED(hr)) {
MessageBox(NULL, msg, L"Error", MB_ICONERROR);
}
}
On my development machine, this program runs without error, exactly as desired.
However, on a different user machine,
it fails with this error:
OnMfpPlay failed (HRESULT=0xC00D36B2, The request is invalid in the current state.)
That is,
this error comes through on the OnMediaPlayerEvent callback
of the IMFPMediaPlayerCallback object.
I do know a few things about the machine that this fails on:
The user has also run a modified version,
with the MFT set to optional, like so:
pPlayer->InsertEffect(pMFT, TRUE).
In this case, the program runs,
but the mirroring MFT has no effect.
The error is definitely caused by this MFT.
This user is running Windows 10, version 1909.
The Video Processor MFT is clearly available.
Its API claims to work - all HRESULTs are successful.
This error, "The request is invalid in the current state", could mean anything, and
I can't find any way to get more observability.
What does 'The request is invalid in the current state' mean?
Why is it generated by adding a Video Processor MFT, only on some machines?
How can I debug this with a more specific error?

Directshow - Cannot set still pin using SetMode

I am trying to get an image from the still pin of my camera using directshow (the framework the camera maker has suggested using).
I've been following the DirectShow MS documentation on https://learn.microsoft.com/en-gb/windows/desktop/DirectShow/capturing-an-image-from-a-still-image-pin and although I can find a still pin using the ICaptureGraphBuilder2::FindPin method and have confirmed that the pin exists on the camera using graphedit app, I've hit a brick wall in using the IAMVideoControl::SetMode method to change pin.
The code that I'm using is below:
HRESULT hr = CoInitializeEx(NULL, COINIT::COINIT_MULTITHREADED);
if (FAILED(hr))
Console::WriteLine("Initialise Failed");
else
Console::WriteLine("Initialise Success");
//Initalise graph builder
ICaptureGraphBuilder2 *pBuild;
IGraphBuilder *pGraph;
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL,
CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void **)&pBuild);
if (FAILED(hr))
Console::WriteLine("Graph builder failed");
else
Console::WriteLine("Graph builder success");
//Create filter graph
hr = CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, (void**)&pGraph);
if (SUCCEEDED(hr))
{
pBuild->SetFiltergraph(pGraph);
Console::WriteLine("Set filter graph success");
}
else
{
pBuild->Release();
Console::WriteLine("Set filter graph failed");
}
// Create the System Device Enumerator.
ICreateDevEnum *pDevEnum;
IEnumMoniker *pDevicesInfo;
HRESULT hr2 = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDevEnum));
if (SUCCEEDED(hr2))
{
Console::WriteLine("Device enum builder success");
// Create an enumerator for the video category.
hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pDevicesInfo, 0);
if (hr == S_FALSE)
Console::WriteLine("Retrieve video input devices failed");
else
Console::WriteLine("Retrieve video input devices success");
pDevEnum->Release();
}
//loop over video devices and find see3cam_130
IMoniker *pMoniker = NULL;
while (pDevicesInfo->Next(1, &pMoniker, NULL) == S_OK)
{
IPropertyBag *pPropBag;
HRESULT hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
if (FAILED(hr))
{
pMoniker->Release();
continue;
}
VARIANT var;
VariantInit(&var);
// Get description or friendly name.
hr = pPropBag->Read(L"FriendlyName", &var, 0);
if (SUCCEEDED(hr))
{
Console::WriteLine("Found video device");
//If correct device, break loop
if (0 == wcscmp(var.bstrVal, L"See3CAM_130"))
{
Console::WriteLine("See3CAM_130");
break;
}
else
{
Console::WriteLine("Comparison failed");
}
printf("%S\n", var.bstrVal);
VariantClear(&var);
}
else
{
Console::WriteLine("Vid Device failed");
}
}
//Create filter for device
IBaseFilter *pCap = NULL;
hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)&pCap);
if (SUCCEEDED(hr))
{
Console::WriteLine("Filter created");
hr = pGraph->AddFilter(pCap, L"Capture Filter");
if (SUCCEEDED(hr))
{
Console::WriteLine("Capture filter added to filter graph");
}
else
{
Console::WriteLine("Capture filter NOT added to filter graph");
}
}
else
Console::WriteLine("Filter failed");
//Render capture pin first before attempting to set still pin (setting still pin fails with ot without this step)
hr = pBuild->RenderStream(
&PIN_CATEGORY_CAPTURE, // Pin category.
&MEDIATYPE_Video, // Media type.
pCap, // Capture filter.
NULL, // Intermediate filter (optional).
NULL); // Mux or file sink filter.
if (SUCCEEDED(hr))
Console::WriteLine("Stream Render success");
else
Console::WriteLine("Stream Render failed");
//Create a control to run graph
IMediaControl *pControl;
hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
if (FAILED(hr))
Console::WriteLine("Graph initalised - Failed");
else
Console::WriteLine("Graph initalised - Success");
// Run the graph.
while (1)
{
hr = pControl->Run();
if (FAILED(hr))
Console::WriteLine("Graph run - Failed");
else
{
Console::WriteLine("Graph run - Success");
break;
}
}
//Find the still pin
IAMVideoControl *pAMVidControl = NULL;
hr = pCap->QueryInterface(IID_IAMVideoControl, (void**)&pAMVidControl);
if (SUCCEEDED(hr))
{
Console::WriteLine("Video Control Initialised - Success");
IPin *pPin = NULL;
hr = pBuild->FindPin(
pCap, // Filter.
PINDIR_OUTPUT, // Look for an output pin.
&PIN_CATEGORY_STILL, // Pin category.
NULL, // Media type (don't care).
FALSE, // Pin must be unconnected.
0, // Get the 0'th pin.
&pPin // Receives a pointer to thepin.
);
if (SUCCEEDED(hr))
{
Console::WriteLine("Find pin - Success");
hr = pAMVidControl->SetMode(pPin, VideoControlFlag_Trigger);
if (FAILED(hr))
Console::WriteLine("Pin Mode Set - Failed");
else
Console::WriteLine("Pin Mode Set - Success");
pPin->Release();
}
else
Console::WriteLine("Find pin - Failed");
}
else
Console::WriteLine("Video Control Initialised - Failed");
Everything succeeds until I try to use the SetMode method and I've no clue as to why...
I'm still a junior developer and quite inexperienced in c++ so I suspect I've missed a step somewhere. I've considered using the directshow.net wrapper but I don't want to waste the time I've spent getting this far.
Any hints on why IAMVideoControl::SetMode method fails in my code?
Note: The HResult error is ERROR_GEN_FAILURE (May be used to indicate that the device has stopped responding (hung) or a general failure has occurred on the device. The device may need to be manually reset.)
i have seen you query and you have to do lot of work to capture still frame.
After you enumerate the still pin, you should connect with sample grabber and null render into camera still pin.
After building and run the graph, you should trigger still mode and the frame will be received in the grabber.
then you can do with the frame whatever you wants.

Polling for audio sessions on default endpoint sometimes crashes on Win7

I'm working on an application which polls for the states and peak levels of audio sessions on the default audio rendering endpoint every X milliseconds, and implements some logic based on that.
It seems to run fine on Windows 10, but on Windows 7 I get occasional crashes when I change the default playback device (e.g. when I switch between my USB headset and the PC speaker).
The exact line where the crash occurs changes between runs, but it's usually when I access the IAudioSessionControl or IAudioSessionControl2 pointers to make various WASAPI calls.
What I could glean from the stack traces created by ProcDump and analyzed by WinDbg is that the COM objects representing audio sessions are destroyed when the default playback device has changed
(even though I had obtained and am still holding pointers to those objects' interfaces), and then my polling thread crashes randomly in places where I access them through the interface pointers.
I figured that maybe I'm doing something wrong, so this led me to Matthew van Eerde's
blog
and sample, where he does the same querying (and more), but for all available audio endpoints in the system.
So I modified his sample program to do it every 5 milliseconds and only for the default rendering endpoint, and I get the same occasional crashes on Windows 7.
Here is a stripped-down version of the sample, which sometimes results in crashes when switching between playback devices.
I usually get the crash within ~2 minutes of switching back-and-forth between devices. YMMV.
#include <windows.h>
#include <atlbase.h>
#include <stdio.h>
#include <mmdeviceapi.h>
#include <audiopolicy.h>
#include <endpointvolume.h>
#include <functiondiscoverykeys_devpkey.h>
#define LOG(format, ...) wprintf(format L"\n", __VA_ARGS__)
class CoUninitializeOnExit {
public:
CoUninitializeOnExit() {}
~CoUninitializeOnExit() {
CoUninitialize();
}
};
class PropVariantClearOnExit {
public:
PropVariantClearOnExit(PROPVARIANT *p) : m_p(p) {}
~PropVariantClearOnExit() {
PropVariantClear(m_p);
}
private:
PROPVARIANT *m_p;
};
int _cdecl wmain() {
HRESULT hr = S_OK;
hr = CoInitialize(NULL);
if (FAILED(hr)) {
LOG(L"CoInitialize failed: hr = 0x%08x", hr);
return -__LINE__;
}
CoUninitializeOnExit cuoe;
while (1)
{
Sleep(5);
// get default device
CComPtr<IMMDeviceEnumerator> pMMDeviceEnumerator;
hr = pMMDeviceEnumerator.CoCreateInstance(__uuidof(MMDeviceEnumerator));
if (FAILED(hr)) {
LOG(L"CoCreateInstance(IMMDeviceEnumerator) failed: hr = 0x%08x", hr);
return -__LINE__;
}
CComPtr<IMMDevice> pMMDevice;
hr = pMMDeviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pMMDevice);
if (FAILED(hr)) {
LOG(L"IMMDeviceEnumerator::GetDefaultAudioEndpoint failed: hr = 0x%08x", hr);
return -__LINE__;
}
// get the name of the endpoint
CComPtr<IPropertyStore> pPropertyStore;
hr = pMMDevice->OpenPropertyStore(STGM_READ, &pPropertyStore);
if (FAILED(hr)) {
LOG(L"IMMDevice::OpenPropertyStore failed: hr = 0x%08x", hr);
return -__LINE__;
}
PROPVARIANT v; PropVariantInit(&v);
PropVariantClearOnExit pvcoe(&v);
hr = pPropertyStore->GetValue(PKEY_Device_FriendlyName, &v);
if (FAILED(hr)) {
LOG(L"IPropertyStore::GetValue(PKEY_Device_FriendlyName) failed: hr = 0x%08x", hr);
return -__LINE__;
}
if (VT_LPWSTR != v.vt) {
LOG(L"PKEY_Device_FriendlyName has unexpected vartype %u", v.vt);
return -__LINE__;
}
LOG(L"Selected playback device: %s\n", v.pwszVal);
// get a session enumerator
CComPtr<IAudioSessionManager2> pAudioSessionManager2;
hr = pMMDevice->Activate(
__uuidof(IAudioSessionManager2),
CLSCTX_ALL,
nullptr,
reinterpret_cast<void **>(&pAudioSessionManager2)
);
if (FAILED(hr)) {
LOG(L"IMMDevice::Activate(IAudioSessionManager2) failed: hr = 0x%08x", hr);
return -__LINE__;
}
CComPtr<IAudioSessionEnumerator> pAudioSessionEnumerator;
hr = pAudioSessionManager2->GetSessionEnumerator(&pAudioSessionEnumerator);
if (FAILED(hr)) {
LOG(L"IAudioSessionManager2::GetSessionEnumerator() failed: hr = 0x%08x", hr);
return -__LINE__;
}
// iterate over all the sessions
int count = 0;
hr = pAudioSessionEnumerator->GetCount(&count);
if (FAILED(hr)) {
LOG(L"IAudioSessionEnumerator::GetCount() failed: hr = 0x%08x", hr);
return -__LINE__;
}
for (int session = 0; session < count; session++) {
// get the session control
CComPtr<IAudioSessionControl> pAudioSessionControl;
hr = pAudioSessionEnumerator->GetSession(session, &pAudioSessionControl);
if (FAILED(hr)) {
LOG(L"IAudioSessionEnumerator::GetSession() failed: hr = 0x%08x", hr);
return -__LINE__;
}
AudioSessionState state;
hr = pAudioSessionControl->GetState(&state);
if (FAILED(hr)) {
LOG(L"IAudioSessionControl::GetState() failed: hr = 0x%08x", hr);
return -__LINE__;
}
CComPtr<IAudioSessionControl2> pAudioSessionControl2;
hr = pAudioSessionControl->QueryInterface(IID_PPV_ARGS(&pAudioSessionControl2));
if (FAILED(hr)) {
LOG(L"IAudioSessionControl::QueryInterface(IAudioSessionControl2) failed: hr = 0x%08x", hr);
return -__LINE__;
}
DWORD pid = 0;
hr = pAudioSessionControl2->GetProcessId(&pid);
if (FAILED(hr)) {
LOG(L"IAudioSessionControl2::GetProcessId() failed: hr = 0x%08x", hr);
return -__LINE__;
}
hr = pAudioSessionControl2->IsSystemSoundsSession();
if (FAILED(hr)) {
LOG(L"IAudioSessionControl2::IsSystemSoundsSession() failed: hr = 0x%08x", hr);
return -__LINE__;
}
bool bIsSystemSoundsSession = (S_OK == hr);
// get the current audio peak meter level for this session
CComPtr<IAudioMeterInformation> pAudioMeterInformation;
hr = pAudioSessionControl->QueryInterface(IID_PPV_ARGS(&pAudioMeterInformation));
if (FAILED(hr)) {
LOG(L"IAudioSessionControl::QueryInterface(IAudioMeterInformation) failed: hr = 0x%08x", hr);
return -__LINE__;
}
float peak = 0.0f;
hr = pAudioMeterInformation->GetPeakValue(&peak);
if (FAILED(hr)) {
LOG(L"IAudioMeterInformation::GetPeakValue() failed: hr = 0x%08x", hr);
return -__LINE__;
}
LOG(
L" Session #%d\n"
L" State: %d\n"
L" Peak value: %g\n"
L" Process ID: %u\n"
L" System sounds session: %s",
session,
state,
peak,
pid,
(bIsSystemSoundsSession ? L"yes" : L"no")
);
} // session
} // while
return 0;
}
Here is one instance of a crash dump analysis: https://pastebin.com/tvRV8ukY.
Is this an issue with the Windows 7 implementation of the Core Audio APIs, or am I doing something wrong?
Thanks.
I eventually contacted Matthew van Eerde by e-mail, and he said it does look like a race condition in Core Audio API on Windows 7, and my best bet is to file a support request to Microsoft.
Thanks for your help, Matthew!

Microsoft Fingerprint SDK C++ winbio.lib not working [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I'm currently working on a Fingerprint verification project and I've already configured all the drivers properly. I'm using Microsoft Fingerprint Reader and it works when i tested it with the software DigitalPersona during login. I currently have windows sdk 7.0A and I'm using Microsoft Visual Studio 2010.
I created an "empty project" for this code and I've linked additional library dependencies to the windows sdk and type the winbio.lib under the "input" for additional dependencies. i got this error.
error C2065: 'CaptureSampleCallback' : undeclared identifier
Here's the code, i followed exactly the microsoft's sample but it can't work =(
http://msdn.microsoft.com/en-us/library/windows/desktop/dd401603(v=vs.85).aspx
#include <Windows.h>
#include <Conio.h>
#include <Stdio.h>
#include <WinBio.h>
HRESULT CaptureSampleWithCallback(BOOL bCancel)
{
HRESULT hr = S_OK;
WINBIO_SESSION_HANDLE sessionHandle = NULL;
// Connect to the system pool.
hr = WinBioOpenSession(
WINBIO_TYPE_FINGERPRINT, // Service provider
WINBIO_POOL_SYSTEM, // Pool type
WINBIO_FLAG_RAW, // Raw access
NULL, // Array of biometric unit IDs
0, // Count of biometric unit IDs
WINBIO_DB_DEFAULT, // Default database
&sessionHandle // [out] Session handle
);
if (FAILED(hr))
{
wprintf_s(L"\n WinBioOpenSession failed. hr = 0x%x\n", hr);
goto e_Exit;
}
// Capture a biometric sample asynchronously.
wprintf_s(L"\n Calling WinBioCaptureSampleWithCallback ");
hr = WinBioCaptureSampleWithCallback(
sessionHandle, // Open session handle
WINBIO_NO_PURPOSE_AVAILABLE, // Intended use of the sample
WINBIO_DATA_FLAG_RAW, // Sample format
CaptureSampleCallback, // Callback function
NULL // Optional context
);
if (FAILED(hr))
{
wprintf_s(L"\n WinBioCaptureSampleWithCallback failed. ");
wprintf_s(L"hr = 0x%x\n", hr);
goto e_Exit;
}
wprintf_s(L"\n Swipe the sensor ...\n");
// Cancel the capture process if the bCancel flag is set.
if (bCancel)
{
wprintf_s(L"\n Starting CANCEL timer...");
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 capture 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)
{
WinBioCloseSession(sessionHandle);
sessionHandle = NULL;
}
wprintf_s(L"\n Press any key to exit...");
_getch();
return hr;
}
//------------------------------------------------------------------------
// The following function is the callback for WinBioCaptureSampleWithCallback.
// The function filters the response from the biometric subsystem and
// writes a result to the console window.
//
VOID CALLBACK CaptureSampleCallback(
__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
)
{
UNREFERENCED_PARAMETER(CaptureCallbackContext);
wprintf_s(L"\n CaptureSampleCallback executing");
wprintf_s(L"\n Swipe processed - Unit ID: %d", UnitId);
if (FAILED(OperationStatus))
{
if (OperationStatus == WINBIO_E_BAD_CAPTURE)
{
wprintf_s(L"\n Bad capture; reason: %d\n", RejectDetail);
}
else
{
wprintf_s(L"\n WinBioCaptureSampleWithCallback failed. ");
wprintf_s(L" OperationStatus = 0x%x\n", OperationStatus);
}
goto e_Exit;
}
wprintf_s(L"\n Captured %d bytes.\n", SampleSize);
e_Exit:
if (Sample != NULL)
{
WinBioFree(Sample);
Sample = NULL;
}
}
You have two solutions:
A. function prototype before calling CaptureSampleCallback
VOID CALLBACK CaptureSampleCallback(
__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
);
B. Move definition of function CaptureSampleCallback before CaptureSampleWithCallback

error C2664 : cannot convert parameter ( fingerprint sensor detection)

I'm having this error and I can't find how to solve this. Which parameter should i change? I am having this error.
error C2664: 'WinBioLocateSensorWithCallback' : cannot convert parameter 2 from 'void (__stdcall *)(void)' to 'PWINBIO_LOCATE_SENSOR_CALLBACK'
Thanks for your help guys!
Here is the code
#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);
}
Your problem is that your definition for LocateSensorCallback doesn't match the signature that the WinBioLocateSensorWithCallback function expects.
Change your forward declaration at the top from
VOID CALLBACK LocateSensorCallback();
to match the actual function:
VOID CALLBACK LocateSensorCallback(
__in_opt PVOID LocateCallbackContext,
__in HRESULT OperationStatus,
__in WINBIO_UNIT_ID UnitId
);