SCardListCardsA
関数シグネチャ
// WinSCard.dll (ANSI / -A)
#include <windows.h>
INT SCardListCardsA(
UINT_PTR hContext,
BYTE* pbAtr, // optional
const GUID* rgquidInterfaces, // optional
DWORD cguidInterfaceCount,
LPSTR mszCards, // optional
DWORD* pcchCards
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hContext | UINT_PTR | in | クエリの対象となるリソースマネージャーコンテキストを識別するハンドルです。リソースマネージャーコンテキストは、事前にSCardEstablishContextを呼び出すことで設定できます。 このパラメーターをNULLに設定した場合、カードの検索は特定のコンテキストに限定されません。 |
| pbAtr | BYTE* | inoptional | 既知のカードと比較する ATR 文字列のアドレスです。ATR の照合を行わない場合はNULLを指定します。 |
| rgquidInterfaces | GUID* | inoptional | 識別子(GUID)の配列です。インターフェイスの照合を行わない場合はNULLを指定します。配列を指定した場合、指定されたすべての識別子がカードでサポートされている場合にのみカード名が返されます。 |
| cguidInterfaceCount | DWORD | in | rgguidInterfaces配列のエントリ数です。rgguidInterfacesがNULLの場合、この値は無視されます。 |
| mszCards | LPSTR | outoptional | 見つかったスマートカードを列挙するマルチストリングです。この値がNULLの場合、SCardListCardsはpcchCardsで指定されたバッファー長を無視し、このパラメーターがNULLでなかった場合に返されるはずのバッファー長をpcchCardsに返したうえで、成功コードを返します。 |
| pcchCards | DWORD* | inout | mszCardsバッファーの長さ(文字数)です。すべての末尾のnull文字を含む、マルチストリング構造体の実際の長さを受け取ります。バッファー長として SCARD_AUTOALLOCATE を指定した場合、mszCardsはバイトポインターへのポインターに変換され、マルチストリング構造体を含むメモリブロックのアドレスを受け取ります。このメモリブロックは SCardFreeMemoryで解放する必要があります。 |
戻り値の型: INT
公式ドキュメント
スマートカードデータベースを検索し、ユーザーが以前にシステムへ登録した名前付きカードの一覧を提供します。(ANSI)
戻り値
この関数は、成功するか失敗するかに応じて異なる値を返します。
| 戻り値 | 説明 |
|---|---|
|
SCARD_S_SUCCESS。 |
|
エラーコード。詳細については、 スマートカードの戻り値を参照してください。 |
解説(Remarks)
この関数はリダイレクトされませんが、リモートデスクトップセッション内で呼び出してもエラーにはなりません。その場合、結果がローカルコンピューターではなくリモートコンピューターから返されることを意味するだけです。
サブシステムに登録されたすべてのスマートカードを返すには、pbAtrとrgguidInterfacesをNULLに設定します。
SCardListCards関数はデータベースクエリ関数です。その他のデータベースクエリ関数の詳細については、 スマートカードデータベースクエリ関数を参照してください。
この関数の呼び出しはトランザクションの外部で行う必要があります。アプリケーションがSCardBeginTransaction関数でトランザクションを開始した後にこの関数を呼び出すと、SCardBeginTransaction関数のhCardパラメーター(型はSCARDHANDLE)がリセットされます。
Windows Server 2008 R2 および Windows 7: トランザクション内でこの関数を呼び出すと、コンピューターが応答しなくなる可能性があります。
Windows Server 2008、Windows Vista、Windows Server 2003 および Windows XP: 該当しません。
例
次の例は、スマートカードの一覧表示を示しています。
LPTSTR pmszCards = NULL;
LPTSTR pCard;
LONG lReturn;
DWORD cch = SCARD_AUTOALLOCATE;
// Retrieve the list of cards.
lReturn = SCardListCards(NULL,
NULL,
NULL,
NULL,
(LPTSTR)&pmszCards,
&cch );
if ( SCARD_S_SUCCESS != lReturn )
{
printf("Failed SCardListCards\n");
exit(1); // Or other appropriate error action
}
// Do something with the multi string of cards.
// Output the values.
// A double-null terminates the list of values.
pCard = pmszCards;
while ( '\0' != *pCard )
{
// Display the value.
printf("%S\n", pCard );
// Advance to the next value.
pCard = pCard + wcslen(pCard) + 1;
}
// Remember to free pmszCards (by calling SCardFreeMemory).
// ...
winscard.h ヘッダーは、SCardListCards を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、不一致が生じ、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規約を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// WinSCard.dll (ANSI / -A)
#include <windows.h>
INT SCardListCardsA(
UINT_PTR hContext,
BYTE* pbAtr, // optional
const GUID* rgquidInterfaces, // optional
DWORD cguidInterfaceCount,
LPSTR mszCards, // optional
DWORD* pcchCards
);[DllImport("WinSCard.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern int SCardListCardsA(
UIntPtr hContext, // UINT_PTR
IntPtr pbAtr, // BYTE* optional
IntPtr rgquidInterfaces, // GUID* optional
uint cguidInterfaceCount, // DWORD
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder mszCards, // LPSTR optional, out
ref uint pcchCards // DWORD* in/out
);<DllImport("WinSCard.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SCardListCardsA(
hContext As UIntPtr, ' UINT_PTR
pbAtr As IntPtr, ' BYTE* optional
rgquidInterfaces As IntPtr, ' GUID* optional
cguidInterfaceCount As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPStr)> mszCards As System.Text.StringBuilder, ' LPSTR optional, out
ByRef pcchCards As UInteger ' DWORD* in/out
) As Integer
End Function' hContext : UINT_PTR
' pbAtr : BYTE* optional
' rgquidInterfaces : GUID* optional
' cguidInterfaceCount : DWORD
' mszCards : LPSTR optional, out
' pcchCards : DWORD* in/out
Declare PtrSafe Function SCardListCardsA Lib "winscard" ( _
ByVal hContext As LongPtr, _
ByVal pbAtr As LongPtr, _
ByVal rgquidInterfaces As LongPtr, _
ByVal cguidInterfaceCount As Long, _
ByVal mszCards As String, _
ByRef pcchCards As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SCardListCardsA = ctypes.windll.winscard.SCardListCardsA
SCardListCardsA.restype = ctypes.c_int
SCardListCardsA.argtypes = [
ctypes.c_size_t, # hContext : UINT_PTR
ctypes.POINTER(ctypes.c_ubyte), # pbAtr : BYTE* optional
ctypes.c_void_p, # rgquidInterfaces : GUID* optional
wintypes.DWORD, # cguidInterfaceCount : DWORD
wintypes.LPSTR, # mszCards : LPSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcchCards : DWORD* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WinSCard.dll')
SCardListCardsA = Fiddle::Function.new(
lib['SCardListCardsA'],
[
Fiddle::TYPE_UINTPTR_T, # hContext : UINT_PTR
Fiddle::TYPE_VOIDP, # pbAtr : BYTE* optional
Fiddle::TYPE_VOIDP, # rgquidInterfaces : GUID* optional
-Fiddle::TYPE_INT, # cguidInterfaceCount : DWORD
Fiddle::TYPE_VOIDP, # mszCards : LPSTR optional, out
Fiddle::TYPE_VOIDP, # pcchCards : DWORD* in/out
],
Fiddle::TYPE_INT)#[link(name = "winscard")]
extern "system" {
fn SCardListCardsA(
hContext: usize, // UINT_PTR
pbAtr: *mut u8, // BYTE* optional
rgquidInterfaces: *const GUID, // GUID* optional
cguidInterfaceCount: u32, // DWORD
mszCards: *mut u8, // LPSTR optional, out
pcchCards: *mut u32 // DWORD* in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WinSCard.dll", CharSet = CharSet.Ansi)]
public static extern int SCardListCardsA(UIntPtr hContext, IntPtr pbAtr, IntPtr rgquidInterfaces, uint cguidInterfaceCount, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder mszCards, ref uint pcchCards);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WinSCard_SCardListCardsA' -Namespace Win32 -PassThru
# $api::SCardListCardsA(hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards)#uselib "WinSCard.dll"
#func global SCardListCardsA "SCardListCardsA" sptr, sptr, sptr, sptr, sptr, sptr
; SCardListCardsA hContext, varptr(pbAtr), varptr(rgquidInterfaces), cguidInterfaceCount, varptr(mszCards), varptr(pcchCards) ; 戻り値は stat
; hContext : UINT_PTR -> "sptr"
; pbAtr : BYTE* optional -> "sptr"
; rgquidInterfaces : GUID* optional -> "sptr"
; cguidInterfaceCount : DWORD -> "sptr"
; mszCards : LPSTR optional, out -> "sptr"
; pcchCards : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WinSCard.dll" #cfunc global SCardListCardsA "SCardListCardsA" sptr, var, var, int, var, var ; res = SCardListCardsA(hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards) ; hContext : UINT_PTR -> "sptr" ; pbAtr : BYTE* optional -> "var" ; rgquidInterfaces : GUID* optional -> "var" ; cguidInterfaceCount : DWORD -> "int" ; mszCards : LPSTR optional, out -> "var" ; pcchCards : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WinSCard.dll" #cfunc global SCardListCardsA "SCardListCardsA" sptr, sptr, sptr, int, sptr, sptr ; res = SCardListCardsA(hContext, varptr(pbAtr), varptr(rgquidInterfaces), cguidInterfaceCount, varptr(mszCards), varptr(pcchCards)) ; hContext : UINT_PTR -> "sptr" ; pbAtr : BYTE* optional -> "sptr" ; rgquidInterfaces : GUID* optional -> "sptr" ; cguidInterfaceCount : DWORD -> "int" ; mszCards : LPSTR optional, out -> "sptr" ; pcchCards : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; INT SCardListCardsA(UINT_PTR hContext, BYTE* pbAtr, GUID* rgquidInterfaces, DWORD cguidInterfaceCount, LPSTR mszCards, DWORD* pcchCards) #uselib "WinSCard.dll" #cfunc global SCardListCardsA "SCardListCardsA" intptr, var, var, int, var, var ; res = SCardListCardsA(hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards) ; hContext : UINT_PTR -> "intptr" ; pbAtr : BYTE* optional -> "var" ; rgquidInterfaces : GUID* optional -> "var" ; cguidInterfaceCount : DWORD -> "int" ; mszCards : LPSTR optional, out -> "var" ; pcchCards : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT SCardListCardsA(UINT_PTR hContext, BYTE* pbAtr, GUID* rgquidInterfaces, DWORD cguidInterfaceCount, LPSTR mszCards, DWORD* pcchCards) #uselib "WinSCard.dll" #cfunc global SCardListCardsA "SCardListCardsA" intptr, intptr, intptr, int, intptr, intptr ; res = SCardListCardsA(hContext, varptr(pbAtr), varptr(rgquidInterfaces), cguidInterfaceCount, varptr(mszCards), varptr(pcchCards)) ; hContext : UINT_PTR -> "intptr" ; pbAtr : BYTE* optional -> "intptr" ; rgquidInterfaces : GUID* optional -> "intptr" ; cguidInterfaceCount : DWORD -> "int" ; mszCards : LPSTR optional, out -> "intptr" ; pcchCards : DWORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
winscard = windows.NewLazySystemDLL("WinSCard.dll")
procSCardListCardsA = winscard.NewProc("SCardListCardsA")
)
// hContext (UINT_PTR), pbAtr (BYTE* optional), rgquidInterfaces (GUID* optional), cguidInterfaceCount (DWORD), mszCards (LPSTR optional, out), pcchCards (DWORD* in/out)
r1, _, err := procSCardListCardsA.Call(
uintptr(hContext),
uintptr(pbAtr),
uintptr(rgquidInterfaces),
uintptr(cguidInterfaceCount),
uintptr(mszCards),
uintptr(pcchCards),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction SCardListCardsA(
hContext: NativeUInt; // UINT_PTR
pbAtr: Pointer; // BYTE* optional
rgquidInterfaces: PGUID; // GUID* optional
cguidInterfaceCount: DWORD; // DWORD
mszCards: PAnsiChar; // LPSTR optional, out
pcchCards: Pointer // DWORD* in/out
): Integer; stdcall;
external 'WinSCard.dll' name 'SCardListCardsA';result := DllCall("WinSCard\SCardListCardsA"
, "UPtr", hContext ; UINT_PTR
, "Ptr", pbAtr ; BYTE* optional
, "Ptr", rgquidInterfaces ; GUID* optional
, "UInt", cguidInterfaceCount ; DWORD
, "Ptr", mszCards ; LPSTR optional, out
, "Ptr", pcchCards ; DWORD* in/out
, "Int") ; return: INT●SCardListCardsA(hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards) = DLL("WinSCard.dll", "int SCardListCardsA(int, void*, void*, dword, char*, void*)")
# 呼び出し: SCardListCardsA(hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards)
# hContext : UINT_PTR -> "int"
# pbAtr : BYTE* optional -> "void*"
# rgquidInterfaces : GUID* optional -> "void*"
# cguidInterfaceCount : DWORD -> "dword"
# mszCards : LPSTR optional, out -> "char*"
# pcchCards : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "winscard" fn SCardListCardsA(
hContext: usize, // UINT_PTR
pbAtr: [*c]u8, // BYTE* optional
rgquidInterfaces: [*c]GUID, // GUID* optional
cguidInterfaceCount: u32, // DWORD
mszCards: [*c]u8, // LPSTR optional, out
pcchCards: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;proc SCardListCardsA(
hContext: uint, # UINT_PTR
pbAtr: ptr uint8, # BYTE* optional
rgquidInterfaces: ptr GUID, # GUID* optional
cguidInterfaceCount: uint32, # DWORD
mszCards: ptr char, # LPSTR optional, out
pcchCards: ptr uint32 # DWORD* in/out
): int32 {.importc: "SCardListCardsA", stdcall, dynlib: "WinSCard.dll".}pragma(lib, "winscard");
extern(Windows)
int SCardListCardsA(
size_t hContext, // UINT_PTR
ubyte* pbAtr, // BYTE* optional
GUID* rgquidInterfaces, // GUID* optional
uint cguidInterfaceCount, // DWORD
char* mszCards, // LPSTR optional, out
uint* pcchCards // DWORD* in/out
);ccall((:SCardListCardsA, "WinSCard.dll"), stdcall, Int32,
(Csize_t, Ptr{UInt8}, Ptr{GUID}, UInt32, Ptr{UInt8}, Ptr{UInt32}),
hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards)
# hContext : UINT_PTR -> Csize_t
# pbAtr : BYTE* optional -> Ptr{UInt8}
# rgquidInterfaces : GUID* optional -> Ptr{GUID}
# cguidInterfaceCount : DWORD -> UInt32
# mszCards : LPSTR optional, out -> Ptr{UInt8}
# pcchCards : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SCardListCardsA(
uintptr_t hContext,
uint8_t* pbAtr,
void* rgquidInterfaces,
uint32_t cguidInterfaceCount,
char* mszCards,
uint32_t* pcchCards);
]]
local winscard = ffi.load("winscard")
-- winscard.SCardListCardsA(hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards)
-- hContext : UINT_PTR
-- pbAtr : BYTE* optional
-- rgquidInterfaces : GUID* optional
-- cguidInterfaceCount : DWORD
-- mszCards : LPSTR optional, out
-- pcchCards : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WinSCard.dll');
const SCardListCardsA = lib.func('__stdcall', 'SCardListCardsA', 'int32_t', ['uintptr_t', 'uint8_t *', 'void *', 'uint32_t', 'char *', 'uint32_t *']);
// SCardListCardsA(hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards)
// hContext : UINT_PTR -> 'uintptr_t'
// pbAtr : BYTE* optional -> 'uint8_t *'
// rgquidInterfaces : GUID* optional -> 'void *'
// cguidInterfaceCount : DWORD -> 'uint32_t'
// mszCards : LPSTR optional, out -> 'char *'
// pcchCards : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WinSCard.dll", {
SCardListCardsA: { parameters: ["usize", "pointer", "pointer", "u32", "buffer", "pointer"], result: "i32" },
});
// lib.symbols.SCardListCardsA(hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards)
// hContext : UINT_PTR -> "usize"
// pbAtr : BYTE* optional -> "pointer"
// rgquidInterfaces : GUID* optional -> "pointer"
// cguidInterfaceCount : DWORD -> "u32"
// mszCards : LPSTR optional, out -> "buffer"
// pcchCards : DWORD* in/out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SCardListCardsA(
size_t hContext,
uint8_t* pbAtr,
void* rgquidInterfaces,
uint32_t cguidInterfaceCount,
char* mszCards,
uint32_t* pcchCards);
C, "WinSCard.dll");
// $ffi->SCardListCardsA(hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards);
// hContext : UINT_PTR
// pbAtr : BYTE* optional
// rgquidInterfaces : GUID* optional
// cguidInterfaceCount : DWORD
// mszCards : LPSTR optional, out
// pcchCards : DWORD* in/out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Winscard extends StdCallLibrary {
Winscard INSTANCE = Native.load("winscard", Winscard.class, W32APIOptions.ASCII_OPTIONS);
int SCardListCardsA(
long hContext, // UINT_PTR
byte[] pbAtr, // BYTE* optional
Pointer rgquidInterfaces, // GUID* optional
int cguidInterfaceCount, // DWORD
byte[] mszCards, // LPSTR optional, out
IntByReference pcchCards // DWORD* in/out
);
}@[Link("winscard")]
lib LibWinSCard
fun SCardListCardsA = SCardListCardsA(
hContext : LibC::SizeT, # UINT_PTR
pbAtr : UInt8*, # BYTE* optional
rgquidInterfaces : GUID*, # GUID* optional
cguidInterfaceCount : UInt32, # DWORD
mszCards : UInt8*, # LPSTR optional, out
pcchCards : UInt32* # DWORD* in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SCardListCardsANative = Int32 Function(UintPtr, Pointer<Uint8>, Pointer<Void>, Uint32, Pointer<Utf8>, Pointer<Uint32>);
typedef SCardListCardsADart = int Function(int, Pointer<Uint8>, Pointer<Void>, int, Pointer<Utf8>, Pointer<Uint32>);
final SCardListCardsA = DynamicLibrary.open('WinSCard.dll')
.lookupFunction<SCardListCardsANative, SCardListCardsADart>('SCardListCardsA');
// hContext : UINT_PTR -> UintPtr
// pbAtr : BYTE* optional -> Pointer<Uint8>
// rgquidInterfaces : GUID* optional -> Pointer<Void>
// cguidInterfaceCount : DWORD -> Uint32
// mszCards : LPSTR optional, out -> Pointer<Utf8>
// pcchCards : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SCardListCardsA(
hContext: NativeUInt; // UINT_PTR
pbAtr: Pointer; // BYTE* optional
rgquidInterfaces: PGUID; // GUID* optional
cguidInterfaceCount: DWORD; // DWORD
mszCards: PAnsiChar; // LPSTR optional, out
pcchCards: Pointer // DWORD* in/out
): Integer; stdcall;
external 'WinSCard.dll' name 'SCardListCardsA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SCardListCardsA"
c_SCardListCardsA :: CUIntPtr -> Ptr Word8 -> Ptr () -> Word32 -> CString -> Ptr Word32 -> IO Int32
-- hContext : UINT_PTR -> CUIntPtr
-- pbAtr : BYTE* optional -> Ptr Word8
-- rgquidInterfaces : GUID* optional -> Ptr ()
-- cguidInterfaceCount : DWORD -> Word32
-- mszCards : LPSTR optional, out -> CString
-- pcchCards : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let scardlistcardsa =
foreign "SCardListCardsA"
(size_t @-> (ptr uint8_t) @-> (ptr void) @-> uint32_t @-> string @-> (ptr uint32_t) @-> returning int32_t)
(* hContext : UINT_PTR -> size_t *)
(* pbAtr : BYTE* optional -> (ptr uint8_t) *)
(* rgquidInterfaces : GUID* optional -> (ptr void) *)
(* cguidInterfaceCount : DWORD -> uint32_t *)
(* mszCards : LPSTR optional, out -> string *)
(* pcchCards : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library winscard (t "WinSCard.dll"))
(cffi:use-foreign-library winscard)
(cffi:defcfun ("SCardListCardsA" scard-list-cards-a :convention :stdcall) :int32
(h-context :uint64) ; UINT_PTR
(pb-atr :pointer) ; BYTE* optional
(rgquid-interfaces :pointer) ; GUID* optional
(cguid-interface-count :uint32) ; DWORD
(msz-cards :pointer) ; LPSTR optional, out
(pcch-cards :pointer)) ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SCardListCardsA = Win32::API::More->new('WinSCard',
'int SCardListCardsA(WPARAM hContext, LPVOID pbAtr, LPVOID rgquidInterfaces, DWORD cguidInterfaceCount, LPSTR mszCards, LPVOID pcchCards)');
# my $ret = $SCardListCardsA->Call($hContext, $pbAtr, $rgquidInterfaces, $cguidInterfaceCount, $mszCards, $pcchCards);
# hContext : UINT_PTR -> WPARAM
# pbAtr : BYTE* optional -> LPVOID
# rgquidInterfaces : GUID* optional -> LPVOID
# cguidInterfaceCount : DWORD -> DWORD
# mszCards : LPSTR optional, out -> LPSTR
# pcchCards : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f SCardListCardsW (Unicode版) — ATRやインターフェイスに一致するカード名を列挙する。
- f SCardEstablishContext — スマートカードリソースマネージャーへの接続コンテキストを確立する。
- f SCardFreeMemory — スマートカードAPIが割り当てたメモリを解放する。
- f SCardGetProviderIdA — 指定カードのプライマリプロバイダーのGUIDを取得する。
- f SCardListInterfacesA — 指定カードがサポートするインターフェイスを列挙する。
- f SCardListReaderGroupsA — システムに定義されたリーダーグループを列挙する。
- f SCardListReadersA — 指定グループに属するスマートカードリーダーを列挙する。