question

BenedyktKubica-8444 avatar image
0 Votes"
BenedyktKubica-8444 asked XiaopoYang-MSFT edited

Smart Card

How to use SmartCard library (SCardConnect, SCardEstablishContext, etc.) in Win64? They work perfectly well in Win32.

not-supported
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have tested the function in 64-bit and found no problem. The program called C:\Windows\System32\WinSCard. DLL, so It can be used in win64. what problems you have in the process of using?

0 Votes 0 ·

When I compile my code to 64 bit SCardConnectW returns code 6.
When I compile the same code to 32 bit the return code is 0 and of course everything is working perfectly well.

0 Votes 0 ·

I have no problem compiling in 64 bits, can you provide a minimal code sample without any privacy.

0 Votes 0 ·

Connecting to SC

var
FReturnCode : Int64;
FContext: LongInt;
FCard: LongInt;

FATR.Protocol: DWORD;

procedure TNFCWin.Connect(const AReader: string);
begin {Connect}
//Connect to reader using a shared connection
FReturnCode := 0;
FReturnCode := SCardConnectW(FContext,
PWideChar(AReader),
SCARD_SHARE_SHARED,
SCARD_PROTOCOL_T0 or SCARD_PROTOCOL_T1,
FCard,
@FATR.Protocol);

if Success
then begin
GetATR(AReader);
FATR.CheckSCType;
CheckBlankCard;
CheckSCTypeFamily;
GetUID;
end;
end; {Connect}

Calling SCardConnectW on Win32 returns 0 but on Win64 returns 6.

0 Votes 0 ·

An invalid handle was passed to the function, according to error code 6 returned. You can debug it to see if the handle is empty.
May I ask what language your code is using? I suggest you use C++ for testing. This is a sample.


0 Votes 0 ·
BenedyktKubica-8444 avatar image
0 Votes"
BenedyktKubica-8444 answered JunjieZhu-MSFT commented

I'm using Embarcadero RAD Studio (Delphi).

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Have you tried the C++ example and checked to see if there are invalid handles?


0 Votes 0 ·
BenedyktKubica-8444 avatar image
0 Votes"
BenedyktKubica-8444 answered

Currently I don't have C++ compiler so I cannot test it.

I found that in fact the problem is in SCardEstablishContext.

FReturnCode := SCardEstablishContext(SCARD_SCOPE_USER,
nil,
nil,
@FContext);

In Win32 FReturnCode is 0 and the handle (FContext) is valid, i.e. SCardIsValidContext(FContext) returns 0.
In Win64 FReturnCode is still 0 but the handle is also 0, thus invalid.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.