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

SCardGetDeviceTypeIdW

関数
指定したスマートカードリーダーのデバイスタイプIDを取得する(Unicode版)。
DLLWinSCard.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

INT SCardGetDeviceTypeIdW(
    UINT_PTR hContext,
    LPCWSTR szReaderName,
    DWORD* pdwDeviceTypeId
);

パラメーター

名前方向説明
hContextUINT_PTRinクエリのリソースマネージャーコンテキストを識別するハンドルです。リソースマネージャーコンテキストは SCardEstablishContext 関数を呼び出すことで設定できます。このパラメーターを NULL にすることはできません。
szReaderNameLPCWSTRinリーダー名です。この値は SCardListReaders 関数を呼び出すことで取得できます。
pdwDeviceTypeIdDWORD*inout実際のデバイス種別識別子です。この関数が返すリーダー種別の一覧は、SCARD_READER_CAPABILITIES 構造体の ReaderType メンバーに記載されています。

戻り値の型: INT

公式ドキュメント

指定されたリーダー名に対応するカードリーダーのデバイス種別識別子を取得します。この関数はリーダーの状態に影響を与えません。(Unicode)

戻り値

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

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

解説(Remarks)

メモ

winscard.h ヘッダーは、UNICODE プリプロセッサー定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして SCardGetDeviceTypeId を定義しています。エンコーディング非依存のエイリアスの使用を、エンコーディング非依存でないコードと混在させると、不一致が生じてコンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、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 SCardGetDeviceTypeIdW(
    UINT_PTR hContext,
    LPCWSTR szReaderName,
    DWORD* pdwDeviceTypeId
);
[DllImport("WinSCard.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int SCardGetDeviceTypeIdW(
    UIntPtr hContext,   // UINT_PTR
    [MarshalAs(UnmanagedType.LPWStr)] string szReaderName,   // LPCWSTR
    ref uint pdwDeviceTypeId   // DWORD* in/out
);
<DllImport("WinSCard.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SCardGetDeviceTypeIdW(
    hContext As UIntPtr,   ' UINT_PTR
    <MarshalAs(UnmanagedType.LPWStr)> szReaderName As String,   ' LPCWSTR
    ByRef pdwDeviceTypeId As UInteger   ' DWORD* in/out
) As Integer
End Function
' hContext : UINT_PTR
' szReaderName : LPCWSTR
' pdwDeviceTypeId : DWORD* in/out
Declare PtrSafe Function SCardGetDeviceTypeIdW Lib "winscard" ( _
    ByVal hContext As LongPtr, _
    ByVal szReaderName As LongPtr, _
    ByRef pdwDeviceTypeId 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

SCardGetDeviceTypeIdW = ctypes.windll.winscard.SCardGetDeviceTypeIdW
SCardGetDeviceTypeIdW.restype = ctypes.c_int
SCardGetDeviceTypeIdW.argtypes = [
    ctypes.c_size_t,  # hContext : UINT_PTR
    wintypes.LPCWSTR,  # szReaderName : LPCWSTR
    ctypes.POINTER(wintypes.DWORD),  # pdwDeviceTypeId : DWORD* in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	winscard = windows.NewLazySystemDLL("WinSCard.dll")
	procSCardGetDeviceTypeIdW = winscard.NewProc("SCardGetDeviceTypeIdW")
)

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

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

let scardgetdevicetypeidw =
  foreign "SCardGetDeviceTypeIdW"
    (size_t @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning int32_t)
(* hContext : UINT_PTR -> size_t *)
(* szReaderName : LPCWSTR -> (ptr uint16_t) *)
(* pdwDeviceTypeId : 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 ("SCardGetDeviceTypeIdW" scard-get-device-type-id-w :convention :stdcall) :int32
  (h-context :uint64)   ; UINT_PTR
  (sz-reader-name (:string :encoding :utf-16le))   ; LPCWSTR
  (pdw-device-type-id :pointer))   ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SCardGetDeviceTypeIdW = Win32::API::More->new('WinSCard',
    'int SCardGetDeviceTypeIdW(WPARAM hContext, LPCWSTR szReaderName, LPVOID pdwDeviceTypeId)');
# my $ret = $SCardGetDeviceTypeIdW->Call($hContext, $szReaderName, $pdwDeviceTypeId);
# hContext : UINT_PTR -> WPARAM
# szReaderName : LPCWSTR -> LPCWSTR
# pdwDeviceTypeId : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い