Adam.Noyes

To my surprise, there hasnt been much in the ways of developement of Smart Cards. Most of the technology has been proprietary and I havnt been able to find any released examples. One path that I am taking is to use the Winscard.dll with the methods SCardEstablishContext() SCardConnect() ect. I have wrote a class importing the .dll and its methods. I have read through the MSDN documentation of what does what and I am still having issues decyphering the logistics of this library.

For Example:

http://msdn2.microsoft.com/en-us/library/aa925107.aspx

LONG SCardConnect(
 SCARDCONTEXT hContext, 
 LPCTSTR szReader, 
 DWORD dwShareMode, 
 DWORD dwPreferredProtocols, 
 LPSCARDHANDLE phCard, 
 LPDWORD pdwActiveProtocol 
);

Parameters

LONG SCardEstablishContext(
 DWORD dwScope,
 LPCVOID pvReserved1,
 LPCVOID pvReserved2,
 LPSCARDCONTEXT phContext
);
 
dwScope
[in] Scope of the resource manager context. This parameter can be one of the following values.
ValueMeaning
SCARD_SCOPE_USERDatabase operations are performed within the domain of the user.
SCARD_SCOPE_SYSTEMDatabase operations are performed within the domain of the system. The calling application must have appropriate access permissions for any database actions.
pvReserved1
[in] Reserved for future use and must be NULL. This parameter will allow a suitably privileged management application to act on behalf of another user.
pvReserved2
[in] Reserved for future use and must be NULL.
phContext
[out] A handle to the established resource manager context. This handle can now be supplied to other functions attempting to do work within this context.
 This is where my skills deterierate. I cannot for the life of me understand these parameters. I cannot use SCARD_SCOPE_USER although I know the value is 1. SCARD_SCOPE_SYSTEM value is 2.
pvReserved1. Do I use null 
pvReserved2. ""
phContext. This parameter I do not understand at all.
 
Any help would be appriciatated. What I would really like is for anyone who has sample code in being able to establish a connection with a smart card through a reader and is sucessful in transmitting data to the card. 
If you could provide me guidence with this project by supplying a sample for me.
 
Thank you in advance.
Adam Noyes


Re: .NET Base Class Library Using the Winscard.dll and methods

Ilya Tumanov

Moved to .NET BCL as it appears to be most appropriate.

To moderators: Please do not move to Smart Device forums. Smart Cards are NOT smart devices; it's just an API on desktop which developers are trying to use from .NET framework. Please move to other forums as you see fit. Thanks.






Re: .NET Base Class Library Using the Winscard.dll and methods

Adam.Noyes

A forum moderator has moved this thread to this forum community. Please dont lock this thread like my last one....

Hint: Tell me where to post please.





Re: .NET Base Class Library Using the Winscard.dll and methods

Ilya Tumanov

I've moved it to .NET BCL forum.

Note if you're trying to use this API in Smart Device project you're welcome to post to Smart Device forums. In that case please indicate which Windows CE or Windows Mobile smart device you¡¯re using and which toolset is used for development.






Re: .NET Base Class Library Using the Winscard.dll and methods

waiwaipang

For SCardEstablishContext,

dwScope:

SCARD_SCOPE_SYSTEM and SCARD_SCOPE_USER, the difference is some other SCAPI functions (such as SCardIntroduceReader, SCardIntroduceCardType etc)can operate or return the Calais database information in either HKLM or HKCU

pvReserved1 and pvReserved2 must be NULL

phContext returns a handle of the resource manager context, which is used for other SCAPI calls, including SCardConnect.

The following example transmit some data to one type of Axalto card:

DWORD dwRet;

SCARDHANDLE hCard = NULL ;

SCARDCONTEXT hSCCtx = NULL;

BYTE pbSendBuffer[]={0x00,0xCA,0x01,0x06};

DWORD cbSendLength = sizeof(pbSendBuffer);

BYTE pbRecvBuffer [MAX_PATH];

DWORD cbRecvLength = sizeof(pbRecvBuffer);

LPSCARD_IO_REQUEST pioSendPci = ( LPSCARD_IO_REQUEST )SCARD_PCI_T0;

DWORD dwActiveProtocol=0;

dwRet = SCardEstablishContext(

SCARD_SCOPE_SYSTEM,

NULL,

NULL,

&hSCCtx

) ;

if ( SCARD_S_SUCCESS != dwRet )

goto ErrorReturn;

dwRet = SCardConnect(

hSCCtx,

_T(¡°Gemplus USB SmartCard Reader 0¡±),

SCARD_SHARE_SHARED,

SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1,

&hCard,

&dwActiveProtocol);

if ( SCARD_S_SUCCESS != dwRet )

goto ErrorReturn;

dwRet = SCardTransmit(

hCard,

pioSendPci,

pbSendBuffer,

cbSendLength,

NULL,

pbRecvBuffer,

&cbRecvLength);

if ( SCARD_S_SUCCESS != dwRet )

goto ErrorReturn;

SCardDisconnect(

hCard,

SCARD_LEAVE_CARD);

SCardReleaseContext (hScctx);