Consulting

Results 1 to 3 of 3

Thread: How do use winscard.dll within VBA?

  1. #1

    How do you use winscard.dll within VBA?

    I am using Access 2010 with a SQL Server 2005 backend. I am using VBA to manipulate the code in SQL Server. Last week I was given a requirement to read a CAC( card inserted in an ActivIdentity card reader ), find the user who is logged in and then log into the SQL Server as that user. I am using winscard.dll to connect to the card reader.

    The following is the declaration I am using:
    'SCardEstablishContext
    '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
    This is how I am calling the function:
    ...
    Dim lParam1 As Long
    Dim lParam4 As Long
    Dim lReturn As Long

    lParam1 = 1
    lReturn = SCardEstablishContext(lParam1, 0, 1, lParam4)
    ...
    The function does not error out, however, the lReturn is = "-2146435055"

    QUESTIONS:
    How do I set up SCardEstablishContext to run properly?
    How do I set up lParam4 to hold all of the information after SCardEstablishContext runs correctly?
    Thanks in advance,
    Last edited by mikwilmot; 10-01-2013 at 06:52 AM.

  2. #2
    I have changed the code slightly. However, the call to SCardEstablishContext fails with the same return "-2146435055".

    Have a look.

    Public Type SCARDCONTEXT
    CardContext1 As Long
    ReaderName As Byte
    End Type

    'SCardEstablishContext
    '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 SCARDCONTEXT _
    ) As Long
    ....

    Dim lParam1 As Long
    Dim lParam4 As SCARDCONTEXT
    Dim lReturn As Long

    lParam1 = 1

    lReturn = SCardEstablishContext(lParam1, 0, 0, lParam4)

    ....

  3. #3
    VBAX Newbie
    Joined
    Feb 2014
    Posts
    1
    Location
    Did you ever make any progress with this project? Im in the same boat and just starting to go down this path. Looking to pull information from the CAC to validate user credentials.

    Any help would be appreciated.

    Thanks,
    Sven

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •