📄 winscard.pas
字号:
{******************************************************************}
{ }
{ Borland Delphi Runtime Library }
{ PCSC interface unit }
{ }
{ Portions created by Microsoft are }
{ Copyright (C) 1996 Microsoft Corporation. }
{ All Rights Reserved. }
{ }
{ The original file is: WinSCard.h }
{ The original Pascal code is: WinSCard.pas }
{ The initial developer of the Pascal code is Chris Dickerson }
{ (chrisd@tsc.com). }
{ }
{ Obtained through: }
{ }
{ Joint Endeavour of Delphi Innovators (Project JEDI) }
{ }
{ You may retrieve the latest version of this file at the Project }
{ JEDI home page, located at http://delphi-jedi.org }
{ }
{ The contents of this file are used with permission, subject to }
{ the Mozilla Public License Version 1.1 (the "License"); you may }
{ not use this file except in compliance with the License. You may }
{ obtain a copy of the License at }
{ http://www.mozilla.org/MPL/MPL-1.1.html }
{ }
{ Software distributed under the License is distributed on an }
{ "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or }
{ implied. See the License for the specific language governing }
{ rights and limitations under the License. }
{ }
{******************************************************************}
unit WinSCard;
interface
uses
Windows;
{$IFDEF WinSCard_LINKONREQUEST}
{$DEFINE WinSCard_DYNLINK}
{$ENDIF}
type
LPCGUID = ^GUID;
{$EXTERNALSYM LPCGUID}
GUID = record
Data1: LongInt;
Data2: Integer;
Data3: Integer;
Data4: array[0..7] of Byte;
end;
{$EXTERNALSYM GUID}
(*
Copyright (c) 1996 Microsoft Corporation
Module Name:
WinSCard
Abstract:
This header file provides the definitions and symbols necessary for an
Application or Smart Card Service Provider to access the Smartcard
Subsystem.
Environment:
Win32
Notes:
*)
var
LPCBYTE: PUChar;
{$EXTERNALSYM LPCBYTE}
LPCVOID: Pointer; { VOID *LPCVOID; }
{$EXTERNALSYM LPCVOID}
type
PSCARD_IO_REQUEST = ^SCARD_IO_REQUEST;
{$EXTERNALSYM PSCARD_IO_REQUEST}
SCARD_IO_REQUEST = record
dwProtocol: DWORD; { Protocol identifier }
dbPciLength: DWORD; { Protocol Control Information Length }
end;
{$EXTERNALSYM SCARD_IO_REQUEST}
//
////////////////////////////////////////////////////////////////////////////////
//
// Service Manager Access Services
//
// The following services are used to manage user and terminal contexts for
// Smart Cards.
//
type
SCARDCONTEXT = DWORD;
{$EXTERNALSYM SCARDCONTEXT}
SCARDHANDLE = DWORD;
{$EXTERNALSYM SCARDHANDLE}
var
PSCARDCONTEXT, LPSCARDCONTEXT: ^SCARDCONTEXT; { SCARDCONTEXT * }
{$EXTERNALSYM PSCARDCONTEXT}
{$EXTERNALSYM LPSCARDCONTEXT}
PSCARDHANDLE, LPSCARDHANDLE: ^SCARDHANDLE; { SCARDHANDLE * }
{$EXTERNALSYM PSCARDHANDLE}
{$EXTERNALSYM LPSCARDHANDLE}
const
SCARD_AUTOALLOCATE = DWORD(-1);
{$EXTERNALSYM SCARD_AUTOALLOCATE}
SCARD_SCOPE_USER = 0; // The context is a user context, and any
{$EXTERNALSYM SCARD_SCOPE_USER} // database operations are performed within the
// domain of the user.
SCARD_SCOPE_TERMINAL = 1; // The context is that of the current terminal,
{$EXTERNALSYM SCARD_SCOPE_TERMINAL} // and any database operations are performed
// within the domain of that terminal. (The
// calling application must have appropriate
// access permissions for any database actions.)
SCARD_SCOPE_SYSTEM = 2; // The context is the system context, and any
{$EXTERNALSYM SCARD_SCOPE_SYSTEM} // database operations are performed within the
// domain of the system. (The calling
// application must have appropriate access
// permissions for any database actions.)
{$IFDEF WinSCard_DYNLINK}
type
TSCardEstablishContext = function (dwScope: DWORD; pvReserved1: Pointer; pvReserved2: Pointer;
phContext: Pointer): LongInt; stdcall;
TSCardReleaseContext = function (hContext: LongInt): LongInt; stdcall;
TSCardIsValidContext = function (hContext: LongInt): LongInt; stdcall;
{$ELSE}
function SCardEstablishContext(dwScope: DWORD; pvReserved1: Pointer; pvReserved2: Pointer;
phContext: Pointer): LongInt; stdcall;
{$EXTERNALSYM SCardEstablishContext}
function SCardReleaseContext(hContext: LongInt): LongInt; stdcall;
{$EXTERNALSYM SCardReleaseContext}
function SCardIsValidContext(hContext: LongInt): LongInt; stdcall;
{$EXTERNALSYM SCardIsValidContext}
{$ENDIF}
//
////////////////////////////////////////////////////////////////////////////////
//
// Smart Card Database Management Services
//
// The following services provide for managing the Smart Card Database.
//
const
SCARD_ALL_READERS = 'SCard$AllReaders' + Chr(0) + Chr(0);
{$EXTERNALSYM SCARD_ALL_READERS}
SCARD_DEFAULT_READERS = 'SCard$DefaultReaders' + Chr(0) + Chr(0);
{$EXTERNALSYM SCARD_DEFAULT_READERS}
SCARD_LOCAL_READERS = 'SCard$LocalReaders' + Chr(0) + Chr(0);
{$EXTERNALSYM SCARD_LOCAL_READERS}
SCARD_SYSTEM_READERS = 'SCard$SystemReaders' + Chr(0) + Chr(0);
{$EXTERNALSYM SCARD_SYSTEM_READERS}
SCARD_PROVIDER_PRIMARY = 1; // Primary Provider Id
{$EXTERNALSYM SCARD_PROVIDER_PRIMARY}
SCARD_PROVIDER_CSP = 2; // Crypto Service Provider Id
{$EXTERNALSYM SCARD_PROVIDER_CSP}
//
// Database Reader routines
//
{$IFDEF WinSCard_DYNLINK}
type
TSCardListReaderGroupsA = function (hContext: LongInt; mszGroups: LPStr; var pcchGroups: LongInt): LongInt; stdcall;
TSCardListReaderGroupsW = function (hContext: LongInt; mszGroups: LPWStr; var pcchGroups: LongInt): LongInt; stdcall;
{$IFDEF UNICODE}
TSCardListReaderGroups = TSCardListReaderGroupsW;
{$ELSE}
TSCardListReaderGroups = TSCardListReaderGroupsA;
{$ENDIF}
TSCardListReadersA = function (SCARDCONTEXT: LongInt; mszGroups: LPStr; mszReaders: LPStr;
var pcchReaders: LongInt): LongInt; stdcall;
TSCardListReadersW = function (SCARDCONTEXT: LongInt; mszGroups: LPWStr; mszReaders: LPWStr;
var pcchReaders: LongInt): LongInt; stdcall;
{$IFDEF UNICODE}
TSCardListReaders = TSCardListReadersW;
{$ELSE}
TSCardListReaders = TSCardListReadersA;
{$ENDIF}
TSCardListCardsA = function (hContext: LongInt; var pbAtr: Byte; var rgguidInterfaces: GUID;
cguidInterfaceCount: LongInt; mszCards: LPStr; var pcchCards: LongInt): LongInt; stdcall;
TSCardListCardsW = function (hContext: LongInt; var pbAtr: Byte; var rgguidInterfaces: GUID;
cguidInterfaceCount: LongInt; mszCards: LPWStr; var pcchCards: LongInt): LongInt; stdcall;
{$IFDEF UNICODE}
TSCardListCards = TSCardListCardsW;
{$ELSE}
TSCardListCards = TSCardListCardsA;
{$ENDIF}
{$ELSE}
function SCardListReaderGroupsA(hContext: LongInt; mszGroups: LPStr; var pcchGroups: LongInt): LongInt; stdcall;
{$EXTERNALSYM SCardListReaderGroupsA}
function SCardListReaderGroupsW(hContext: LongInt; mszGroups: LPWStr; var pcchGroups: LongInt): LongInt; stdcall;
{$EXTERNALSYM SCardListReaderGroupsW}
function SCardListReadersA(SCARDCONTEXT: LongInt; mszGroups: LPStr; mszReaders: LPStr;
var pcchReaders: LongInt): LongInt; stdcall;
{$EXTERNALSYM SCardListReadersA}
function SCardListReadersW(SCARDCONTEXT: LongInt; mszGroups: LPWStr; mszReaders: LPWStr;
var pcchReaders: LongInt): LongInt; stdcall;
{$EXTERNALSYM SCardListReadersW}
function SCardListCardsA(hContext: LongInt; var pbAtr: Byte; var rgguidInterfaces: GUID;
cguidInterfaceCount: LongInt; mszCards: LPStr; var pcchCards: LongInt): LongInt; stdcall;
{$EXTERNALSYM SCardListCardsA}
function SCardListCardsW(hContext: LongInt; var pbAtr: Byte; var rgguidInterfaces: GUID;
cguidInterfaceCount: LongInt; mszCards: LPWStr; var pcchCards: LongInt): LongInt; stdcall;
{$EXTERNALSYM SCardListCardsW}
{$ENDIF}
//
// NOTE: The routine SCardListCards name differs from the PC/SC definition.
// It should be:
//
// extern WINSCARDAPI LONG WINAPI
// SCardListCardTypes(
// IN SCARDCONTEXT hContext,
// IN LPCBYTE pbAtr,
// IN LPCGUID rgquidInterfaces,
// IN DWORD cguidInterfaceCount,
// OUT LPTSTR mszCards,
// IN OUT LPDWORD pcchCards);
//
// Here's a work-around MACRO:
//#define SCardListCardTypes SCardListCards
{$IFDEF WinSCard_DYNLINK}
type
TSCardListCardTypes = TSCardListCardsA;
TSCardListInterfacesA = function (hContext: LongInt; szCard: LPStr; var pguidInterfaces: GUID;
var pcguidInterfaces: LongInt): LongInt; stdcall;
TSCardListInterfacesW = function (hContext: LongInt; szCard: LPWStr; var pguidInterfaces: GUID;
var pcguidInterfaces: LongInt): LongInt; stdcall;
{$IFDEF UNICODE}
TSCardListInterfaces = TSCardListInterfacesW;
{$ELSE}
TSCardListInterfaces = TSCardListInterfacesA;
{$ENDIF}
TSCardGetProviderIdA = function (hContext: LongInt; szCard: LPStr; var pguidProviderId: GUID): LongInt; stdcall;
TSCardGetProviderIdW = function (hContext: LongInt; szCard: LPWStr; var pguidProviderId: GUID): LongInt; stdcall;
{$IFDEF UNICODE}
TSCardGetProviderId = TSCardGetProviderIdW;
{$ELSE}
TSCardGetProviderId = TSCardGetProviderIdA;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -