I’m trying to use an API under Delphi. Here’s the API documentation:
OKERR ENTRY SCardCLMifareStdAuthent
(IN SCARDHANDLE ulHandleCard,IN ULONG ulMifareBlockNr,
IN UCHAR ucMifareAuthMode,IN UCHAR ucMifareAccessType,IN UCHAR ucMifareKeyNr,
IN PUCHAR pucMifareKey,IN ULONG ulMifareKeyLen);
Whereas pucMifareKey:
A pointer to the six byte Mifare key.
The code I’ve been trying so far:
function Auth():Integer;
type
TSCardCLMifareStdAuthent = function(SCARDHANDLE: cardinal; ulMifareBlockNr: ULONG;
ucMifareAuthMode, ucMifareAccessType, ucMifareKeyNr: byte; pucMifareKey: puchar;
ulMifareKeyLen: cardinal):LONG;
var
SCardCLMifareStdAuthent: TSCardCLMifareStdAuthent;
hDLL: Integer;
CardHandle: cardinal;
i: integer;
Key: array of UCHAR;
begin
Result:=1;
//CardHandle is defined here
SetLength(Key, 6);
for i := low(key) to high(key) do
Key[i] := $FF;
hDLL := LoadLibrary('scardsyn.dll');
@SCardCLMifareStdAuthent := GetProcAddress(hDLL, 'SCardCLMifareStdAuthent');
if @SCardCLMifareStdAuthent <> nil then
Result:=SCardCLMifareStdAuthent(CardHandle, $00, 96, 0, 0, ^Key, 6);
FreeLibrary(hDLL);
end;
The error I’m getting is:
Incompatible types: ‘Byte’ and ‘Char’ at the line of
`Result:=SCardCL…. ` due ^Key pointer.
Any ideas?
I don’t know the DLL in question, but for a Delphi pre 2009 I would do the following:
The access violation you get probably comes from the C string not being 0-terminated. Using a string and casting it to PChar will make things easier.