Using Win32 functions in Visual FoxPro Image Gallery
COM
..msdn
CLSIDFromString
CoCreateGuid
CoTaskMemFree
CreateStreamOnHGlobal
GetHGlobalFromStream
StringFromGUID2
Code examples:
Custom GDI+ class
Enumerating devices installed on the local machine
How to generate GUID values
Smart Card Database Query Functions
Winsock: retrieving information about available transport protocols
Smart Card Database Query Functions

User rating: 9.67/10 (3 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Versions:
click to open
Before you begin:

Smart cards often are used in conjunction with security and personal privacy. Wherever possible, the resource manager uses the security mechanisms that exist within the underlying operating system (OS) when accessing a reader or smart card.

The smart card resource manager manages the access to readers and smart cards. It identifies and tracks resources, allocates readers and resources across multiple applications, and supports transaction primitives for accessing services that are available on a specified smart card.

The Smart Card Database contains a list of known smart cards, the interfaces and primary service provider of each card, and known smart card readers and reader groups.

Purchase complete VFP solution.
Download ACOS3 Class Library
DEFINE CLASS SmartCards As Session
#DEFINE SCARD_SCOPE_USER 0
#DEFINE SCARD_SCOPE_SYSTEM 2
#DEFINE SCARD_S_SUCCESS 0
#DEFINE SCARD_E_NO_SERVICE 0x8010001D

    hContext=0
    ReaderGroups=NULL
    Readers=NULL

PROCEDURE Init
    THIS.declare
    IF NOT THIS.EstablishContext()
        = MESSAGEBOX("SCardEstablishContext " +;
            "call failed.", 48, "Class Initialization Error")
        RETURN .F.
    ENDIF

    THIS.ReaderGroups = CREATEOBJECT("Collection")
    THIS.Readers = CREATEOBJECT("Collection")

    THIS.GetReaderGroups
    THIS.GetReaders

PROCEDURE Destroy
    THIS.ReleaseContext

PROTECTED PROCEDURE EstablishContext
    THIS.ReleaseContext

    LOCAL nResult, hContext
    STORE 0 TO nResult, hContext
    nResult = SCardEstablishContext(SCARD_SCOPE_USER,;
        0, 0, @hContext)

    THIS.hContext = m.hContext
RETURN (nResult=0)

PROTECTED PROCEDURE ReleaseContext
    IF THIS.hContext <> 0
        = SCardReleaseContext(THIS.hContext)
        THIS.hContext=0
    ENDIF

PROCEDURE GetReaderGroups
    DO WHILE THIS.ReaderGroups.Count > 0
        THIS.ReaderGroups.Remove(1)
    ENDDO

    LOCAL cBuffer, nBufsize, nResult
    nBufsize=1024
    cBuffer=REPLICATE(CHR(0), nBufsize)

    nResult = SCardListReaderGroups(THIS.hContext,;
        @cBuffer, @nBufsize)

    IF nResult <> SCARD_S_SUCCESS
        RETURN .F.
    ENDIF

    LOCAL nItemCount, nItemIndex, cItem
    nItemCount = ALINES(arrSCardItems, cBuffer, CHR(0))

    FOR nItemIndex=1 TO nItemCount
        cItem = STRTRAN(arrSCardItems[nItemIndex], CHR(0), "")
        IF LEN(m.cItem) > 0
            THIS.ReaderGroups.Add(m.cItem)
        ENDIF
    NEXT

PROCEDURE GetReaders()
    DO WHILE THIS.Readers.Count > 0
        THIS.Readers.Remove(1)
    ENDDO

    LOCAL cBuffer, nBufsize, nResult
    nBufsize=1024
    cBuffer=REPLICATE(CHR(0), nBufsize)

    nResult = SCardListReaders(THIS.hContext,;
        NULL, @cBuffer, @nBufsize)

    IF nResult <> SCARD_S_SUCCESS
        RETURN .F.
    ENDIF

    LOCAL nItemCount, nItemIndex, cItem
    nItemCount = ALINES(arrSCardItems, cBuffer, CHR(0))

    FOR nItemIndex=1 TO nItemCount
        cItem = STRTRAN(arrSCardItems[nItemIndex], CHR(0), "")
        IF LEN(m.cItem) > 0
            THIS.Readers.Add(m.cItem)
        ENDIF
    NEXT

PROTECTED PROCEDURE declare
    DECLARE LONG SCardEstablishContext IN Winscard;
        INTEGER dwScope, INTEGER pvReserved1,;
        INTEGER pvReserved2, INTEGER @phContext

    DECLARE LONG SCardReleaseContext IN Winscard;
        INTEGER hContext

    DECLARE LONG SCardListReaderGroups IN Winscard;
        LONG hContext, STRING @mszGroups,;
        LONG @pcchGroups

    DECLARE LONG SCardListReaders IN Winscard;
        INTEGER hContext, STRING mszGroups,;
        STRING @mszReaders, LONG @pcchReaders

    DECLARE LONG SCardListCards IN Winscard;
        INTEGER hContext, INTEGER pbAtr,;
        INTEGER rgguidInterfaces, LONG cguidInterfaceCount,;
        STRING @mszCards, LONG @pcchCards

    DECLARE LONG SCardListInterfaces IN Winscard;
        INTEGER hContext, STRING szCard,;
        STRING @pguidInterfaces, LONG @pcguidInterfaces

    DECLARE LONG SCardGetProviderId IN Winscard;
        INTEGER hContext, STRING szCard,;
        STRING @pguidProviderId

    DECLARE INTEGER StringFromGUID2 IN ole32;
        STRING rguid, STRING @lpsz, INTEGER cchMax

ENDDEFINE

User rating: 9.67/10 (3 votes)
Rate this code sample:
  • ~
3123 bytes  
Created: 2008-10-22 20:30:53  
Modified: 2009-12-15 16:03:29  
Visits in 7 days: 181  
Listed functions:
SCardEstablishContext
SCardGetProviderId
SCardListCards
SCardListInterfaces
SCardListReaderGroups
SCardListReaders
SCardReleaseContext
StringFromGUID2
Printer friendly API declarations
My comment:
Use the following code to test the SmartCard classes:

LOCAL oSmartCards As SmartCards
oSmartCards = CREATEOBJECT("SmartCards")

FOR EACH cReaderGroup IN oSmartCards.ReaderGroups
        ? cReaderGroup
NEXT

FOR EACH cReader IN oSmartCards.Readers
        ? cReader
NEXT
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com offers instant, free translations of text or web pages.
User Contributed Notes:
There are no notes on this subject.


Copyright 2001-2018 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

Privacy policy
Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.6.39), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (54.226.41.91)
22 sec.Function: 'FindNextVolumeMountPoint'
Function group: 'File System'
40 sec.Function: 'SetEvent'
Function group: 'Synchronization'
1 min.Example: 'Windows Shell Icons displayed and exported to ICO files (Vista)'
1.3 min.Updates
1.63 min.Function: 'GetLogicalDrives'
Function group: 'File System'
1.95 min.Function: 'getservbyname'
Function group: 'Windows Sockets 2 (Winsock)'
2.3 min.Function: 'FindNextVolume'
Function group: 'File System'
2.67 min.Example: 'Using WM_COPYDATA for interprocess communication (VFP9)'
3.05 min.Function: 'UrlEscape'
Function group: 'Shell Lightweight Utility APIs -- Path Functions'
3.4 min.Function: 'WNetGetNetworkInformation'
Function group: 'Windows Networking'
Google
Advertise here!