2

I am working on a time attendance software that work with biometric time attendance device. The vendor of the device provided a COM Class library "zemkeeper" that you have to register and link to it.

In the demo they provided they used it in GUI winform app and it works and it worked for me too.

zkemkeeper.CZKEMClass axCZKEM1 = new zkemkeeper.CZKEMClass();
bool bIsConnected = axCZKEM1.Connect_Net(txtIP.Text, Convert.ToInt32(txtPort.Text));

 if (bIsConnected == true)
            {
                btnConnect.Text = "DisConnect";
                btnConnect.Refresh();
                lblState.Text = "Current State:Connected";
                iMachineNumber = 1;//In fact,when you are using the tcp/ip communication,this parameter will be ignored,that is any integer will all right.Here we use 1.
                if (axCZKEM1.RegEvent(iMachineNumber, 65535))//Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
                {
                    this.axCZKEM1.OnFinger += new zkemkeeper._IZKEMEvents_OnFingerEventHandler(axCZKEM1_OnFinger);
                    ...
                }
            }
            else
            {
                axCZKEM1.GetLastError(ref idwErrorCode);
                MessageBox.Show("Unable to connect the device,ErrorCode=" + idwErrorCode.ToString(), "Error");
            }
}

But when I tried to build a windows service the registered event doesn't fire at all. I tried to do the same thing using a console app but it doesnt work too.

What is the problem ? does this type of COM object require a GUI to be able to handle events ? if yes is their any work around it ?

Thanks in advance.

Ayoub M.
  • 4,690
  • 10
  • 42
  • 52
  • 2
    Yes, it is the kind of COM object that requires [an STA thread](http://stackoverflow.com/a/21684059/17034). – Hans Passant Oct 13 '15 at 15:52
  • Check [this](http://stackoverflow.com/q/21438747/1768303) and [this](http://stackoverflow.com/q/18296834/1768303). – noseratio Oct 13 '15 at 19:49

1 Answers1

1

I had same problem.I have finally found a solution.You need to crate STA thread for that. Check the following links.

If your project is Windows Application,, you no need to do this. because the STA main thread run form calling Applcation.Run(Form). Check following links.

Raising Custom Class Events In Windows Service C#

http://www.codeproject.com/Questions/711973/Using-Zkemkeeper-dll-from-SDK-for-Biometric-scanne

Community
  • 1
  • 1
Poorna
  • 323
  • 7
  • 20