12/26/2021 Update: A PowerBuilder 2021 sample app that includes all of the following code is available in CodeXchange at: https://community.appeon.com/index.php/codeexchange/powerbuilder/306-reading-a-smard-card-from-powerbuilder
We’re going to look at using the Smart Card SDK provided in more recent versions of Windows (XP and later). Earlier versions of Windows had an ActiveX installed called CAPICOM which could be accessed from PowerBuilder through OLE Automation, but that control was removed as of Windows Vista because of security issues.
We’re going to look at a number of operations:
· Communication with the card
· Validating the user’s PIN
· Reading the certificate Subject Name
· Reading other certificate data
Note: This post was updated on December 8th, 2021 to support 64 bit compilation. Thanks to Jason Schultz for pointing out the problem and to John Fauss and others for pointing out the necessary changes.
Communicating with the card
The first step is establish a context for the API calls. To do that, we need to declare the following local external function for SCardEstablishContext:
Function ulong SCardEstablishContext ( &
ulong dwScope, &
longptr pvReserved1, &
longptr pvReserved2, &
REF longptr phContext &
) Library "winscard.dll"
|
And call it as follows:
ulong rc
rc = scardestablishcontext( SCARD_SCOPE_USER, 0, 0, context )
IF rc = SCARD_S_SUCCESS THEN
Return SUCCESS
ELSE
Return FAILURE
END IF
|