Full Version: Acccess And Card Readers
UtterAccess Discussion Forums > Microsoft® Access > Access Q and A
Tiesto_X
Hi,

I never worked with Card Readers. Now, customer wants program to track employers when they check in and check out.

I dont understand how Access read data from Card. Totally confused!

Any tip, where to start?

This is the Card Reader that they have:

THE CARD READER LINK
jleach
Hi,

It's been a long time since I looked at this, and even then I didn't actually use it but just got a glance, but here's how I recall that they work, in general:

The card reader comes with hardware (to read), and it's own softare which takes the information from the card reader and converts it to some more or less standard information readable by application software (this may be in many formats, but it should be in some format that can be universally handled).

Access (or rather, VBA, or whatever other language is being used to write the logic) interacts with the Card Reader's API (Application Programming Interface). This may be very similar to using an ActiveX object, or perhaps more along the lines of programming external DLL functions as we would with the Win32 API. In either case, the key is that the software receives information from the hardware and provides us with some sort of interface that allows us to interact with that information (likely as well as some rudimentary Events for triggering when the information becomes available, etc).

This is my basic understanding of how it works, though again I'll offer a disclaimer that I've never actually used such devices, nor programmed any.

Hopefully that gives some basic direction at least. You may find more readily available but similar concept information by searching for Bar Code Scanner integration with VBA (or other languages... if you can psuedo-read code it's helpful in getting the basic "gist" of how some things will work)
jleach
Takng a look at the link, then going to the product sheet (http://www.gemalto.com/products/pc_link_readers/) and clikcing the "Technical Specifications" tab, scroll down and you will see the "API" category which provides the following information:

Microsoft PC/SC environment with associated drivers
CT-API
Synchronous Card API for support of memory cards

The first of that list sounds like it'd be the ideal place to start some research for using VBA. Smart Cards (MSDN) (this looks awfully dated... back to Win 98/95 even, with no mention of OS's past XP... although Win32 API is Win32API and should still be supported as such) Particularly you'll want to pay attention to the Interoperability section and the Software Development section.

Good luck! There's some work there...

Cheers,
Tiesto_X
Hi sir,

that is good post for the beginning.

I will keep in mind your words and hopefully that Smart Cards article has something useful.

Big thanks for your time!
Tiesto_X
Hi,

I found, hope so, good article.

Since the code is too complex for me I'm not able to implement it into Access, i get compile error.

Any help?

QUOTE
The OP is some guy named Ryan Olbe

Using the winscard.dll PC/SC API in Visual Basic 6

Here's some example code I wrote in July of 2008 that shows how a Visual Basic program can interact with a smart card reader using the winscard.dll PC/SC API. Most of the functions contained in winscard.dll I was able to get working except SCardTransmit which would always return ERROR_GEN_FAILURE (0x1F) or SCARD_E_COMM_DATA_LOST (0x8010002F) for some reason and I was never able to figure out why. If there's anyone out there who's interested in writing a VB implementation of the PC/SC API this would probably be a good place to start.


CODE
'**************************************************************************
' winscard.dll Visual Basic Function Prototypes
'**************************************************************************
'SCardAccessStartedEvent
'http://msdn.microsoft.com/en-us/library/aa379466(VS.85).aspx
'HANDLE STDCALL SCardAccessStartedEvent(VOID)
Public Declare Function SCardAccessStartedEvent Lib "winscard.dll" () As Long

'SCardAddReaderToGroup
'http://msdn.microsoft.com/en-us/library/aa379468(VS.85).aspx
'LONG STDCALL SCardAddReaderToGroupA(SCARDCONTEXT(in), LPCSTR(in), LPCSTR(in))
Public Declare Function SCardAddReaderToGroup Lib "winscard.dll" Alias "SCardAddReaderToGroupA" ( _
    ByVal hContext As Long, _
    ByVal szReaderName As String, _
    ByVal szGroupName As String _
    ) As Long

'SCardBeginTransaction
'http://msdn.microsoft.com/en-us/library/aa379469(VS.85).aspx
'LONG STDCALL SCardBeginTransaction(SCARDHANDLE(in))
Public Declare Function SCardBeginTransaction Lib "winscard.dll" ( _
    ByVal hCard As Long _
    ) As Long

'SCardCancel
'http://msdn.microsoft.com/en-us/library/aa379470(VS.85).aspx
'LONG STDCALL SCardCancel(SCARDCONTEXT(in))
Public Declare Function SCardCancel Lib "winscard.dll" ( _
    ByVal hContext As Long _
    ) As Long

'SCardConnect
'http://msdn.microsoft.com/en-us/library/aa379473(VS.85).aspx
'LONG STDCALL SCardConnectA(SCARDCONTEXT(in), LPCSTR(in), DWORD(in), DWORD(in),
' LPSCARDHANDLE(out), LPDWORD(out))
Public Declare Function SCardConnect Lib "winscard.dll" Alias "SCardConnectA" ( _
    ByVal hContext As Long, _
    ByVal szReader As String, _
    ByVal dwShareMode As Long, _
    ByVal dwPreferredProtocols As Long, _
    ByRef phCard As Long, _
    ByRef pdwActiveProtocol As Long _
    ) As Long

'SCardControl
'http://msdn.microsoft.com/en-us/library/aa379474(VS.85).aspx
'LONG STDCALL SCardControl(SCARDHANDLE(in), DWORD(in), LPCVOID(in), DWORD(in),
' LPVOID(out), DWORD(in), LPDWORD(out))
Public Declare Function SCardControl Lib "winscard.dll" ( _
    ByVal hCard As Long, _
    ByVal dwControlCode As Long, _
    ByRef lpInBuffer As Long, _
    ByVal nInBufferSize As Long, _
    ByRef lpOutBuffer As Long, _
    ByVal nOutBufferSize As Long, _
    ByRef lpBytesReturned As Long _
    ) As Long

'SCardDisconnect
'http://msdn.microsoft.com/en-us/library/aa379475(VS.85).aspx
'LONG STDCALL SCardDisconnect(SCARDHANDLE(in), DWORD(in))
Public Declare Function SCardDisconnect Lib "winscard.dll" ( _
    ByVal hCard As Long, _
    ByVal dwDisposition As Long _
    ) As Long

'SCardEndTransaction
'http://msdn.microsoft.com/en-us/library/aa379477(VS.85).aspx
'LONG STDCALL SCardEndTransaction(SCARDHANDLE(in), DWORD(in))
Public Declare Function SCardEndTransaction Lib "winscard.dll" ( _
    ByVal hCard As Long, _
    ByVal dwDisposition As Long _
    ) As Long

'SCardEstablishContext
'http://msdn.microsoft.com/en-us/library/aa379479(VS.85).aspx
'LONG STDCALL SCardEstablishContext(DWORD(in), LPCVOID(in), LPCVOID(in),
' LPSCARDCONTEXT(out))
Public Declare Function SCardEstablishContext Lib "winscard.dll" ( _
    ByVal dwScope As Long, _
    ByVal pvReserved1 As Long, _
    ByVal pvReserved2 As Long, _
    ByRef phContext As Long _
    ) As Long

'SCardForgetCardType
'http://msdn.microsoft.com/en-us/library/aa379482(VS.85).aspx
'LONG STDCALL SCardForgetCardTypeA(SCARDCONTEXT(in), LPCSTR(in))
Public Declare Function SCardForgetCardType Lib "winscard.dll" Alias "SCardForgetCardTypeA" ( _
    ByVal hContext As Long, _
    ByVal szCardName As String _
    ) As Long

'SCardForgetReader
'http://msdn.microsoft.com/en-us/library/aa379484(VS.85).aspx
'LONG STDCALL SCardForgetReaderA(SCARDCONTEXT(in), LPCSTR(in))
Public Declare Function SCardForgetReader Lib "winscard.dll" Alias "SCardForgetReaderA" ( _
    ByVal hContext As Long, _
    ByVal szReaderName As String _
    ) As Long

'SCardForgetReaderGroup
'http://msdn.microsoft.com/en-us/library/aa379486(VS.85).aspx
'LONG STDCALL SCardForgetReaderGroupA(SCARDCONTEXT(in), LPCSTR(in))
Public Declare Function SCardForgetReaderGroup Lib "winscard.dll" Alias "SCardForgetReaderGroupA" ( _
    ByVal hContext As Long, _
    ByVal szGroupName As String _
    ) As Long

'SCardFreeMemory
'http://msdn.microsoft.com/en-us/library/aa379488(VS.85).aspx
'LONG STDCALL SCardFreeMemory(SCARDCONTEXT(in), LPCVOID(in))
Public Declare Function SCardFreeMemory Lib "winscard.dll" ( _
    ByVal hContext As Long, _
    ByVal pvMem As Long _
    ) As Long

'SCardGetAttrib
'http://msdn.microsoft.com/en-us/library/aa379559(VS.85).aspx
'LONG STDCALL SCardGetAttrib(SCARDHANDLE(in), DWORD(in), LPBYTE(out), LPDWORD(inout))
Public Declare Function SCardGetAttrib Lib "winscard.dll" ( _
    ByVal hCard As Long, _
    ByVal dwAttrId As Long, _
    ByRef pbAttr As ByteArray, _
    ByRef pcbAttrLen As Long _
    ) As Long

'SCardGetCardTypeProviderName
'http://msdn.microsoft.com/en-us/library/aa379655(VS.85).aspx
'LONG STDCALL SCardGetCardTypeProviderNameA(SCARDCONTEXT(in), LPCSTR(in), DWORD(in),
' LPSTR(out), LPDWORD(inout))
Public Declare Function SCardGetCardTypeProviderName Lib "winscard.dll" Alias "SCardGetCardTypeProviderNameA" ( _
    ByVal hContext As Long, _
    ByVal szCardName As String, _
    ByVal dwProviderId As Long, _
    ByVal szProvider As String, _
    ByRef pcchProvider As Long _
    ) As Long

'SCardGetProviderId
'http://msdn.microsoft.com/en-us/library/aa379761(VS.85).aspx
'LONG STDCALL SCardGetProviderIdA(SCARDCONTEXT(in), LPCSTR(in), LPGUID(out))
Public Declare Function SCardGetProviderId Lib "winscard.dll" Alias "SCardGetProviderIdA" ( _
    ByVal hContext As Long, _
    ByVal szCard As String, _
    ByRef pguidProviderId As GUID _
    ) As Long

'SCardGetStatusChange
'http://msdn.microsoft.com/en-us/library/aa379773(VS.85).aspx
'LONG STDCALL SCardGetStatusChangeA(SCARDCONTEXT(in), DWORD(in),
' LPSCARD_READERSTATEA(inout), DWORD(in))
Public Declare Function SCardGetStatusChange Lib "winscard.dll" Alias "SCardGetStatusChangeA" ( _
    ByVal hContext As Long, _
    ByVal dwTimeout As Long, _
    ByRef rgReaderStates() As SCARD_READERSTATE, _
    ByVal cReaders As Long _
    ) As Long

'SCardIntroduceCardType
'http://msdn.microsoft.com/en-us/library/aa379784(VS.85).aspx
'LONG STDCALL SCardIntroduceCardTypeA(SCARDCONTEXT(in), LPCSTR(in), LPCGUID(in),
' LPCGUID(in), DWORD(in), LPCBYTE(in), LPCBYTE(in), DWORD(in))
Public Declare Function SCardIntroduceCardType Lib "winscard.dll" Alias "SCardIntroduceCardTypeA" ( _
    ByVal hContext As Long, _
    ByVal szCardName As String, _
    ByRef pguidPrimaryProvider As GUID, _
    ByRef pguidInterfaces As GUID, _
    ByVal dwInterfaceCount As Long, _
    ByVal pbAtr As ByteArray, _
    ByVal pbAtrMask As ByteArray, _
    ByVal cbAtrLen As Long _
    ) As Long

'SCardIntroduceReader
'http://msdn.microsoft.com/en-us/library/aa379786(VS.85).aspx
'LONG STDCALL SCardIntroduceReaderA(SCARDCONTEXT(in), LPCSTR(in), LPCSTR(in))
Public Declare Function SCardIntroduceReader Lib "winscard.dll" Alias "SCardIntroduceReaderA" ( _
    ByVal hContext As Long, _
    ByVal szReaderName As String, _
    ByVal szDeviceName As String _
    ) As Long

'SCardIntroduceReaderGroup
'http://msdn.microsoft.com/en-us/library/aa379787(VS.85).aspx
'LONG STDCALL SCardIntroduceReaderGroupA(SCARDCONTEXT(in), LPCSTR(in))
Public Declare Function SCardIntroduceReaderGroup Lib "winscard.dll" Alias "SCardIntroduceReaderGroupA" ( _
    ByVal hContext As Long, _
    ByVal szGroupName As String _
    ) As Long

'SCardIsValidContext
'http://msdn.microsoft.com/en-us/library/aa379788(VS.85).aspx
'LONG STDCALL SCardIsValidContext(SCARDCONTEXT(in))
Public Declare Function SCardIsValidContext Lib "winscard.dll" ( _
    ByVal hContext As Long _
) As Long

'SCardListCards
'http://msdn.microsoft.com/en-us/library/aa379789(VS.85).aspx
'LONG STDCALL SCardListCardsA(SCARDCONTEXT(in), LPCBYTE(in), LPCGUID(in), DWORD(in),
' LPCSTR(out), LPDWORD(inout))
Public Declare Function SCardListCards Lib "winscard.dll" Alias "SCardListCardsA" ( _
    ByVal hContext As Long, _
    ByVal pbAtr As ByteArray, _
    ByVal rgguidInterfaces As Long, _
    ByVal cguidInterfaceCount As Long, _
    ByVal mszCards As String, _
    ByRef pcchCards As Long _
    ) As Long

'SCardListInterfaces
'http://msdn.microsoft.com/en-us/library/aa379790(VS.85).aspx
'LONG STDCALL SCardListInterfacesA(SCARDCONTEXT(in), LPCSTR(in), LPGUID(out),
' LPDWORD(inout))
Public Declare Function SCardListInterfaces Lib "winscard.dll" Alias "SCardListInterfacesA" ( _
    ByVal hContext As Long, _
    ByVal szCard As String, _
    ByRef pguidInterfaces As GUID, _
    ByRef pcguidInterfaces As Long _
    ) As Long

'SCardListReaderGroups
'http://msdn.microsoft.com/en-us/library/aa379792(VS.85).aspx
'LONG STDCALL SCardListReaderGroupsA(SCARDCONTEXT(in), LPSTR(out), LPDWORD(inout))
Public Declare Function SCardListReaderGroups Lib "winscard.dll" Alias "SCardListReaderGroupsA" ( _
    ByVal hContext As Long, _
    ByVal mszGroups As String, _
    ByRef pcchGroups As Long _
    ) As Long

'SCardListReaders
'http://msdn.microsoft.com/en-us/library/aa379793(VS.85).aspx
'LONG STDCALL SCardListReadersA(SCARDCONTEXT(in), LPCSTR(in), LPSTR(out), LPDWORD(inout))
Public Declare Function SCardListReaders Lib "winscard.dll" Alias "SCardListReadersA" ( _
    ByVal hContext As Long, _
    ByVal mszGroups As String, _
    ByVal mszReaders As String, _
    ByRef pcchReaders As Long _
    ) As Long

'SCardLocateCards
'http://msdn.microsoft.com/en-us/library/aa379794(VS.85).aspx
'LONG STDCALL SCardLocateCardsA(SCARDCONTEXT(in), LPCSTR(in),
' LPSCARD_READERSTATEA(inout), DWORD(in))
Public Declare Function SCardLocateCards Lib "winscard.dll" Alias "SCardLocateCardsA" ( _
    ByVal hContext As Long, _
    ByVal mszCards As String, _
    ByRef rgReaderStates() As SCARD_READERSTATE, _
    ByVal cReaders As Long _
    ) As Long

'SCardLocateCardsByATR
'http://msdn.microsoft.com/en-us/library/aa379796(VS.85).aspx
'LONG STDCALL SCardLocateCardsByATRA(SCARDCONTEXT(in), LPSCARD_ATRMASK(in), DWORD(in),
' LPSCARD_READERSTATEA(inout), DWORD(in))
Public Declare Function SCardLocateCardsByATR Lib "winscard.dll" Alias "SCardLocateCardsByATRA" ( _
    ByVal hContext As Long, _
    ByRef rgAtrMasks() As SCARD_ATRMASK, _
    ByVal cAtrs As Long, _
    ByRef rgReaderStates() As SCARD_READERSTATE, _
    ByVal cReaders As Long _
    ) As Long

'SCardReconnect
'http://msdn.microsoft.com/en-us/library/aa379797(VS.85).aspx
'LONG STDCALL SCardReconnect(SCARDHANDLE(in), DWORD(in), DWORD(in), DWORD(in),
' LPDWORD(out))
Public Declare Function SCardReconnect Lib "winscard.dll" ( _
    ByVal hCard As Long, _
    ByVal dwShareMode As Long, _
    ByVal dwPreferredProtocols As Long, _
    ByVal dwInitialization As Long, _
    ByRef pdwActiveProtocol As Long _
    ) As Long

'SCardReleaseContext
'http://msdn.microsoft.com/en-us/library/aa379798(VS.85).aspx
'LONG STDCALL SCardReleaseContext(SCARDCONTEXT(in))
Public Declare Function SCardReleaseContext Lib "winscard.dll" ( _
    ByVal hContext As Long _
    ) As Long

'SCardReleaseStartedEvent
'http://msdn.microsoft.com/en-us/library/aa379799(VS.85).aspx
'VOID STDCALL SCardReleaseStartedEvent(HANDLE(in))
Public Declare Sub SCardReleaseStartedEvent Lib "winscard.dll" ( _
    ByVal hStartedEventHandle As Long _
    )

'SCardRemoveReaderFromGroup
'http://msdn.microsoft.com/en-us/library/aa379800(VS.85).aspx
'LONG STDCALL SCardRemoveReaderFromGroupA(SCARDCONTEXT(in), LPCSTR(in), LPCSTR(in))
Public Declare Function SCardRemoveReaderFromGroup Lib "winscard.dll" Alias "SCardRemoveReaderFromGroupA" ( _
    ByVal hContext As Long, _
    ByVal szReaderName As String, _
    ByVal szGroupName As String _
    ) As Long

'SCardSetAttrib
'http://msdn.microsoft.com/en-us/library/aa379801(VS.85).aspx
'LONG STDCALL SCardSetAttrib(SCARDHANDLE(in), DWORD(in), LPCBYTE(in), DWORD(in))
Public Declare Function SCardSetAttrib Lib "winscard.dll" ( _
    ByVal hCard As Long, _
    ByVal dwAttrId As Long, _
    ByVal pbAttr As ByteArray, _
    ByVal cbAttrLen As Long _
    ) As Long

'SCardSetCardTypeProviderName
'http://msdn.microsoft.com/en-us/library/aa379802(VS.85).aspx
'LONG STDCALL SCardSetCardTypeProviderNameA(SCARDCONTEXT(in), LPCSTR(in), DWORD(in),
' LPCSTR(in))
Public Declare Function SCardSetCardTypeProviderName Lib "winscard.dll" Alias "SCardSetCardTypeProviderNameA" ( _
    ByVal hContext As Long, _
    ByVal szCardName As String, _
    ByVal dwProviderId As Long, _
    ByVal szProvider As String _
    ) As Long

'SCardState
'LONG STDCALL SCardState(SCARDHANDLE(in), LPDWORD(out), LPDWORD(out), LPBYTE(out),
' LPDWORD(out))
Public Declare Function SCardState Lib "winscard.dll" ( _
    ByVal hCard As Long, _
    ByRef pdwState As Long, _
    ByRef pdwProtocol As Long, _
    ByRef pbAtr As ByteArray, _
    ByRef pcbAtrLen As Long _
) As Long

'SCardStatus
'http://msdn.microsoft.com/en-us/library/aa379803(VS.85).aspx
'LONG STDCALL SCardStatusA(SCARDHANDLE(in), LPSTR(out), LPDWORD(inout), LPDWORD(out),
' LPDWORD(out), LPBYTE(out), LPDWORD(inout))
Public Declare Function SCardStatus Lib "winscard.dll" Alias "SCardStatusA" ( _
    ByVal hCard As Long, _
    ByVal szReaderName As String, _
    ByRef pcchReaderLen As Long, _
    ByRef pdwState As Long, _
    ByRef pdwProtocol As Long, _
    ByRef pbAtr As ByteArray, _
    ByRef pcbAtrLen As Long _
    ) As Long

'SCardTransmit
'http://msdn.microsoft.com/en-us/library/aa379804.aspx
'LONG STDCALL SCardTransmit(SCARDHANDLE(in), LPCSCARD_IO_REQUEST(in), LPCBYTE(in),
' DWORD(in), LPSCARD_IO_REQUEST(inout), LPBYTE(out), LPDWORD(inout))
Public Declare Function SCardTransmit Lib "winscard.dll" ( _
    ByVal hCard As Long, _
    ByRef pioSendPci As SCARD_IO_REQUEST, _
    ByRef pbSendBuffer As Byte, _
    ByVal cbSendLength As Long, _
    ByRef pioRecvPci As SCARD_IO_REQUEST, _
    ByRef pbRecvBuffer As Byte, _
    ByRef pcbRecvLength As Long _
) As Long

Public Declare Function SCardTransmitLong Lib "winscard.dll" Alias "SCardTransmit" ( _
    ByVal hCard As Long, _
    ByRef pioSendPci As SCARD_IO_REQUEST, _
    ByRef pbSendBuffer As Byte, _
    ByVal cbSendLength As Long, _
    ByVal pioRecvPci As Long, _
    ByRef pbRecvBuffer As Byte, _
    ByRef pcbRecvLength As Long _
) As Long
jleach
What line is highlighted on the compile error? At a quick glance they look like all API declarations and they appear to be correct in syntax.

What version of Access are you using? If you're using 64 bit 2010 we'll need to adjust a few things.
jleach
Nevermind, I got the compile error stuff more or less squared away.

Add the following to your module, after the Option Explicit but before all the declarations you posted:

CODE
'http://msdn.microsoft.com/en-us/library/aa379808(v=vs.85).aspx
Public Type SCARD_READERSTATE
  szReader As String
  pvUserData As Long
  dwCurrentState As Long
  dwEventState As Long
  cbAtr As Long
  rgbAtr As Byte
End Type

'http://msdn.microsoft.com/en-us/library/aa922903.aspx
Public Type SCARD_ATRMASK
  cbAtr As Long
  rgbAtr As Byte
  rgbMask As Byte
End Type

'http://msdn.microsoft.com/en-us/library/aa379807.aspx
Public Type SCARD_IO_REQUEST
  dwProtocol As Long
  dwPciLength As Long
End Type


These are structures (User Defined Types (UDTs)) that are required for certain parameters of the API stuff. Once declared, you assign them as a variable type: Dim x As SCARD_ATRMASK etc.

Also, do a Find/Replace in the module and change the following:

ByteArray to Long
Guid to Long

(note that I'm not positive Longs are sufficient for this, but it gets the code to compile for the time being and can be debugged afterwords)

Do you happen to have the link where you found this code by chance? Nice find...
jleach
Just as a side note, I don't know if you've ever gotten into API programming at all... it's a bit of a complex beast, but it can be done. If you're unfamiliar with it, you will definately have your work cut out for you. The following wiki article (unfinished at this time) attempts to give an overall walkthrough of the ins and outs of API programming: API. Perhaps a runthrough of this will give you some ideas of what you'll be working with. It's a bit different mindset than standard VBA programming.

Good luck,
Tiesto_X
Hi,

its Windows 7 x64 and Office 2007 x32.

I'm not at home right now, but since user got Windows XP x32 i will need Virtual Machine in test purpose.

I'll test code and see what I get.

This is the article link: http://www.rolbe.com/2009/03/01/vb6-winscard-api/

Thank you.

EDIT: I never worked with API, you are right, its BEAST for me, but with your help I have a hope.

I will read Wiki for sure.

Thanks again.
jleach
OS 32bit vs. 64bit will be mostly irrelevant to us, being that the Application we're working with will be using the 32bit OS functions (it's the 64bit Office that gets even more tricky, because it uses the newer 64bit OS architectures).

I took a look at the link... the bad news is you should disregard those previous edits I told you about. The good news is that the zip file contains a module that has everything worked up correctly (what I had was a fix to get it compiled, but I didn't think it was correct).

Open the winscard.bas file in the zip provided (it's just a text file) and copy/paste that code into your module. It should compile fine. (note at the top of the module all the Public Types that define the required datatypes).

You can also probably import the file directly... from the VBE in the module list right click then Import then select the file. We'll go from there.

Cheers,
Tiesto_X
Glad to hear good news!

I copied code into module it does compile, but i need to delete :
CODE
Attribute VB_Name = "winscard"


What should I do with this? Its even above
CODE
Option Compare Database
Option Explicit
jleach
More notes on working with API stuff:

The MSDN contains entries for each of the functions exposed through the API (you'll find these links at the top of each declaration). These give complete instructions and details on how the functions work: it's all there, the problem is deciphering it and makeing use of it. When we're venturing into new API projects, we'll tend to spend a lot of time reading on the function details (or general overviews on the task) to figure out what it is we need to do.

Declaring the API functions and structs (types) are a third of the problem. Finding out how to use those functions as required to complete a task is the second third. Finally, writing and testing the VBA code itself that makes use of the functions in the final third.

We've luckily got one step more or less complete: the API declarations have been spelled out for us. Next is to figure out what's what.... ideally, the MSDN will have an overview article that more or less says to use a card reader, you must do This and This and This and This. If there is such an article present, they should give some very helpful clues as to which MSDN functions we need to be reading about. If not, we'll have to pick one and go from there (generally, an MSDN function documentation will refer to other functions/structs, which then refers to other functions/structs, etc, so if we pick a function from the declaration list at random, chances are we'll end up touching base on many of the others before we're done... take notes while you're going through this!)

To find related information (such as overview articles) in the MSDN, often the left sidebar will have a sort of treeview which has the functions listed. Sometimes, you can work your way back up a few levels to get overview details. Sometimes, though, you're just stuck with the functions themselves.

This is general API investigation work. Luckily though, the other files in that zip are VB6 files which I'm guessing provide some sort of examples on how to actually do this, which may save tons of work in testing and trying to make sense of the ever-fun MSDN documentation.

Even though this project was done in VB6, much of it can still be made use of for VBA. For example, even though we probably can't import the "Form1.frm" VB6 Form object to our Access project, we can open the file with a text editor (notepad++ is highly recommended) and get some clues as to the form's construction, as well as the code contained in the form's module. With a little investigation, this may tell us what functions need to be called in what order, so on and so forth. (also note that the zip file contains a "PCSC_API_Test.exe" or "SimplePC_SC.exe", which are presumably the compiled output of the VB6 project(s), and may be able to be used as a testing tool to see if the thing does what's required or not.)

That should do for now...

Cheers,
jleach
QUOTE (Tiesto_X @ May 7 2012, 07:23 AM) *
Glad to hear good news!

I copied code into module it does compile, but i need to delete :
CODE
Attribute VB_Name = "winscard"


What should I do with this? Its even above
CODE
Option Compare Database
Option Explicit



The "Attribute" line is put in when you output a file from VB/VBA. Delete it from the code, it's a behind the scenes thing and not required (by us anyway).

Option Compare Database and Option Explicit are only allowed once, and must be at the very top of the module.
Tiesto_X
You are extremely helpful!

I'll try to do all testings and back with results.

Very thanks for your time.

EDIT:

I see in Form that there is ByteArray. How should I declare that in VBA?
jleach
ByteArray is defined as a UDT in the winscard.bas file:

CODE
Public Const DEFAULT_BUFFER_SIZE As Integer = 255

Public Type ByteArray
b(0 To DEFAULT_BUFFER_SIZE) As Byte
End Type


(as is Guid, when you see what one as well):

CODE
Public Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type


Cheers,
Tiesto_X
Cristal clear!

Thanks.
Tiesto_X
Hi,

sorry if its off topic but dont know where to search for help anymore...

I have a big problem. Can't solve it.

Still didn't start to work on this project because card reader doesn't recognize card.

I installed drivers and two programs from vendors site, SmartDiag and GemPSCS.
On device manager it says: This device is working properly.

On the pictures below you will see errors.

What I tried:

- Different PC's
- Different OS's (XP x32 SP3 and Windows 7 x64)
- Old drivers
- System reinstall (on Virtual Machine)
- To follow troubleshooter instruction from vendors site: http://support.gemalto.com/index.php?id=202
- New Card Reader
- New Smart Card
- Old registered Smart Card
- Tried to google the error

What I noticed is that SmartDiag shows different for both Card Readers.
First doesn't even recognize the Smart Card and second says: MuteCard

Anyone had similar problem ?
jleach
Hi,

You might have better luck starting a new thread in the Q/A - Hardware or Software forums rather than here (often when threads get to be fairly deep new posts tend to go unnoticed except by a few).

Also you might try any resources available from the manufacturer... I would think this would be something their support would cover assuming you just purchased it (as in calling and saying hey, walk me through this).

Either way, I'm not sure what to do with it myself... never really worked with them and I'm only good with drivers if they do what they're supposed to thumbup.gif

Cheers,
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.