I need some help with C++


I have never done anything with C++ but I have some project that I must now do with C++ in Visual Studio 2010. Microsoft has provided some APIs for working with Biometric fingerprint readers but it is all in C++. I need a kick start with just one of these. My exact problem problem is:

1) What does this part of the code mean and how to I create that:

To compile this sample, link to the Winbio.lib static library and include the following header files:


2) All the sample codes seem to be starting with this:

HRESULT CaptureSampleWithCallback(BOOL bCancel)
    HRESULT hr = S_OK;

I don't see C++ classes starting with that, so I don't know what this part of the code means. Where should I use/paste it?

I think I need just to figure out the first sample: where to put this code and how to execute it, then I should be ready to follow through with the other samples.

the code is here

Thank you.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I am afraid it will be a rather longer run than you expect. The .h files (h for header) are source files that (by convention) contain function prototypes (that is how the function looks like for calling -- name of the function and number and types of parameters), or class definitions (the same -- interface to the class, what the methods are and what parameters they expect), or various constants.

Another complication is that C++ is backward compatible and some of the ready-to-be-used code (libraries) are actually implemented using the C subset of the language. This is often the case for the libraries that are close to the OS core. Some programmers still prefer C way of coding as they still do not "feel" the fresh wind of modern C++. (Visual Studio 2010 does not implement the C++11 standard, the newer versions do.)

The case of the header file names usually matters -- probably not so much in Windows, but you should get used to using the recommended case.

The stdio.h is the only header file defined by standard. When working with C++ you should #include <cstdio> instead. See here for details http://www.cplusplus.com/reference/cstdio/

conio.h stands for console input/output and its origin was DOS. http://en.wikipedia.org/wiki/Conio.h

windows.h defines the interface to the Windows OS.

The Winbio.h will be specific for the biometric device.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
i know from your other thread that you have a full c/c++ code example for the biometric functions.

if you would put that source to a c++ dll project in visual studio, it is a good chance that you get the project built with little changes (it is mostly to add a header file which would export the functions needed to be called by VB.NET or C#).

after that you would have two choices:

one is to add managed c++ code to the dll (such creating a so-called mixed assembly) and make it a bridge between your .NET application and the dll functions. the managed c++ classes in the dll could be used directly in your VB.NET or C# project.

second choice is to call the exported functions of the c++ directly from your code. this can be the faster way granted that the sample code already provides all the functionality you need.

I don't see C++ classes starting with that, so I don't know what this part of the code means.
in c and c++ you can define global functions which are not bound to a class context. the code you posted was a so-called callback function. a callback can be used for asynchronous communication with another thread. from your thread - mostly the main thread with the gui - you send a request to a subsystem by calling a function. this request wasn't processed immediately but was put into a queue. the subsystem asynchronously processes the request and provides the response (result) by calling a callback function. the function was passed with the request by means of a function pointer. a function pointer is an address in the process' address space. in your case the address was pointing to the object code of function CaptureSampleWithCallback which was defined above main function. a callback function always needs two parts. one is the function pointer to the function and the second is some kind of a "handle" which was passed as argument to the callback function such that it "knows" for which request it was called back. you normally would use a pointer to the request (structure or class) for this.

main thread:
       - create request
       - create worker thread and pass the request

worker thread:
       - call subsystem and pass request arguments + callback function + handle to request as arguments.
       - request was stored in a queue managed by the subsystem
       - thread waits for request status was turning from 'open' to 'answered'

subsystem (biometric driver):
       - reads request from queue
       - processes the request and builds result
       - calls callback function by pointer and passes handle + result as arguments
         (the call would run asynchronously in a further thread of your process)

callback function (callback thread):
       - stores result
       - maps the result to the request by using the request handle
       - sets the request status to 'answered'

worker thread:
       - returns from wait state
       - sends message to main thread that the request was finished.
       - exits from thread

main thread:
       - processes message from worker thread
       - updates gui and show results

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

hmamboAuthor Commented:
Thank you all very much for the responses.

I figured out this was a tall order for me so I found a friend who codes in C++ and we have been able to do console applications for the scripts that I needed. Basically: 1) Biometric Enroll & Capture, 2) Biometric Identify.

We have now run into another glitch with the enroll. we can seem to be able to enroll more than one fingerprint. We get the error 0x8009801c, indicating that the Identity has been enrolled. We are using this code

Is there any reference we can use to get past this? C++ is fine, we are able to work with it.

Thank you very much.
seems as you would need to call EnrollSysPoolWithCallback again with the bCancel and bDiscard flag set to true, before you can do a second enrollment.

if you look at the code of EnrollSysPoolWithCallback you can see that it either can enroll and commit or cancel and disregard an enrollment. if you would split the function into two functions one for enrolling and one for discarding, the design probably would be better ...

hmamboAuthor Commented:
Thanks, Sara.

I think I was not very clear in my previous question. We are able to register several fingerprints (thumb, index, etc) of one person/profile. What we need is to register fingerprints (eg, just the thumb) for several different people (eg, employees) and to be able to verify which of them swiped their finger by comparing with what we stored. I am thinking this requires storing the fingerprints in some sort of database.

Our current application allows us to save the fingerprint of the currently logged in person and verifies it when we swipe it later, but we want to verify different people using this one application/scanner.

sorry, i missed the last comment somehow.

I am thinking this requires storing the fingerprints in some sort of database
since you already saved the fingerprint of the currently logged-in user (somehow) and can verify a new scan against this, you only have to do this verification in a loop and either use multiple files - one for each registered user - or if stored fingerprints always have same size (or there is a maximum size), you could create a binary file where each record exactly is one stored fingerprint associated to a user.

#define MAXSIZ_FP 4096
struct FingerPrintRecord
      char szusernname[32];
      int    recsize;
      unsigned char fingerprint[MAXSIZ_FP];

Open in new window

to find out whether a new scan is valid, you would read the file record by record and check the scan against the buffer:

// pass new scan and check against all stored prints
std::string FindUserByFingerPrint(unsigned char * new_fingerprint, int sizfp)
      std::ifstream ifs("myfingerprintfile", std::ios::binary || std::ios::in);
      MyStruct ms;
      std::string struser;
      while (ifs.read((char *)&ms, sizeof(ms))
            if (CheckFingerPrint(ms.fingerprint, new_fingerprint))
                 struser = ms.szusername;
      return struser;

Open in new window

@evilrix: Sara tried harder. She should get more points ;)
thanks pepr

since i missed the last response i shouldn't get any points ...

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.