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

SCardListInterfacesW

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

シグネチャ

// WinSCard.dll  (Unicode / -W)
#include <windows.h>

INT SCardListInterfacesW(
    UINT_PTR hContext,
    LPCWSTR szCard,
    GUID* pguidInterfaces,
    DWORD* pcguidInterfaces
);

パラメーター

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

戻り値の型: INT

公式ドキュメント

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

戻り値

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

戻り値 説明
成功
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 ヘッダーは、SCardListInterfaces を UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義しています。エンコーディング中立なエイリアスの使用と、エンコーディング中立でないコードを混在させると、コンパイルエラーまたは実行時エラーを引き起こす不整合が生じる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。

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

各言語での呼び出し定義

// WinSCard.dll  (Unicode / -W)
#include <windows.h>

INT SCardListInterfacesW(
    UINT_PTR hContext,
    LPCWSTR szCard,
    GUID* pguidInterfaces,
    DWORD* pcguidInterfaces
);
[DllImport("WinSCard.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int SCardListInterfacesW(
    UIntPtr hContext,   // UINT_PTR
    [MarshalAs(UnmanagedType.LPWStr)] string szCard,   // LPCWSTR
    out Guid pguidInterfaces,   // GUID* out
    ref uint pcguidInterfaces   // DWORD* in/out
);
<DllImport("WinSCard.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SCardListInterfacesW(
    hContext As UIntPtr,   ' UINT_PTR
    <MarshalAs(UnmanagedType.LPWStr)> szCard As String,   ' LPCWSTR
    <Out> ByRef pguidInterfaces As Guid,   ' GUID* out
    ByRef pcguidInterfaces As UInteger   ' DWORD* in/out
) As Integer
End Function
' hContext : UINT_PTR
' szCard : LPCWSTR
' pguidInterfaces : GUID* out
' pcguidInterfaces : DWORD* in/out
Declare PtrSafe Function SCardListInterfacesW Lib "winscard" ( _
    ByVal hContext As LongPtr, _
    ByVal szCard As LongPtr, _
    ByVal pguidInterfaces As LongPtr, _
    ByRef pcguidInterfaces 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

SCardListInterfacesW = ctypes.windll.winscard.SCardListInterfacesW
SCardListInterfacesW.restype = ctypes.c_int
SCardListInterfacesW.argtypes = [
    ctypes.c_size_t,  # hContext : UINT_PTR
    wintypes.LPCWSTR,  # szCard : LPCWSTR
    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')
SCardListInterfacesW = Fiddle::Function.new(
  lib['SCardListInterfacesW'],
  [
    Fiddle::TYPE_UINTPTR_T,  # hContext : UINT_PTR
    Fiddle::TYPE_VOIDP,  # szCard : LPCWSTR
    Fiddle::TYPE_VOIDP,  # pguidInterfaces : GUID* out
    Fiddle::TYPE_VOIDP,  # pcguidInterfaces : DWORD* in/out
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "winscard")]
extern "system" {
    fn SCardListInterfacesW(
        hContext: usize,  // UINT_PTR
        szCard: *const u16,  // LPCWSTR
        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.Unicode)]
public static extern int SCardListInterfacesW(UIntPtr hContext, [MarshalAs(UnmanagedType.LPWStr)] string szCard, out Guid pguidInterfaces, ref uint pcguidInterfaces);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WinSCard_SCardListInterfacesW' -Namespace Win32 -PassThru
# $api::SCardListInterfacesW(hContext, szCard, pguidInterfaces, pcguidInterfaces)
#uselib "WinSCard.dll"
#func global SCardListInterfacesW "SCardListInterfacesW" wptr, wptr, wptr, wptr
; SCardListInterfacesW hContext, szCard, varptr(pguidInterfaces), varptr(pcguidInterfaces)   ; 戻り値は stat
; hContext : UINT_PTR -> "wptr"
; szCard : LPCWSTR -> "wptr"
; pguidInterfaces : GUID* out -> "wptr"
; pcguidInterfaces : DWORD* in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WinSCard.dll"
#cfunc global SCardListInterfacesW "SCardListInterfacesW" sptr, wstr, var, var
; res = SCardListInterfacesW(hContext, szCard, pguidInterfaces, pcguidInterfaces)
; hContext : UINT_PTR -> "sptr"
; szCard : LPCWSTR -> "wstr"
; pguidInterfaces : GUID* out -> "var"
; pcguidInterfaces : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT SCardListInterfacesW(UINT_PTR hContext, LPCWSTR szCard, GUID* pguidInterfaces, DWORD* pcguidInterfaces)
#uselib "WinSCard.dll"
#cfunc global SCardListInterfacesW "SCardListInterfacesW" intptr, wstr, var, var
; res = SCardListInterfacesW(hContext, szCard, pguidInterfaces, pcguidInterfaces)
; hContext : UINT_PTR -> "intptr"
; szCard : LPCWSTR -> "wstr"
; pguidInterfaces : GUID* out -> "var"
; pcguidInterfaces : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winscard = windows.NewLazySystemDLL("WinSCard.dll")
	procSCardListInterfacesW = winscard.NewProc("SCardListInterfacesW")
)

// hContext (UINT_PTR), szCard (LPCWSTR), pguidInterfaces (GUID* out), pcguidInterfaces (DWORD* in/out)
r1, _, err := procSCardListInterfacesW.Call(
	uintptr(hContext),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szCard))),
	uintptr(pguidInterfaces),
	uintptr(pcguidInterfaces),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function SCardListInterfacesW(
  hContext: NativeUInt;   // UINT_PTR
  szCard: PWideChar;   // LPCWSTR
  pguidInterfaces: PGUID;   // GUID* out
  pcguidInterfaces: Pointer   // DWORD* in/out
): Integer; stdcall;
  external 'WinSCard.dll' name 'SCardListInterfacesW';
result := DllCall("WinSCard\SCardListInterfacesW"
    , "UPtr", hContext   ; UINT_PTR
    , "WStr", szCard   ; LPCWSTR
    , "Ptr", pguidInterfaces   ; GUID* out
    , "Ptr", pcguidInterfaces   ; DWORD* in/out
    , "Int")   ; return: INT
●SCardListInterfacesW(hContext, szCard, pguidInterfaces, pcguidInterfaces) = DLL("WinSCard.dll", "int SCardListInterfacesW(int, char*, void*, void*)")
# 呼び出し: SCardListInterfacesW(hContext, szCard, pguidInterfaces, pcguidInterfaces)
# hContext : UINT_PTR -> "int"
# szCard : LPCWSTR -> "char*"
# pguidInterfaces : GUID* out -> "void*"
# pcguidInterfaces : 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 SCardListInterfacesW(
    hContext: usize, // UINT_PTR
    szCard: [*c]const u16, // LPCWSTR
    pguidInterfaces: [*c]GUID, // GUID* out
    pcguidInterfaces: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc SCardListInterfacesW(
    hContext: uint,  # UINT_PTR
    szCard: WideCString,  # LPCWSTR
    pguidInterfaces: ptr GUID,  # GUID* out
    pcguidInterfaces: ptr uint32  # DWORD* in/out
): int32 {.importc: "SCardListInterfacesW", stdcall, dynlib: "WinSCard.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "winscard");
extern(Windows)
int SCardListInterfacesW(
    size_t hContext,   // UINT_PTR
    const(wchar)* szCard,   // LPCWSTR
    GUID* pguidInterfaces,   // GUID* out
    uint* pcguidInterfaces   // DWORD* in/out
);
ccall((:SCardListInterfacesW, "WinSCard.dll"), stdcall, Int32,
      (Csize_t, Cwstring, Ptr{GUID}, Ptr{UInt32}),
      hContext, szCard, pguidInterfaces, pcguidInterfaces)
# hContext : UINT_PTR -> Csize_t
# szCard : LPCWSTR -> Cwstring
# pguidInterfaces : GUID* out -> Ptr{GUID}
# pcguidInterfaces : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t SCardListInterfacesW(
    uintptr_t hContext,
    const uint16_t* szCard,
    void* pguidInterfaces,
    uint32_t* pcguidInterfaces);
]]
local winscard = ffi.load("winscard")
-- winscard.SCardListInterfacesW(hContext, szCard, pguidInterfaces, pcguidInterfaces)
-- hContext : UINT_PTR
-- szCard : LPCWSTR
-- pguidInterfaces : GUID* out
-- pcguidInterfaces : 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 SCardListInterfacesW = lib.func('__stdcall', 'SCardListInterfacesW', 'int32_t', ['uintptr_t', 'str16', 'void *', 'uint32_t *']);
// SCardListInterfacesW(hContext, szCard, pguidInterfaces, pcguidInterfaces)
// hContext : UINT_PTR -> 'uintptr_t'
// szCard : LPCWSTR -> 'str16'
// pguidInterfaces : GUID* out -> 'void *'
// pcguidInterfaces : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WinSCard.dll", {
  SCardListInterfacesW: { parameters: ["usize", "buffer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.SCardListInterfacesW(hContext, szCard, pguidInterfaces, pcguidInterfaces)
// hContext : UINT_PTR -> "usize"
// szCard : LPCWSTR -> "buffer"
// pguidInterfaces : GUID* out -> "pointer"
// pcguidInterfaces : DWORD* in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SCardListInterfacesW(
    size_t hContext,
    const uint16_t* szCard,
    void* pguidInterfaces,
    uint32_t* pcguidInterfaces);
C, "WinSCard.dll");
// $ffi->SCardListInterfacesW(hContext, szCard, pguidInterfaces, pcguidInterfaces);
// hContext : UINT_PTR
// szCard : LPCWSTR
// 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.UNICODE_OPTIONS);
    int SCardListInterfacesW(
        long hContext,   // UINT_PTR
        WString szCard,   // LPCWSTR
        Pointer pguidInterfaces,   // GUID* out
        IntByReference pcguidInterfaces   // DWORD* in/out
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("winscard")]
lib LibWinSCard
  fun SCardListInterfacesW = SCardListInterfacesW(
    hContext : LibC::SizeT,   # UINT_PTR
    szCard : UInt16*,   # LPCWSTR
    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 SCardListInterfacesWNative = Int32 Function(UintPtr, Pointer<Utf16>, Pointer<Void>, Pointer<Uint32>);
typedef SCardListInterfacesWDart = int Function(int, Pointer<Utf16>, Pointer<Void>, Pointer<Uint32>);
final SCardListInterfacesW = DynamicLibrary.open('WinSCard.dll')
    .lookupFunction<SCardListInterfacesWNative, SCardListInterfacesWDart>('SCardListInterfacesW');
// hContext : UINT_PTR -> UintPtr
// szCard : LPCWSTR -> Pointer<Utf16>
// pguidInterfaces : GUID* out -> Pointer<Void>
// pcguidInterfaces : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SCardListInterfacesW(
  hContext: NativeUInt;   // UINT_PTR
  szCard: PWideChar;   // LPCWSTR
  pguidInterfaces: PGUID;   // GUID* out
  pcguidInterfaces: Pointer   // DWORD* in/out
): Integer; stdcall;
  external 'WinSCard.dll' name 'SCardListInterfacesW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let scardlistinterfacesw =
  foreign "SCardListInterfacesW"
    (size_t @-> (ptr uint16_t) @-> (ptr void) @-> (ptr uint32_t) @-> returning int32_t)
(* hContext : UINT_PTR -> size_t *)
(* szCard : LPCWSTR -> (ptr uint16_t) *)
(* 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 ("SCardListInterfacesW" scard-list-interfaces-w :convention :stdcall) :int32
  (h-context :uint64)   ; UINT_PTR
  (sz-card (:string :encoding :utf-16le))   ; LPCWSTR
  (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 $SCardListInterfacesW = Win32::API::More->new('WinSCard',
    'int SCardListInterfacesW(WPARAM hContext, LPCWSTR szCard, LPVOID pguidInterfaces, LPVOID pcguidInterfaces)');
# my $ret = $SCardListInterfacesW->Call($hContext, $szCard, $pguidInterfaces, $pcguidInterfaces);
# hContext : UINT_PTR -> WPARAM
# szCard : LPCWSTR -> LPCWSTR
# pguidInterfaces : GUID* out -> LPVOID
# pcguidInterfaces : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

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