i bought nfc acr122u. comes samples delphi 7.
i using delphi xe8 , compiling sample 32 bits/win 8.1.
i did correct changes(i believe) adapt api , sample project functions delphi xe8, replacing pchar pansichar , char ansichar needed.
i using native win 8 drivers, no manufacturer drive.
i can initialize device , device name correctly with:
procedure tfrmdevprog.btninitclick(sender: tobject); var index: integer; begin //establish context retcode := scardestablishcontext(scard_scope_user, nil, nil, @hcontext); if retcode <> scard_s_success begin displayout(getscarderrmsg(retcode),2); exit; end ; //list pc/sc readers installed in system bufferlen := max_buffer_len; retcode := scardlistreadersa(hcontext, nil, @buffer, @bufferlen); if retcode <> scard_s_success begin displayout(getscarderrmsg(retcode),2); exit; end; btninit.enabled := false; btnconnect.enabled := true; loadlisttocontrol(cbreader,@buffer,bufferlen); // acr128 picc , make default reader in combobox index := 0 cbreader.items.count-1 begin cbreader.itemindex := index; if ansipos('acr122u picc', cbreader.text) > 0 exit; end; cbreader.itemindex := 0; end;
the procedure above works well. next, use next code connect device:
procedure tfrmdevprog.btnconnectclick(sender: tobject); begin //connect reader using shared connection retcode := scardconnecta(hcontext, pansichar(cbreader.text), scard_share_shared, scard_protocol_t0 or scard_protocol_t1, @hcard, @dwactprotocol); if retcode <> scard_s_success begin displayout(getscarderrmsg(retcode),2) end else begin displayout('successful connection ' + cbreader.text, 1) end; end;
here, getting error scardconnecta: "the specified reader name not recognized." , retcode var is: -2146435063.
here snippet code of api copied dvd sent device, when bought it:
/////////////////////////////////////////////////////////////////////////////// // imported functions winscard.dll (win32 api) /////////////////////////////////////////////////////////////////////////////// function scardestablishcontext(dwscope :dword; pvreserved1: lpcvoid; pvreserved2: lpcvoid; phcontext :lpscardcontext):long; stdcall; external 'winscard.dll'; function scardreleasecontext(hcontext:scardcontext):long; stdcall; external 'winscard.dll'; function scardlistreadersa(hcontext : scardcontext; mszgroups:lpcstr; szreaders:lpstr; pcchreaders:lpdword):long; stdcall; external 'winscard.dll'; //note : scardconnecta non-unicode characters 1 byte. // unicode characters scardconnectw. special processing // required unicode. careful! function scardconnecta(hcontext : scardcontext; szreaders:lpstr; dwsharemode : dword; dwpreferredprotocols : dword; phcard : lpscardhandle; pdwactiveprotocols:lpdword):long; stdcall; external 'winscard.dll';
i downloaded binary app mannufacturer site test device , works well. need work delphi app.
any help, please.
the problem cast cbreader.text pansichar. fix
retcode := scardconnecta(hcontext, pansichar(ansistring(cbreader.text)), scard_share_shared, scard_protocol_t0 or scard_protocol_t1, @hcard, @dwactprotocol);
Comments
Post a Comment