Win32 API 日本語リファレンス
ホームSecurity.Credentials › SCardListInterfacesA

SCardListInterfacesA

関数
指定カードがサポートするインターフェイスを列挙する。
DLLWinSCard.dll文字セットANSI (-A)呼出規約winapi対応OSWindows XP 以降

シグネチャ

// WinSCard.dll  (ANSI / -A)
#include <windows.h>

INT SCardListInterfacesA(
    UINT_PTR hContext,
    LPCSTR szCard,
    GUID* pguidInterfaces,
    DWORD* pcguidInterfaces
);

パラメーター

名前方向説明
hContextUINT_PTRinクエリ対象のリソースマネージャーコンテキストを識別するハンドルです。リソースマネージャーコンテキストは、事前に SCardEstablishContext を呼び出して設定できます。このパラメーターを NULL にすることはできません。
szCardLPCSTRinスマートカードサブシステムに既に登録されているスマートカードの名前です。
pguidInterfacesGUID*outスマートカードがサポートするインターフェイスを示すインターフェイス識別子 (GUID) の配列です。この値が NULL の場合、SCardListInterfacespcguidInterfaces で指定された配列長を無視し、このパラメーターが NULL でなかった場合に返されたであろう配列のサイズを pcguidInterfaces に返し、成功コードを返します。
pcguidInterfacesDWORD*inoutpcguidInterfaces 配列のサイズであり、返される配列の実際のサイズを受け取ります。配列サイズに SCARD_AUTOALLOCATE を指定した場合、pcguidInterfaces は GUID ポインターへのポインターに変換され、配列を格納したメモリブロックのアドレスを受け取ります。このメモリブロックは SCardFreeMemory で解放する必要があります。

戻り値の型: INT

公式ドキュメント

指定したカードが提供するインターフェイスの一覧を返します。(ANSI)

戻り値

この関数は、成功するか失敗するかに応じて異なる値を返します。

戻り値コード 説明
成功
SCARD_S_SUCCESS。
失敗
エラーコード。詳細については、 Smart Card Return Values を参照してください。

解説(Remarks)

この関数はリダイレクトされませんが、リモートデスクトップセッションで呼び出してもエラーにはなりません。ただし、その結果はローカルコンピューターではなくリモートコンピューターから返される点に注意してください。

SCardListInterfaces 関数はデータベースクエリ関数です。その他のデータベースクエリ関数の詳細については、 Smart Card Database Query Functions を参照してください。

次の例は、スマートカードのインターフェイスを一覧表示する方法を示しています。

LPGUID          pGuids = NULL;
LONG            lReturn;
DWORD           cGuid = SCARD_AUTOALLOCATE;

// Retrieve the list of interfaces.
lReturn = SCardListInterfaces(NULL,
                              (LPCSTR) "MyCard",
                              (LPGUID)&pGuids,
                              &cGuid );
if ( SCARD_S_SUCCESS != lReturn )
{
    printf("Failed SCardListInterfaces\n");
    exit(1);   // Or other appropriate action
}

if ( 0 != cGuid )
{
    // Do something with the array of Guids.
    // Remember to free pGuids when done (by SCardFreeMemory).
    // ...
}
メモ

winscard.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして SCardListInterfaces を定義します。エンコーディング非依存のエイリアスを、エンコーディング非依存でないコードと混在させると、不一致が生じ、コンパイルエラーや実行時エラーの原因となることがあります。詳細については、Conventions for Function Prototypes を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// WinSCard.dll  (ANSI / -A)
#include <windows.h>

INT SCardListInterfacesA(
    UINT_PTR hContext,
    LPCSTR szCard,
    GUID* pguidInterfaces,
    DWORD* pcguidInterfaces
);
[DllImport("WinSCard.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern int SCardListInterfacesA(
    UIntPtr hContext,   // UINT_PTR
    [MarshalAs(UnmanagedType.LPStr)] string szCard,   // LPCSTR
    out Guid pguidInterfaces,   // GUID* out
    ref uint pcguidInterfaces   // DWORD* in/out
);
<DllImport("WinSCard.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SCardListInterfacesA(
    hContext As UIntPtr,   ' UINT_PTR
    <MarshalAs(UnmanagedType.LPStr)> szCard As String,   ' LPCSTR
    <Out> ByRef pguidInterfaces As Guid,   ' GUID* out
    ByRef pcguidInterfaces As UInteger   ' DWORD* in/out
) As Integer
End Function
' hContext : UINT_PTR
' szCard : LPCSTR
' pguidInterfaces : GUID* out
' pcguidInterfaces : DWORD* in/out
Declare PtrSafe Function SCardListInterfacesA Lib "winscard" ( _
    ByVal hContext As LongPtr, _
    ByVal szCard As String, _
    ByVal pguidInterfaces As LongPtr, _
    ByRef pcguidInterfaces As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SCardListInterfacesA = ctypes.windll.winscard.SCardListInterfacesA
SCardListInterfacesA.restype = ctypes.c_int
SCardListInterfacesA.argtypes = [
    ctypes.c_size_t,  # hContext : UINT_PTR
    wintypes.LPCSTR,  # szCard : LPCSTR
    ctypes.c_void_p,  # pguidInterfaces : GUID* out
    ctypes.POINTER(wintypes.DWORD),  # pcguidInterfaces : DWORD* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WinSCard.dll')
SCardListInterfacesA = Fiddle::Function.new(
  lib['SCardListInterfacesA'],
  [
    Fiddle::TYPE_UINTPTR_T,  # hContext : UINT_PTR
    Fiddle::TYPE_VOIDP,  # szCard : LPCSTR
    Fiddle::TYPE_VOIDP,  # pguidInterfaces : GUID* out
    Fiddle::TYPE_VOIDP,  # pcguidInterfaces : DWORD* in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "winscard")]
extern "system" {
    fn SCardListInterfacesA(
        hContext: usize,  // UINT_PTR
        szCard: *const u8,  // LPCSTR
        pguidInterfaces: *mut GUID,  // GUID* out
        pcguidInterfaces: *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 SCardListInterfacesA(UIntPtr hContext, [MarshalAs(UnmanagedType.LPStr)] string szCard, out Guid pguidInterfaces, ref uint pcguidInterfaces);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WinSCard_SCardListInterfacesA' -Namespace Win32 -PassThru
# $api::SCardListInterfacesA(hContext, szCard, pguidInterfaces, pcguidInterfaces)
#uselib "WinSCard.dll"
#func global SCardListInterfacesA "SCardListInterfacesA" sptr, sptr, sptr, sptr
; SCardListInterfacesA hContext, szCard, varptr(pguidInterfaces), varptr(pcguidInterfaces)   ; 戻り値は stat
; hContext : UINT_PTR -> "sptr"
; szCard : LPCSTR -> "sptr"
; pguidInterfaces : GUID* out -> "sptr"
; pcguidInterfaces : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WinSCard.dll"
#cfunc global SCardListInterfacesA "SCardListInterfacesA" sptr, str, var, var
; res = SCardListInterfacesA(hContext, szCard, pguidInterfaces, pcguidInterfaces)
; hContext : UINT_PTR -> "sptr"
; szCard : LPCSTR -> "str"
; pguidInterfaces : GUID* out -> "var"
; pcguidInterfaces : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT SCardListInterfacesA(UINT_PTR hContext, LPCSTR szCard, GUID* pguidInterfaces, DWORD* pcguidInterfaces)
#uselib "WinSCard.dll"
#cfunc global SCardListInterfacesA "SCardListInterfacesA" intptr, str, var, var
; res = SCardListInterfacesA(hContext, szCard, pguidInterfaces, pcguidInterfaces)
; hContext : UINT_PTR -> "intptr"
; szCard : LPCSTR -> "str"
; pguidInterfaces : GUID* out -> "var"
; pcguidInterfaces : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winscard = windows.NewLazySystemDLL("WinSCard.dll")
	procSCardListInterfacesA = winscard.NewProc("SCardListInterfacesA")
)

// hContext (UINT_PTR), szCard (LPCSTR), pguidInterfaces (GUID* out), pcguidInterfaces (DWORD* in/out)
r1, _, err := procSCardListInterfacesA.Call(
	uintptr(hContext),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(szCard))),
	uintptr(pguidInterfaces),
	uintptr(pcguidInterfaces),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function SCardListInterfacesA(
  hContext: NativeUInt;   // UINT_PTR
  szCard: PAnsiChar;   // LPCSTR
  pguidInterfaces: PGUID;   // GUID* out
  pcguidInterfaces: Pointer   // DWORD* in/out
): Integer; stdcall;
  external 'WinSCard.dll' name 'SCardListInterfacesA';
result := DllCall("WinSCard\SCardListInterfacesA"
    , "UPtr", hContext   ; UINT_PTR
    , "AStr", szCard   ; LPCSTR
    , "Ptr", pguidInterfaces   ; GUID* out
    , "Ptr", pcguidInterfaces   ; DWORD* in/out
    , "Int")   ; return: INT
●SCardListInterfacesA(hContext, szCard, pguidInterfaces, pcguidInterfaces) = DLL("WinSCard.dll", "int SCardListInterfacesA(int, char*, void*, void*)")
# 呼び出し: SCardListInterfacesA(hContext, szCard, pguidInterfaces, pcguidInterfaces)
# hContext : UINT_PTR -> "int"
# szCard : LPCSTR -> "char*"
# pguidInterfaces : GUID* out -> "void*"
# pcguidInterfaces : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "winscard" fn SCardListInterfacesA(
    hContext: usize, // UINT_PTR
    szCard: [*c]const u8, // LPCSTR
    pguidInterfaces: [*c]GUID, // GUID* out
    pcguidInterfaces: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;
proc SCardListInterfacesA(
    hContext: uint,  # UINT_PTR
    szCard: cstring,  # LPCSTR
    pguidInterfaces: ptr GUID,  # GUID* out
    pcguidInterfaces: ptr uint32  # DWORD* in/out
): int32 {.importc: "SCardListInterfacesA", stdcall, dynlib: "WinSCard.dll".}
pragma(lib, "winscard");
extern(Windows)
int SCardListInterfacesA(
    size_t hContext,   // UINT_PTR
    const(char)* szCard,   // LPCSTR
    GUID* pguidInterfaces,   // GUID* out
    uint* pcguidInterfaces   // DWORD* in/out
);
ccall((:SCardListInterfacesA, "WinSCard.dll"), stdcall, Int32,
      (Csize_t, Cstring, Ptr{GUID}, Ptr{UInt32}),
      hContext, szCard, pguidInterfaces, pcguidInterfaces)
# hContext : UINT_PTR -> Csize_t
# szCard : LPCSTR -> Cstring
# pguidInterfaces : GUID* out -> Ptr{GUID}
# pcguidInterfaces : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SCardListInterfacesA(
    uintptr_t hContext,
    const char* szCard,
    void* pguidInterfaces,
    uint32_t* pcguidInterfaces);
]]
local winscard = ffi.load("winscard")
-- winscard.SCardListInterfacesA(hContext, szCard, pguidInterfaces, pcguidInterfaces)
-- hContext : UINT_PTR
-- szCard : LPCSTR
-- pguidInterfaces : GUID* out
-- pcguidInterfaces : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('WinSCard.dll');
const SCardListInterfacesA = lib.func('__stdcall', 'SCardListInterfacesA', 'int32_t', ['uintptr_t', 'str', 'void *', 'uint32_t *']);
// SCardListInterfacesA(hContext, szCard, pguidInterfaces, pcguidInterfaces)
// hContext : UINT_PTR -> 'uintptr_t'
// szCard : LPCSTR -> 'str'
// pguidInterfaces : GUID* out -> 'void *'
// pcguidInterfaces : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WinSCard.dll", {
  SCardListInterfacesA: { parameters: ["usize", "buffer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.SCardListInterfacesA(hContext, szCard, pguidInterfaces, pcguidInterfaces)
// hContext : UINT_PTR -> "usize"
// szCard : LPCSTR -> "buffer"
// pguidInterfaces : GUID* out -> "pointer"
// pcguidInterfaces : DWORD* in/out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SCardListInterfacesA(
    size_t hContext,
    const char* szCard,
    void* pguidInterfaces,
    uint32_t* pcguidInterfaces);
C, "WinSCard.dll");
// $ffi->SCardListInterfacesA(hContext, szCard, pguidInterfaces, pcguidInterfaces);
// hContext : UINT_PTR
// szCard : LPCSTR
// pguidInterfaces : GUID* out
// pcguidInterfaces : 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 SCardListInterfacesA(
        long hContext,   // UINT_PTR
        String szCard,   // LPCSTR
        Pointer pguidInterfaces,   // GUID* out
        IntByReference pcguidInterfaces   // DWORD* in/out
    );
}
@[Link("winscard")]
lib LibWinSCard
  fun SCardListInterfacesA = SCardListInterfacesA(
    hContext : LibC::SizeT,   # UINT_PTR
    szCard : UInt8*,   # LPCSTR
    pguidInterfaces : GUID*,   # GUID* out
    pcguidInterfaces : 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 SCardListInterfacesANative = Int32 Function(UintPtr, Pointer<Utf8>, Pointer<Void>, Pointer<Uint32>);
typedef SCardListInterfacesADart = int Function(int, Pointer<Utf8>, Pointer<Void>, Pointer<Uint32>);
final SCardListInterfacesA = DynamicLibrary.open('WinSCard.dll')
    .lookupFunction<SCardListInterfacesANative, SCardListInterfacesADart>('SCardListInterfacesA');
// hContext : UINT_PTR -> UintPtr
// szCard : LPCSTR -> Pointer<Utf8>
// pguidInterfaces : GUID* out -> Pointer<Void>
// pcguidInterfaces : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SCardListInterfacesA(
  hContext: NativeUInt;   // UINT_PTR
  szCard: PAnsiChar;   // LPCSTR
  pguidInterfaces: PGUID;   // GUID* out
  pcguidInterfaces: Pointer   // DWORD* in/out
): Integer; stdcall;
  external 'WinSCard.dll' name 'SCardListInterfacesA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SCardListInterfacesA"
  c_SCardListInterfacesA :: CUIntPtr -> CString -> Ptr () -> Ptr Word32 -> IO Int32
-- hContext : UINT_PTR -> CUIntPtr
-- szCard : LPCSTR -> CString
-- pguidInterfaces : GUID* out -> Ptr ()
-- pcguidInterfaces : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let scardlistinterfacesa =
  foreign "SCardListInterfacesA"
    (size_t @-> string @-> (ptr void) @-> (ptr uint32_t) @-> returning int32_t)
(* hContext : UINT_PTR -> size_t *)
(* szCard : LPCSTR -> string *)
(* pguidInterfaces : GUID* out -> (ptr void) *)
(* pcguidInterfaces : 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 ("SCardListInterfacesA" scard-list-interfaces-a :convention :stdcall) :int32
  (h-context :uint64)   ; UINT_PTR
  (sz-card :string)   ; LPCSTR
  (pguid-interfaces :pointer)   ; GUID* out
  (pcguid-interfaces :pointer))   ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SCardListInterfacesA = Win32::API::More->new('WinSCard',
    'int SCardListInterfacesA(WPARAM hContext, LPCSTR szCard, LPVOID pguidInterfaces, LPVOID pcguidInterfaces)');
# my $ret = $SCardListInterfacesA->Call($hContext, $szCard, $pguidInterfaces, $pcguidInterfaces);
# hContext : UINT_PTR -> WPARAM
# szCard : LPCSTR -> LPCSTR
# pguidInterfaces : GUID* out -> LPVOID
# pcguidInterfaces : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
公式の関連項目