SCardListCardsW
関数シグネチャ
// WinSCard.dll (Unicode / -W)
#include <windows.h>
INT SCardListCardsW(
UINT_PTR hContext,
BYTE* pbAtr, // optional
const GUID* rgquidInterfaces, // optional
DWORD cguidInterfaceCount,
LPWSTR 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 | LPWSTR | outoptional | 見つかったスマートカードを列挙するマルチ文字列です。この値が NULL の場合、SCardListCards は pcchCards で指定されたバッファー長を無視し、このパラメーターが NULL でなかった場合に返されたであろうバッファーの長さを pcchCards に返し、成功コードを返します。 |
| pcchCards | DWORD* | inout | mszCards バッファーの長さ(文字数)です。末尾のすべての null 文字を含む、マルチ文字列構造の実際の長さを受け取ります。バッファー長として SCARD_AUTOALLOCATE が指定された場合、mszCards はバイトポインターへのポインターに変換され、マルチ文字列構造を含むメモリブロックのアドレスを受け取ります。このメモリブロックは SCardFreeMemory で解放する必要があります。 |
戻り値の型: INT
公式ドキュメント
スマートカードデータベースを検索し、ユーザーによって以前にシステムに登録された名前付きカードの一覧を提供します。(Unicode)
戻り値
この関数は、成功したか失敗したかに応じて異なる値を返します。
| 戻り値 | 説明 |
|---|---|
|
SCARD_S_SUCCESS。 |
|
エラーコード。詳細については、 Smart Card Return Values を参照してください。 |
解説(Remarks)
この関数はリダイレクトされませんが、リモートデスクトップセッション内でこの関数を呼び出してもエラーにはなりません。その場合、結果はローカルコンピューターではなくリモートコンピューターのものになるだけです。
サブシステムに登録されたすべてのスマートカードを返すには、pbAtr と rgguidInterfaces を NULL に設定します。
SCardListCards 関数はデータベースクエリ関数です。その他のデータベースクエリ関数の詳細については、 Smart Card Database Query Functions を参照してください。
この関数の呼び出しはトランザクションの外で行う必要があります。アプリケーションが 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 ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして SCardListCards を定義します。エンコーディング非依存のエイリアスの使用と、エンコーディング非依存ではないコードを混在させると、コンパイルエラーや実行時エラーを引き起こす不整合につながる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// WinSCard.dll (Unicode / -W)
#include <windows.h>
INT SCardListCardsW(
UINT_PTR hContext,
BYTE* pbAtr, // optional
const GUID* rgquidInterfaces, // optional
DWORD cguidInterfaceCount,
LPWSTR mszCards, // optional
DWORD* pcchCards
);[DllImport("WinSCard.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int SCardListCardsW(
UIntPtr hContext, // UINT_PTR
IntPtr pbAtr, // BYTE* optional
IntPtr rgquidInterfaces, // GUID* optional
uint cguidInterfaceCount, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder mszCards, // LPWSTR optional, out
ref uint pcchCards // DWORD* in/out
);<DllImport("WinSCard.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SCardListCardsW(
hContext As UIntPtr, ' UINT_PTR
pbAtr As IntPtr, ' BYTE* optional
rgquidInterfaces As IntPtr, ' GUID* optional
cguidInterfaceCount As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> mszCards As System.Text.StringBuilder, ' LPWSTR 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 : LPWSTR optional, out
' pcchCards : DWORD* in/out
Declare PtrSafe Function SCardListCardsW Lib "winscard" ( _
ByVal hContext As LongPtr, _
ByVal pbAtr As LongPtr, _
ByVal rgquidInterfaces As LongPtr, _
ByVal cguidInterfaceCount As Long, _
ByVal mszCards As LongPtr, _
ByRef pcchCards As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SCardListCardsW = ctypes.windll.winscard.SCardListCardsW
SCardListCardsW.restype = ctypes.c_int
SCardListCardsW.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.LPWSTR, # mszCards : LPWSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcchCards : DWORD* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WinSCard.dll')
SCardListCardsW = Fiddle::Function.new(
lib['SCardListCardsW'],
[
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 : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # pcchCards : DWORD* in/out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "winscard")]
extern "system" {
fn SCardListCardsW(
hContext: usize, // UINT_PTR
pbAtr: *mut u8, // BYTE* optional
rgquidInterfaces: *const GUID, // GUID* optional
cguidInterfaceCount: u32, // DWORD
mszCards: *mut u16, // LPWSTR 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.Unicode)]
public static extern int SCardListCardsW(UIntPtr hContext, IntPtr pbAtr, IntPtr rgquidInterfaces, uint cguidInterfaceCount, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder mszCards, ref uint pcchCards);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WinSCard_SCardListCardsW' -Namespace Win32 -PassThru
# $api::SCardListCardsW(hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards)#uselib "WinSCard.dll"
#func global SCardListCardsW "SCardListCardsW" wptr, wptr, wptr, wptr, wptr, wptr
; SCardListCardsW hContext, varptr(pbAtr), varptr(rgquidInterfaces), cguidInterfaceCount, varptr(mszCards), varptr(pcchCards) ; 戻り値は stat
; hContext : UINT_PTR -> "wptr"
; pbAtr : BYTE* optional -> "wptr"
; rgquidInterfaces : GUID* optional -> "wptr"
; cguidInterfaceCount : DWORD -> "wptr"
; mszCards : LPWSTR optional, out -> "wptr"
; pcchCards : DWORD* in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WinSCard.dll" #cfunc global SCardListCardsW "SCardListCardsW" sptr, var, var, int, var, var ; res = SCardListCardsW(hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards) ; hContext : UINT_PTR -> "sptr" ; pbAtr : BYTE* optional -> "var" ; rgquidInterfaces : GUID* optional -> "var" ; cguidInterfaceCount : DWORD -> "int" ; mszCards : LPWSTR optional, out -> "var" ; pcchCards : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WinSCard.dll" #cfunc global SCardListCardsW "SCardListCardsW" sptr, sptr, sptr, int, sptr, sptr ; res = SCardListCardsW(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 : LPWSTR optional, out -> "sptr" ; pcchCards : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; INT SCardListCardsW(UINT_PTR hContext, BYTE* pbAtr, GUID* rgquidInterfaces, DWORD cguidInterfaceCount, LPWSTR mszCards, DWORD* pcchCards) #uselib "WinSCard.dll" #cfunc global SCardListCardsW "SCardListCardsW" intptr, var, var, int, var, var ; res = SCardListCardsW(hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards) ; hContext : UINT_PTR -> "intptr" ; pbAtr : BYTE* optional -> "var" ; rgquidInterfaces : GUID* optional -> "var" ; cguidInterfaceCount : DWORD -> "int" ; mszCards : LPWSTR optional, out -> "var" ; pcchCards : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT SCardListCardsW(UINT_PTR hContext, BYTE* pbAtr, GUID* rgquidInterfaces, DWORD cguidInterfaceCount, LPWSTR mszCards, DWORD* pcchCards) #uselib "WinSCard.dll" #cfunc global SCardListCardsW "SCardListCardsW" intptr, intptr, intptr, int, intptr, intptr ; res = SCardListCardsW(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 : LPWSTR optional, out -> "intptr" ; pcchCards : DWORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
winscard = windows.NewLazySystemDLL("WinSCard.dll")
procSCardListCardsW = winscard.NewProc("SCardListCardsW")
)
// hContext (UINT_PTR), pbAtr (BYTE* optional), rgquidInterfaces (GUID* optional), cguidInterfaceCount (DWORD), mszCards (LPWSTR optional, out), pcchCards (DWORD* in/out)
r1, _, err := procSCardListCardsW.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 SCardListCardsW(
hContext: NativeUInt; // UINT_PTR
pbAtr: Pointer; // BYTE* optional
rgquidInterfaces: PGUID; // GUID* optional
cguidInterfaceCount: DWORD; // DWORD
mszCards: PWideChar; // LPWSTR optional, out
pcchCards: Pointer // DWORD* in/out
): Integer; stdcall;
external 'WinSCard.dll' name 'SCardListCardsW';result := DllCall("WinSCard\SCardListCardsW"
, "UPtr", hContext ; UINT_PTR
, "Ptr", pbAtr ; BYTE* optional
, "Ptr", rgquidInterfaces ; GUID* optional
, "UInt", cguidInterfaceCount ; DWORD
, "Ptr", mszCards ; LPWSTR optional, out
, "Ptr", pcchCards ; DWORD* in/out
, "Int") ; return: INT●SCardListCardsW(hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards) = DLL("WinSCard.dll", "int SCardListCardsW(int, void*, void*, dword, char*, void*)")
# 呼び出し: SCardListCardsW(hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards)
# hContext : UINT_PTR -> "int"
# pbAtr : BYTE* optional -> "void*"
# rgquidInterfaces : GUID* optional -> "void*"
# cguidInterfaceCount : DWORD -> "dword"
# mszCards : LPWSTR optional, out -> "char*"
# pcchCards : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "winscard" fn SCardListCardsW(
hContext: usize, // UINT_PTR
pbAtr: [*c]u8, // BYTE* optional
rgquidInterfaces: [*c]GUID, // GUID* optional
cguidInterfaceCount: u32, // DWORD
mszCards: [*c]u16, // LPWSTR optional, out
pcchCards: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SCardListCardsW(
hContext: uint, # UINT_PTR
pbAtr: ptr uint8, # BYTE* optional
rgquidInterfaces: ptr GUID, # GUID* optional
cguidInterfaceCount: uint32, # DWORD
mszCards: ptr uint16, # LPWSTR optional, out
pcchCards: ptr uint32 # DWORD* in/out
): int32 {.importc: "SCardListCardsW", stdcall, dynlib: "WinSCard.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "winscard");
extern(Windows)
int SCardListCardsW(
size_t hContext, // UINT_PTR
ubyte* pbAtr, // BYTE* optional
GUID* rgquidInterfaces, // GUID* optional
uint cguidInterfaceCount, // DWORD
wchar* mszCards, // LPWSTR optional, out
uint* pcchCards // DWORD* in/out
);ccall((:SCardListCardsW, "WinSCard.dll"), stdcall, Int32,
(Csize_t, Ptr{UInt8}, Ptr{GUID}, UInt32, Ptr{UInt16}, 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 : LPWSTR optional, out -> Ptr{UInt16}
# pcchCards : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t SCardListCardsW(
uintptr_t hContext,
uint8_t* pbAtr,
void* rgquidInterfaces,
uint32_t cguidInterfaceCount,
uint16_t* mszCards,
uint32_t* pcchCards);
]]
local winscard = ffi.load("winscard")
-- winscard.SCardListCardsW(hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards)
-- hContext : UINT_PTR
-- pbAtr : BYTE* optional
-- rgquidInterfaces : GUID* optional
-- cguidInterfaceCount : DWORD
-- mszCards : LPWSTR optional, out
-- pcchCards : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('WinSCard.dll');
const SCardListCardsW = lib.func('__stdcall', 'SCardListCardsW', 'int32_t', ['uintptr_t', 'uint8_t *', 'void *', 'uint32_t', 'uint16_t *', 'uint32_t *']);
// SCardListCardsW(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 : LPWSTR optional, out -> 'uint16_t *'
// pcchCards : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WinSCard.dll", {
SCardListCardsW: { parameters: ["usize", "pointer", "pointer", "u32", "buffer", "pointer"], result: "i32" },
});
// lib.symbols.SCardListCardsW(hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards)
// hContext : UINT_PTR -> "usize"
// pbAtr : BYTE* optional -> "pointer"
// rgquidInterfaces : GUID* optional -> "pointer"
// cguidInterfaceCount : DWORD -> "u32"
// mszCards : LPWSTR optional, out -> "buffer"
// pcchCards : DWORD* in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SCardListCardsW(
size_t hContext,
uint8_t* pbAtr,
void* rgquidInterfaces,
uint32_t cguidInterfaceCount,
uint16_t* mszCards,
uint32_t* pcchCards);
C, "WinSCard.dll");
// $ffi->SCardListCardsW(hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount, mszCards, pcchCards);
// hContext : UINT_PTR
// pbAtr : BYTE* optional
// rgquidInterfaces : GUID* optional
// cguidInterfaceCount : DWORD
// mszCards : LPWSTR 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.UNICODE_OPTIONS);
int SCardListCardsW(
long hContext, // UINT_PTR
byte[] pbAtr, // BYTE* optional
Pointer rgquidInterfaces, // GUID* optional
int cguidInterfaceCount, // DWORD
char[] mszCards, // LPWSTR optional, out
IntByReference pcchCards // DWORD* in/out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("winscard")]
lib LibWinSCard
fun SCardListCardsW = SCardListCardsW(
hContext : LibC::SizeT, # UINT_PTR
pbAtr : UInt8*, # BYTE* optional
rgquidInterfaces : GUID*, # GUID* optional
cguidInterfaceCount : UInt32, # DWORD
mszCards : UInt16*, # LPWSTR 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 SCardListCardsWNative = Int32 Function(UintPtr, Pointer<Uint8>, Pointer<Void>, Uint32, Pointer<Utf16>, Pointer<Uint32>);
typedef SCardListCardsWDart = int Function(int, Pointer<Uint8>, Pointer<Void>, int, Pointer<Utf16>, Pointer<Uint32>);
final SCardListCardsW = DynamicLibrary.open('WinSCard.dll')
.lookupFunction<SCardListCardsWNative, SCardListCardsWDart>('SCardListCardsW');
// hContext : UINT_PTR -> UintPtr
// pbAtr : BYTE* optional -> Pointer<Uint8>
// rgquidInterfaces : GUID* optional -> Pointer<Void>
// cguidInterfaceCount : DWORD -> Uint32
// mszCards : LPWSTR optional, out -> Pointer<Utf16>
// pcchCards : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SCardListCardsW(
hContext: NativeUInt; // UINT_PTR
pbAtr: Pointer; // BYTE* optional
rgquidInterfaces: PGUID; // GUID* optional
cguidInterfaceCount: DWORD; // DWORD
mszCards: PWideChar; // LPWSTR optional, out
pcchCards: Pointer // DWORD* in/out
): Integer; stdcall;
external 'WinSCard.dll' name 'SCardListCardsW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SCardListCardsW"
c_SCardListCardsW :: CUIntPtr -> Ptr Word8 -> Ptr () -> Word32 -> CWString -> Ptr Word32 -> IO Int32
-- hContext : UINT_PTR -> CUIntPtr
-- pbAtr : BYTE* optional -> Ptr Word8
-- rgquidInterfaces : GUID* optional -> Ptr ()
-- cguidInterfaceCount : DWORD -> Word32
-- mszCards : LPWSTR optional, out -> CWString
-- pcchCards : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let scardlistcardsw =
foreign "SCardListCardsW"
(size_t @-> (ptr uint8_t) @-> (ptr void) @-> uint32_t @-> (ptr uint16_t) @-> (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 : LPWSTR optional, out -> (ptr uint16_t) *)
(* 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 ("SCardListCardsW" scard-list-cards-w :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) ; LPWSTR optional, out
(pcch-cards :pointer)) ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SCardListCardsW = Win32::API::More->new('WinSCard',
'int SCardListCardsW(WPARAM hContext, LPVOID pbAtr, LPVOID rgquidInterfaces, DWORD cguidInterfaceCount, LPWSTR mszCards, LPVOID pcchCards)');
# my $ret = $SCardListCardsW->Call($hContext, $pbAtr, $rgquidInterfaces, $cguidInterfaceCount, $mszCards, $pcchCards);
# hContext : UINT_PTR -> WPARAM
# pbAtr : BYTE* optional -> LPVOID
# rgquidInterfaces : GUID* optional -> LPVOID
# cguidInterfaceCount : DWORD -> DWORD
# mszCards : LPWSTR optional, out -> LPWSTR
# pcchCards : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f SCardListCardsA (ANSI版) — ATRやインターフェイスに一致するカード名を列挙する。
- f SCardEstablishContext — スマートカードリソースマネージャーへの接続コンテキストを確立する。
- f SCardFreeMemory — スマートカードAPIが割り当てたメモリを解放する。
- f SCardGetProviderIdW — 指定カードのプライマリプロバイダーのGUIDを取得する。
- f SCardListInterfacesW — 指定カードがサポートするインターフェイスを列挙する。
- f SCardListReaderGroupsW — システムに定義されたリーダーグループを列挙する。
- f SCardListReadersW — 指定グループに属するスマートカードリーダーを列挙する。