nimanga Posted November 1, 2010 Posted November 1, 2010 (edited) Hi there, first of all, excuse me if I have bad English but I'm not used to write in English (but google will help me, je). Well, I'm trying to call functions in the AET60.dll, which contains the API for AET60 BioCARDKey (finger print and smart card reader) with c#; actually, I have succesfully called almost every function, except for those that manipulate the finger print template: capture, match, enroll. I'm sure it's a problem of parameters types, but the problem is that I can't undestand the type of the template paramter, the dll function capture for example, expects a byte pointer (byte*) to save the template, I've tryed with ref, and unsafe code (for using pointers) and it works fine if called from a console app directly (and the dll import in the same class), but the value pointed is simply a byte (0-255), and there I get lost (256 codes are not enough to identify more than 6 biliion people, so I supose that that byte* is actually something similar to c strings: char*, but I don't know how to use that in c#). Another problem is that if this dll function is encapsulated in a method, an AccesViolationException is thrown when trying to use the template data. Here is some code: public class NativeMethods { private static const Int32 DEFAULT_TIMEOUT = 10000; [DllImport("AET60.dll")] private static extern UInt32 AET60_Open(); [DllImport("AET60.dll")] private static extern UInt32 AET60_Close(); [DllImport("AET60.dll")] private static extern Int32 AET60_GetNumDevices(); [DllImport("AET60.dll")] private static extern UInt32 AET60_GetDeviceName(Int32 index, StringBuilder name, ref int nameLength); [DllImport("AET60.dll")] private static extern UInt32 AET60_GetMessage(int number, StringBuilder message); [DllImport("AET60.dll")] private static extern UInt32 AET60_GetLastStatus(); [DllImport("AET60.dll")] private static extern UInt32 AET60_GetStatus(UInt32 status, StringBuilder message); [DllImport("AET60.dll")] private static extern UInt32 AET60_LockReader(Int32 index); [DllImport("AET60.dll")] private static extern UInt32 AET60_UnlockReader(); [DllImport("AET60.dll")] private static extern UInt32 AET60_Capture(ref byte template, ref Int32 templateLength, UInt32 timeOut); public static void capture(Template template) { Byte templateData = template.Data; Int32 templateLength = template.Length; Int32 numberOfDevices; UInt32 errorCode = NativeMethods.AET60_Open(); //for now Im doing nothing with errorCode numberOfDevices = NativeMethods.AET60_GetNumDevices(); errorCode = NativeMethods.AET60_LockReader(numberOfDevices - 1); errorCode = NativeMethods.AET60_Capture(ref templateData, ref templateLength, DEFAULT_TIMEOUT); errorCode = NativeMethods.AET60_UnlockReader(); template.Data = templateData; //here is thrown the exception template.Length = templateLength; //here is thrown the exception errorCode = NativeMethods.AET60_Close(); } } In this code, the AccesViolationExeption is thrown. Every other dll functions listed work fine except for AET60_Capture. Thanks for the help! Edited November 1, 2010 by nimanga Quote
Recommended Posts