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

SCardGetDeviceTypeIdA

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

シグネチャ

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

INT SCardGetDeviceTypeIdA(
    UINT_PTR hContext,
    LPCSTR szReaderName,
    DWORD* pdwDeviceTypeId
);

パラメーター

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

戻り値の型: INT

公式ドキュメント

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

戻り値

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

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

解説(Remarks)

メモ

winscard.h ヘッダーでは、SCardGetDeviceTypeId は、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  (ANSI / -A)
#include <windows.h>

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

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

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

var (
	winscard = windows.NewLazySystemDLL("WinSCard.dll")
	procSCardGetDeviceTypeIdA = winscard.NewProc("SCardGetDeviceTypeIdA")
)

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

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

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

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

関連項目

文字セット違い