DNIE smartcard hardware y software

DNIE smartcard hardware y software

Postby Antonio Linares » Thu Sep 07, 2023 7:50 am

Estimados amigos,

Alguno de vosotros usa un lector de DNI electrónico ó compatible con tarjetas ISO 7816 ?

En caso afirmativo:

1. que hardware usais ?
2. Lo usais desde Harbour ?
3. Que API usais ?

gracias por la ayuda
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: DNIE hardware y software

Postby Antonio Linares » Thu Sep 07, 2023 8:30 am

Windows proporciona winscard.dll para leer smartcards

Code: Select all  Expand view
#include <stdio.h>
#include <stdlib.h>
#include <winscard.h>

int main() {
    SCARDCONTEXT hContext;
    SCARDHANDLE hCard;
    DWORD dwReaders, dwActiveProtocol, dwReaderLen;
    LONG lResult;
    LPTSTR szReaders;
    BYTE pbAtr[MAX_ATR_SIZE];
    DWORD dwAtrLen;

    // Establish a context to the PC/SC Resource Manager
    lResult = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
    if (lResult != SCARD_S_SUCCESS) {
        printf("SCardEstablishContext failed with error: %08X\n", lResult);
        return 1;
    }

    // Get the list of available readers
    dwReaderLen = SCARD_AUTOALLOCATE;
    lResult = SCardListReaders(hContext, NULL, (LPTSTR)&szReaders, &dwReaderLen);
    if (lResult != SCARD_S_SUCCESS) {
        printf("SCardListReaders failed with error: %08X\n", lResult);
        SCardReleaseContext(hContext);
        return 1;
    }

    printf("Available readers:\n%s\n", szReaders);

    // Connect to the first reader in the list
    lResult = SCardConnect(hContext, szReaders, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &hCard, &dwActiveProtocol);
    if (lResult != SCARD_S_SUCCESS) {
        printf("SCardConnect failed with error: %08X\n", lResult);
        SCardFreeMemory(hContext, szReaders);
        SCardReleaseContext(hContext);
        return 1;
    }

    // Get the ATR of the card
    dwAtrLen = sizeof(pbAtr);
    lResult = SCardStatus(hCard, NULL, &dwReaderLen, &dwState, &dwActiveProtocol, pbAtr, &dwAtrLen);
    if (lResult != SCARD_S_SUCCESS) {
        printf("SCardStatus failed with error: %08X\n", lResult);
        SCardDisconnect(hCard, SCARD_LEAVE_CARD);
        SCardFreeMemory(hContext, szReaders);
        SCardReleaseContext(hContext);
        return 1;
    }

    printf("ATR of the card: ");
    for (DWORD i = 0; i < dwAtrLen; i++) {
        printf("%02X ", pbAtr[i]);
    }
    printf("\n");

    // Disconnect from the card
    lResult = SCardDisconnect(hCard, SCARD_LEAVE_CARD);
    if (lResult != SCARD_S_SUCCESS) {
        printf("SCardDisconnect failed with error: %08X\n", lResult);
    }

    // Release resources
    SCardFreeMemory(hContext, szReaders);
    SCardReleaseContext(hContext);

    return 0;
}
 

Para comprobar si teneis winscard.dll accesible:
Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

    MsgInfo( LoadLibrary( "winscard.dll" ) )

return nil  
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 62 guests