problem using sdk
|
|
Thread rating:  |
Mark - 26 May 2008 18:11 GMT I have an sdk that I need to use (secbank.dll to access the Biometrika Fx3000 fingerprint scanner)
I have had to covert from the 'C' header file sample into a VB DLL function, but I've obviously go it wrong because Access keeps on crashing.
I think the problem is with 'fileName' parameter - any obvious mistake? (the maximum file length is 16 characters)
C ORIGINAL:
SECBANKDLL_API UINT SB_CALLMODE SecBank_Create (Device Disp, char *fileName, DWORD *IDSecBank, BYTE *Pin, DWORD lenPin); //Creates a new SecBank on the scanner RAM
VB:
Public Declare Function SecBank_Create Lib "SecBank.dll" (ByVal Device As Long, ByVal afileName As Byte, ByVal aIDSecBank As Long, ByRef aPin As Byte, ByVal lenPin As Long) As Integer 'Creates a new SecBank on the scanner RAM
Code: Dim RetV As Long Dim SB_ID As Long Dim PinArr() As Byte Dim FileName() As Byte Const IDDevFlashScanner As Long = 1 Const Pin As String = "12345678901234567890123456789012" Const FName As String = "FileName00123456" PinArr() = StrConv(Pin, vbFromUnicode) FileName() = StrConv(FName, vbFromUnicode) RetV = SecBank_Create(IDDevFlashScanner, FileName(0), SB_ID, PinArr(0), 32) If RetV <> 0 Then Call FPErrMsg(RetV)
 Signature Mark Desser
Thorsten Albers - 26 May 2008 20:20 GMT Mark <someknowhow@googlemail.com> schrieb im Beitrag <$j8KOOF98uOIFA+L@thedessers.com>...
> C ORIGINAL: > [quoted text clipped - 8 lines] > As Byte, ByVal lenPin As Long) As Integer 'Creates a new > SecBank on the scanner RAM - I can't judge the correctness of 'Disp' since you didn't provide the type definition of 'Device'; but 'ByVal Disp As Long' is very likely. - In 'fileName' a pointer to at least one character of 1 byte memory usage is expected, but presumably it has to be a pointer to a NULL terminated character array, i.e. an ANSI string. If so, you may use 'ByVal fileName As String' in VB since with this VB internally converts the given Unicode string to a NULL terminated ANSI string and then passes a pointer to the latter to the external library. - In IDSecBank' a pointer to a DWORD value is expected not a DWORD value. Use 'ByRef IDSecBank As Long'. - Altough the data type of 'Pin' is given as 'BYTE', in VB you may use 'ByVal Pin As String' here as well since, as stated above, the string will be converted internally to an ANSI string where 1 character uses 1 byte of memory. - The C data type 'UINT' uses 4 bytes of memory (at least on 32 bit machines), the VB data type 2 bytes; unfortunately there is no unsigned 4 byte integer data type in VB, the most appropriate one is 'Long' (4 bytes of memory). In case you will have to add code which handles the returned signed value as an unsigned value although this is not very likely since return values usually only are = 0 or <> 0 (so the sign may be ignored).
->
Public Declare Function SecBank_Create _ Lib "SecBank.dll" _ ( _ ByVal Device As Long, _ ByVal fileName As String, _ ByRef IDSecBank As Long, _ ByVal Pin As String, _ ByVal lenPin As Long _ ) As Long
Dim RetV As Long Dim SB_ID As Long Const IDDevFlashScanner As Long = 1 Const Pin As String = "12345678901234567890123456789012" Const FName As String = "FileName00123456"
RetV = SecBank_Create(IDDevFlashScanner, _ FName, _ SB_ID, Pin, Len(Pin))
 Signature ---------------------------------------------------------------------- Thorsten Albers albers(a)uni-freiburg.de ----------------------------------------------------------------------
Mark - 26 May 2008 22:13 GMT Thorsten Albers <albersRE@MOVEuni-freiburg.de> wrote on Mon, 26 May 2008 12:20:14
Thanks Thorsten for your reply. I have tried you suggestion but the function still returns an error ('input parameter error' - but doesn't perform a GP crash)
>- I can't judge the correctness of 'Disp' since you didn't provide the >type definition of 'Device'; but 'ByVal Disp As Long' is very likely. Device was an enum type that is a long data type.
> - In 'fileName' a pointer to at least one character of 1 byte memory >usage is expected, but presumably it has to be a pointer to a NULL >terminated character array, i.e. an ANSI string. If so, you may use >'ByVal fileName As String' in VB since with this VB internally converts >the given Unicode string to a NULL terminated ANSI string and then >passes a pointer to the latter to the external library.
>Altough the data type of 'Pin' is given as 'BYTE', in VB you may use >'ByVal Pin As String' here as well since, as stated above, the string >will be converted internally to an ANSI string where 1 character uses 1 >byte of memory. What confuses me is that for Pin, there is a second parameter to pass the length (lenPin). Doesn't this indicate that it is an array, thus requiring the length to be declared. Filename, however does not have an accompanying variable to pass its length to the dll. Why should there be this discrepancy for two seemingly similar variables that carry a text string of variable length? For this reason I originally changed FileName to byVal String, but the function returns an 'input parameter error'. (This is better than a GP crash, but is still incorrect.)
> - The C data type 'UINT' uses 4 bytes of memory (at least on 32 bit >machines), the VB data type 2 bytes; unfortunately there is no unsigned [quoted text clipped - 3 lines] >likely since return values usually only are = 0 or <> 0 (so the sign >may be ignored). I don't think there is a difference in this instance since the function returns a 2 byte error code.
To summarise; I am troubled by the inconstancy between Pin requiring a parameter to pass its length, whilst FileName doesn't. This would seem to indicate that it is a byVal String, but this still fails.
You seem to be familiar with C (which I am not.) If you feel that this problem is uncharacteristic, I will go back to the technical support - I just want to be sure that I haven't missed anything in C. Might this have to do with the dll not having been compiled correctly for use with VB?
 Signature Mark Desser
Thorsten Albers - 26 May 2008 23:09 GMT Mark <someknowhow@googlemail.com> schrieb im Beitrag <f84yJDJtfyOIFAbZ@thedessers.com>...
> What confuses me is that for Pin, there is a second parameter to pass > the length (lenPin). Doesn't this indicate that it is an array, thus [quoted text clipped - 4 lines] > FileName to byVal String, but the function returns an 'input parameter > error'. (This is better than a GP crash, but is still incorrect.) You seem to misundertand this error code! It doesn't say that you passed a parameter the wrong way (from VB) but that >the value of a parameter is incorrect<. It is possible to change the declaration in VB but that wouldn't change the data which is sent to the DLL. Here we can't help you with the parameter values since we don't know what they should be - you should refer to the documentation on the function.
 Signature ---------------------------------------------------------------------- Thorsten Albers albers(a)uni-freiburg.de ----------------------------------------------------------------------
expvb - 26 May 2008 23:46 GMT > Thorsten Albers <albersRE@MOVEuni-freiburg.de> wrote on Mon, 26 May 2008 > 12:20:14 > > Thanks Thorsten for your reply. I have tried you suggestion but the > function still returns an error ('input parameter error' - but doesn't > perform a GP crash) 'input parameter error' sometimes means that there is a structure that has a variable that must be filled with the number of bytes in the structure. It's usually the first member in the structure.
expvb - 27 May 2008 00:01 GMT >> Thorsten Albers <albersRE@MOVEuni-freiburg.de> wrote on Mon, 26 May 2008 >> 12:20:14 [quoted text clipped - 6 lines] > a variable that must be filled with the number of bytes in the structure. > It's usually the first member in the structure. If you used "Error Lookup" program in VS6 Tools menu, or Win32 API error codes to see the meaning of the returned value, then it's incorrect. Each vendor has their own explanation for error codes, so my explanation in the previous reply could be incorrect.
Jim Mack - 26 May 2008 23:17 GMT > I have an sdk that I need to use (secbank.dll to access the > Biometrika Fx3000 fingerprint scanner) [quoted text clipped - 5 lines] > I think the problem is with 'fileName' parameter - any obvious > mistake? (the maximum file length is 16 characters) Thorsten's comments are all valid (no surprise), but there are a couple of areas that are open to variations.
First, the way that *filename and *Pin are different is that filename is expected to be a null-terminated array of char (presumably bytes, but not necessarily), while Pin is explicitly declared as BYTE and is not expected to be null-terminated (so a length is needed).
Why that was done is anyone's guess. But because it was done, because the coder felt it necessary to distinguish BYTE from char, I'd check to be sure that char is defined on the C side as being equivalent to BYTE. It's barely possible that the intent is to use Unicode.
You _could_ use ByRef Pin As Byte and pass Pin(0), but there's probably no reason not to go with the suggested ByVal Pin As String.
> C ORIGINAL: > > SECBANKDLL_API UINT SB_CALLMODE SecBank_Create Here's a perfect example of how translating from C can be a minefield.
Without knowing what SECBANKDLL_API and SB_CALLMODE are, especially the latter, you can't be sure that the DLL uses stdcall, which is vital for correct operation with VB. Find the definitions for those and post them, for completeness.
-- Jim
mark - 27 May 2008 00:10 GMT Jim Mack <jmack@mdxi.nospam.com> wrote on Mon, 26 May 2008 18:17:46
>Here's a perfect example of how translating from C can be a minefield. > >Without knowing what SECBANKDLL_API and SB_CALLMODE are, >especially the latter, you can't be sure that the DLL uses stdcall, which is >vital for correct operation with VB. Find the definitions for those and post >them, for completeness. Here is the text from the header file:
//----------------------------------------------------------------------------- ----------------------- // // Company: BiometriKa s.r.l. - www.biometrika.it // E-mail: info@biometrika.it // // Copyright(C) 2006, Biometrika s.r.l. // All rights reserved. // // //----------------------------------------------------------------------------- -----------------------
#ifndef __SECBANK #define __SECBANK
// The following ifdef block is the standard way of creating macros which make exporting // from a DLL simpler. All files within this DLL are compiled with the SECBANKDLL_EXPORTS // symbol defined on the command line. this symbol should not be defined on any project // that uses this DLL. This way any other project whose source files include this file see // SECBANKDLL_API functions as being imported from a DLL, whereas this DLL sees symbols // defined with this macro as being exported.
#ifndef FXDLL_LINUX // win32 #ifdef SECBANKDLL_EXPORTS #define SECBANKDLL_API extern "C" __declspec(dllexport) #else #define SECBANKDLL_API #endif
#define SB_CALLMODE __stdcall
#else //Linux #define SECBANKDLL_API #define SB_CALLMODE #endif
#ifdef __cplusplus extern "C" { #endif
//It's used to indicate the device where the SecBank is to be found typedef enum { FlashScanner = 1, SmartCard = 2 } Device;
#define MAX_PIN_LEN 32
#define NULL_ID_SECBANK 0 #define PIN_PROTECTION 1 #define MODEL_PROTECTION 2
//----------------------------------- Types ----------------------------------- ---------- typedef unsigned char BYTE; typedef unsigned short int WORD; typedef unsigned long DWORD; typedef unsigned int UINT; typedef int BOOL;
//----------------------------------------------------------------------------- ---------
//--------------------------------- Functions --------------------------------- --------- SECBANKDLL_API UINT SB_CALLMODE SecBank_GetLastError();
SECBANKDLL_API UINT SB_CALLMODE SecBank_Init (); //Library initialization SECBANKDLL_API UINT SB_CALLMODE SecBank_End (); //Library deallocation SECBANKDLL_API UINT SB_CALLMODE SecBank_SetPort (DWORD port); //Sets a scanner port (the default is 200, for standard Fx3000)
SECBANKDLL_API UINT SB_CALLMODE SecBank_GetFirstPublic (DWORD IDSecBank, DWORD IDAppl, WORD *IDEntry, BYTE *Public, DWORD *lenPublic); //Returns the first public Entry related to the given application ID SECBANKDLL_API UINT SB_CALLMODE SecBank_GetNextPublic (DWORD IDSecBank, DWORD IDAppl, WORD *IDEntry, BYTE *Public, DWORD *lenPublic); //Returns the next public Entry related to the given application ID SECBANKDLL_API UINT SB_CALLMODE SecBank_GetPrivate (DWORD IDSecBank, WORD IDEntry, BYTE *Private, DWORD *lenPrivate); //Returns the private data related to the given Entry SECBANKDLL_API UINT SB_CALLMODE SecBank_NewEntry (DWORD IDSecBank, DWORD IDAppl, WORD *IDEntry, BYTE *Public, DWORD lenPublic, BYTE *Private, DWORD lenPrivate); //Insert a new Entry in the SecBank currentrly on RAM and returns the ID of the new Entry SECBANKDLL_API UINT SB_CALLMODE SecBank_ModifyEntry (DWORD IDSecBank, WORD IDEntry, BYTE *Public, DWORD lenPublic, BYTE *Private, DWORD lenPrivate); //Modifies public and private data of the given Entry SECBANKDLL_API UINT SB_CALLMODE SecBank_DeleteEntry (DWORD IDSecBank, WORD IDEntry); //Deletes the specified Entry from the RAM SECBANKDLL_API UINT SB_CALLMODE SecBank_DeleteAllEntry (DWORD IDSecBank, DWORD IDAppl); //Deletes all the Entries of a given application from the RAM SECBANKDLL_API UINT SB_CALLMODE SecBank_Save (DWORD IDSecBank); //Saves the SecBank currentrly on the RAM of the device SECBANKDLL_API UINT SB_CALLMODE SecBank_Open (Device Disp, char *fileName, DWORD *IDSecBank, BYTE *Pin, DWORD lenPin); //Loads in RAM the specified SecBank and returns the related ID SECBANKDLL_API UINT SB_CALLMODE SecBank_Create (Device Disp, char *fileName, DWORD *IDSecBank, BYTE *Pin, DWORD lenPin); //Creates a new SecBank on the scanner RAM SECBANKDLL_API UINT SB_CALLMODE SecBank_Clone (Device Disp, char *fileName, DWORD IDSecBank, BYTE *Pin, DWORD lenPin); //Clonate the SecBank currentrly in RAM saving it on the selected device SECBANKDLL_API UINT SB_CALLMODE SecBank_RAMDelete (BOOL ForceDelete); //Erases the opened SecBank from the scanner RAM SECBANKDLL_API UINT SB_CALLMODE SecBank_Delete (Device Disp, char *fileName); //Erases the specified SecBank from the device SECBANKDLL_API UINT SB_CALLMODE SecBank_StartEnrollModel(DWORD IDSecBank, BYTE *Model, DWORD lenModel); //Acquires a new model for the current SecBank SECBANKDLL_API UINT SB_CALLMODE SecBank_EndEnrollModel(DWORD IDSecBank); //Stores the model acquired with StartEnrollModel on the current SecBank SECBANKDLL_API UINT SB_CALLMODE SecBank_TestModel(DWORD IDSecBank, BYTE *Model, DWORD lenModel, float *score); //Returns a matching score between the model on the SecBank and the given (or acquired) model SECBANKDLL_API UINT SB_CALLMODE SecBank_SetThreshold(DWORD IDSecBank, float threshold); //Sets the matching threshold SECBANKDLL_API UINT SB_CALLMODE SecBank_GetThreshold(DWORD IDSecBank, float *threshold); //Gets the current matching threshold SECBANKDLL_API UINT SB_CALLMODE SecBank_DeleteModel (DWORD IDSecBank); //Deletes the model from the current SecBank SECBANKDLL_API UINT SB_CALLMODE SecBank_GetModel (DWORD IDSecBank, BYTE *Model, DWORD *lenModel); //Returns the model stored on the current SecBank SECBANKDLL_API UINT SB_CALLMODE SecBank_GetFileList (Device Disp, BYTE *fileList, DWORD *lenList); //Gets a list of Secrets Banks on the device SECBANKDLL_API UINT SB_CALLMODE SecBank_SetPin (DWORD IDSecBank, BYTE *OldPin, DWORD lenOldPin, BYTE *NewPin, DWORD lenNewPin); //Update the current SecBank PIN SECBANKDLL_API UINT SB_CALLMODE SecBank_SetTimeout (DWORD IDSecBank, DWORD Timeout); //Sets the current SecBank timeout SECBANKDLL_API UINT SB_CALLMODE SecBank_GetTimeout (DWORD IDSecBank, DWORD *Timeout); //Gets the current SecBank timeout SECBANKDLL_API UINT SB_CALLMODE SecBank_Lock (DWORD IDSecBank); //Locks the currrent SecBank: a new PIN verification would be needed SECBANKDLL_API UINT SB_CALLMODE SecBank_Unlock (DWORD IDSecBank, BYTE *Pin, DWORD lenPin); //Unlocks the current SecBank if it was previously locked or the timeout expired SECBANKDLL_API UINT SB_CALLMODE SecBank_GetIDSecBank (DWORD *IDSecBank, BYTE *Pin, DWORD lenPin); //Return the ID of the current SecBank on RAM SECBANKDLL_API UINT SB_CALLMODE SecBank_GetInfoCurrentSecBank (Device *Disp, char *fileName, DWORD *lenFileName, BYTE *security); //Returns info on the curretn SecBank: device, filename and security attributes
SECBANKDLL_API UINT SB_CALLMODE SecBank_DetectCard (); //Check the presence of a Smart Card in the reader SECBANKDLL_API UINT SB_CALLMODE SecBank_FormatCard (BYTE mode, BYTE auth_mode, BYTE enc_mode, BYTE extraAuth[32]); //Formats the SmartCard in the reader SECBANKDLL_API UINT SB_CALLMODE SecBank_FormatCardDlg(BYTE cardID[10]); //Formats the SmartCard. Displays an user interface SECBANKDLL_API UINT SB_CALLMODE SecBank_GetCardInfo (BYTE extraAuth[32], int *status, BYTE *cardType, BYTE cardID[10], BYTE *idLen, WORD *freeSize, BYTE *app, BYTE *auth_mode, BYTE *enc_mode, WORD *FSVersion, BYTE *numEntry, BYTE *templateAval); //----------------------------------------------------------------------------- ---------
//-------------------------------- Application ID ----------------------------- --------- #define IDAppSecBank 1 #define IDAppLogon 2 #define IDAppReserved3 3 #define IDAppReserved4 4 #define IDAppReserved5 5 #define IDAppReservedLast 100 //Applications ID > 100 are available for user applications
//----------------------------------- Errors ---------------------------------- ---------
#define errSBSuccess 0 #define errSBNoCard 1 #define errSBNoSecBank 2 #define errSBNoFile 3 #define errSBNoDevice 4 #define errSBNoCheckUser 5 #define errSBNoModel 6 #define errSBModifiedSB 7 #define errSBAccessDenied 8 #define errSBSecBankOnSC 9 #define errSBNoFormattedCard 10 #define errSBInputParameter 11 #define errSBOutputParameter 12 #define errSBNoMemoryLeft 13 #define errSBDeviceConnection 14 #define errSBFingerprintAcquisition 15 #define errSBTimeOut 16 #define errSBNoPin 17 #define errSBNoEntry 18 #define errSBCrypto 19 #define errSBSecBankAlreadyExist 20 #define errSBModelNotEnrolled 21 #define errSBModelWrong 22 #define errSBOperationCancelled 23 #define errSBCardFull 24 #define errSBWrongCard 25
#define errSBUnknown 40
// Blocking errors #define errSBInternalError 101 #define errSBUnableToSave 102 #define errSBUnableToLoad 103
#define errSBMatchErrorBase 150 #define errSBAGIStep 300 #define errSBEGIStep 301
//Base error for the fingerprint acquisition routine #define errSBFingerPrintAcquisitionPlus 1000
#ifdef __cplusplus } #endif
#endif
 Signature Mark Desser
Jim Mack - 27 May 2008 00:39 GMT > Jim Mack <jmack@mdxi.nospam.com> wrote on Mon, 26 May 2008 18:17:46 > [quoted text clipped - 6 lines] >> definitions for those and post them, for completeness. > Here is the text from the header file: Aside from that line-wrapped mess of prototypes, it looks OK.
From the comments, SECBANKDLL_EXPORTS will be defined on the compiler command line, which makes the call equivalent to:
extern "C" __declspec(dllexport) UINT __stdcall SecBank_Create...
Which ought to be fine for VB.
-- Jim
//-------------------------------------------------------------------- ---------
> ----------------------- > // [quoted text clipped - 5 lines] > // > // //-------------------------------------------------------------------- ---------
> ----------------------- > [quoted text clipped - 54 lines] > typedef unsigned int UINT; > typedef int BOOL; //-------------------------------------------------------------------- ---------
> --------- > [quoted text clipped - 92 lines] > BYTE *auth_mode, BYTE *enc_mode, WORD *FSVersion, BYTE *numEntry, > BYTE *templateAval); //-------------------------------------------------------------------- ---------
> --------- > [quoted text clipped - 63 lines] > > #endif expvb - 27 May 2008 01:51 GMT > Const Pin As String = "12345678901234567890123456789012" > Const FName As String = "FileName00123456" Try making these smaller. Sometimes the maximum means including the null terminating character, so try one less character to see if it works.
mark - 27 May 2008 09:50 GMT expvb <nobody@cox.net> wrote on Mon, 26 May 2008 20:51:25
>Try making these smaller. Sometimes the maximum means including the >null terminating character, so try one less character to see if it >works. This size is as per the guidelines of the developer. So if there is a null, it will be in addition to this string.
 Signature Mark Desser
Thorsten Albers - 27 May 2008 09:03 GMT Mark <someknowhow@googlemail.com> schrieb im Beitrag <$j8KOOF98uOIFA+L@thedessers.com>...
> Public Declare Function SecBank_Create _ > Lib "SecBank.dll" _ [quoted text clipped - 16 lines] > SB_ID, > Pin, Len(Pin)) Just one more guess: This function creates a >new< 'SecBank' and returns the ID of the newly created 'SecBank' in parameter 'IDSecBank' - that's the reason why this parameter has to be a reference. It is not unlikely that SecBank_Create() expects 'IDSecBank' to be 0 (i.e. 'undefined', 'no valid ID') on input.
 Signature ---------------------------------------------------------------------- Thorsten Albers albers(a)uni-freiburg.de ----------------------------------------------------------------------
mark - 27 May 2008 09:51 GMT Thorsten Albers <albersRE@MOVEuni-freiburg.de> wrote on Tue, 27 May 2008 01:03:14
>Just one more guess: This function creates a >new< 'SecBank' and >returns the ID of the newly created 'SecBank' in parameter 'IDSecBank' >- that's the reason why this parameter has to be a reference. It is not >unlikely that SecBank_Create() expects 'IDSecBank' to be 0 (i.e. >'undefined', 'no valid ID') on input. Variables with the long data type are set to this by default in VB.
I have now contacted the developers and they say that it is a new product in late beta and that they will improve this dll for VB use. It seems that a 'C' library must be conform to certain guidelines to be usable by VB.
I will now wait for their update and hope for better results!
I have been recommended Win32 API Programming with Visual Basic by Steven Roman, and hope to become more knowledgeable about this field.
Thanks for your help
 Signature Mark Desser
Thorsten Albers - 27 May 2008 22:48 GMT mark <someknowhow@googlemail.com> schrieb im Beitrag <3j3I+kMQu8OIFAfR@thedessers.com>...
> Variables with the long data type are set to this by default in VB. Sorry, I've mixed this one up with 'IDDevFlashScanner' which is set to 1 in your code.
> It > seems that a 'C' library must be conform to certain guidelines to be > usable by VB. I don't know of any guidelines except the 'standard calling convention' and the guidelines which are valid for any DLL no matter in which language it is written.
 Signature ---------------------------------------------------------------------- Thorsten Albers albers(a)uni-freiburg.de ----------------------------------------------------------------------
|
|
|