libreria zkteco9500 libzkfpcsharp.dll ERROR Attempted to read or write protected memory

296 Views Asked by At

I have a problem when reading the fingerprints on the zk9500, I get a memory error

enter image description here

I tried it with both x86 and x64 libraries but they give me the same error, at first it captures the fingerprint and shows it but after doing several fingerprint tests the error appears, perhaps the allowed memory is full and I should empty it with each fingerprint reading or maybe the value entered is null.

In addition, the data that enters the variables shown in the image are:

  • FPBuffer = 90000
  • CapTmp = 2048
  • cbCapTmp = 2048 For FPBuffer there are:
  • mfpWidth = 300
  • mfpHeight = 300

I'm use this demo text and I adapt it to my C# project, I use all your code as indicated

Could someone help me on how to debug to find the problem or I would also like if someone could tell me what I'm doing wrong.

1

There are 1 best solutions below

0
jstuardo On

I think there is an initialization problem. Fingerprint template that is read is not always of the same size so maybe you have some kind of buffer overrun. Also, I recommend using zkfp2 object everywhere instead of a new instance of zkfp.

Please, try the following code:

private void DoCapture()
{
    byte[] fpBuffer = new byte[_fpWidth * _fpHeight];
    byte[] capTmp = new byte[2048];
    while (!_isTimeToDie)
    {
        int cbCapTmp = 2048;

        int ret = zkfp2.AcquireFingerprint(_devHandle, fpBuffer, capTmp, ref cbCapTmp);
        if (ret == zkfp.ZKFP_ERR_OK)
        {
            ProcessFingerPrint(fpBuffer, capTmp, cbCapTmp);
        }

        if (ret != zkfp.ZKFP_ERR_CAPTURE && ret != zkfp.ZKFP_ERR_OK)
            OnDriverError(ret, string.Empty);

        Thread.Sleep(200);
    }
}

both _fpWidth and _fpHeight are retrieved the same way as the demo, and _devHandle is the result of zkfp2.OpenDevice(0).

By using zkfp2 everywhere (instead a creating a new instance of zkfp) you have to make some other changes in the demo code as well.

For example, to open the device, use _devHandle = zkfp2.OpenDevice(0) and to close it, zkfp2.CloseDevice(_devHandle).

To initialize the library, use zkfp2.Init() and to terminate it, zkfp2.Terminate().

To initialize the database, use _dbHandle = zkfp2.DBInit() and to free it, zkfp2.DBFree(_dbHandle).

Also, make sure you are using the last version of the ZK Finger libraries.