<div dir="ltr">Based on this your declaration of the API function appears to be incorrect:<br><br><span style="font-size:12.8000001907349px">Documentation:<br></span><span style="font-size:12.8000001907349px"><br><font face="monospace, monospace">int API_PCDRead(HANDLE commHandle,</font></span><div><font face="monospace, monospace"><span style="font-size:12.8000001907349px"> int: DeviceAddress,</span></font><div><font face="monospace, monospace"><span style="font-size:12.8000001907349px"> unsigned char: mode,</span></font><div><font face="monospace, monospace"><span style="font-size:12.8000001907349px"> unsigned </span><span style="font-size:12.8000001907349px">char: blk_add,</span></font><div><span style="font-size:12.8000001907349px"><font face="monospace, monospace"> unsigned char: num_blk,</font></span><div><span style="font-size:12.8000001907349px"><font face="monospace, monospace"> unsigned char: *snr,</font></span><div><span style="font-size:12.8000001907349px"><font face="monospace, monospace"> unsigned char: *buffer);<br></font></span><br>Your declaration:<br><br><font face="monospace, monospace"><span style="font-size:12.8000001907349px">function </span><span style="font-size:12.8000001907349px">API_PCDRead(comHandle: Thandle;</span></font></div><div><font face="monospace, monospace"><span style="font-size:12.8000001907349px"> DeviceAddress: integer; </span></font></div><div><font face="monospace, monospace"><span style="font-size:12.8000001907349px"> mode: </span><span style="font-size:12.8000001907349px">byte;</span></font></div><div><font face="monospace, monospace"><span style="font-size:12.8000001907349px"> add_blk,num_blk:integer;</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px"> snr,buffer:pchar): integer;</span><br></font></div></div></div></div></div></div><div><font face="monospace, monospace"><span style="font-size:12.8000001907349px"><br></span></font></div><div><span style="font-size:12.8000001907349px"><font face="arial, helvetica, sans-serif">Your <b>add_blk</b> and <b>num_blk</b> parameters are declared of type <i>Integer</i> (4 bytes) when the function is expecting parameters of type <i>unsigned char</i> (1 byte). This explains your access violation (the result of the way that memory used for passing parameters is handled when using 'C' calling conventions, if the caller of a function, and the function itself, do not agree on the exact sizes of the parameters being passed).</font></span></div><div><span style="font-size:12.8000001907349px"><font face="arial, helvetica, sans-serif"><br></font></span></div><div><span style="font-size:12.8000001907349px"><font face="arial, helvetica, sans-serif">Change your function declaration to:</font></span></div><div><font face="monospace, monospace"><span style="font-size:12.8000001907349px"><br></span></font></div><div><div><div><font face="monospace, monospace"><b><span style="font-size:12.8000001907349px">function </span><span style="font-size:12.8000001907349px">API_PCDRead(comHandle: THandle;</span></b></font></div><div><font face="monospace, monospace"><b><span style="font-size:12.8000001907349px"> DeviceAddress: integer; </span></b></font></div><div><font face="monospace, monospace"><b><span style="font-size:12.8000001907349px"> mode: </span><span style="font-size:12.8000001907349px">byte;</span></b></font></div><div><font face="monospace, monospace"><b><span style="font-size:12.8000001907349px"> add_blk,num_blk: byte;</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px"> snr,buffer: pchar): integer;</span></b><br></font></div></div></div><div><font face="monospace, monospace"><span style="font-size:12.8000001907349px"><br></span></font></div><div><span style="font-size:12.8000001907349px"><font face="arial, helvetica, sans-serif">I would also double check the type declaration for the <b>Handle</b> parameter, just to be certain that the "HANDLE" type expected by the API function does in fact correspond to what appears to be the Windows API specific <b>THandle</b> type that you have declared it as.</font><br><br>This will almost certainly solve your access violation. Based on the documentation it appears that the way that you are handling the result following the call is correct (though I haven't examined it exhaustively). You will do yourself an enormous favour by simplifying and tidying this up as well as the initialization part.<br></span><span style="font-size:12.8000001907349px"><br>Apart from anything else, it will greatly help someone maintaining the code in the future if the variables used in the calling code correspond to the parameters documented for the API. </span><span style="font-size:12.8000001907349px">e.g. if you are passing a buffer in a parameter called "<b>snr</b>" then name your variable "<b>snr</b>", or <b>snrParam</b>, and only access it that way. Don't use a variable and a pointer that happens to point to that variable (via a side-effect!) or if you absolutely must then at least ensure that the names involved make this usage clear, e.g. </span><b style="font-size:12.8000001907349px">snr</b><span style="font-size:12.8000001907349px"> and <b>ptr</b></span><b style="font-size:12.8000001907349px">snr</b><span style="font-size:12.8000001907349px">.</span></div><div><span style="font-size:12.8000001907349px"><br>Finally, the documentation also says that upon calling the function, the <b>snr</b> buffer is expected to hold an <i>8 byte</i> key value which you are only initialising with 7 bytes (6 x $FF and a $00) so I would double check that this initialization of the <b>snr</b> buffer in your code is correct.<br><br><br>Hope this helps.</span></div><div><span style="font-size:12.8000001907349px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 28 May 2015 at 18:27, Marshland Engineering <span dir="ltr"><<a href="mailto:marshland@marshland.co.nz" target="_blank">marshland@marshland.co.nz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This is running with a USB cable and Windows XP. It installs as a HID device.<br>
<br>
4.2 Mifare Appilication Commands<br>
<br>
4.2.1 int<br>
API_PCDRead(HANDLEcommHandle,int:DeviceAddress,unsignedchar:mode,unsigned<br>
char:blk_add,unsigned char:num_blk,unsigned char:*snr, unsigned char:*buffer);<br>
<br>
Description:<br>
read the appointed length date at the appointed station<br>
Input Parameter Description<br>
<br>
commHandle the serial port handle<br>
DeviceAddress equipment address<br>
mode read mode<br>
( Request Idle + Key A mode=00 , Request Idle + Key B mode= 02,<br>
Request All + Key A mode=01 , Request All + Key B mode=03<br>
the up number is hex)<br>
blk_add read block address<br>
num_blk read block amount<br>
*snr a finger, transfer eight byte secret key<br>
*buffer wait receive the variable of output finger<br>
<br>
Output Parameter<br>
If Command success<br>
*snr 4 byte card number<br>
*buffer the read date (the fact number is num_blk*16)<br>
If Command Failure<br>
buffer[0] System Error/Status Codes(You can consult the 2.2)<br>
<br>
Return value:<br>
0x00 Command OK. ( success)<br>
0x01 Command FAILURE<br>
<br>
<br>
The full manual is here<br>
<a href="http://www.marshland.co.nz/ftp/Misc/DLL.doc" target="_blank">http://www.marshland.co.nz/ftp/Misc/DLL.doc</a><br>
Thanks Wallace.<br>
<br>
_______________________________________________<br>
NZ Borland Developers Group - Delphi mailing list<br>
Post: <a href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz">delphi-request@listserver.123.net.nz</a> with Subject: unsubscribe</blockquote></div><br></div>