ホーム › Security.Credentials › SCardIntroduceReaderW
SCardIntroduceReaderW
関数新しいスマートカードリーダーをシステムに登録する。
シグネチャ
// WinSCard.dll (Unicode / -W)
#include <windows.h>
INT SCardIntroduceReaderW(
UINT_PTR hContext,
LPCWSTR szReaderName,
LPCWSTR szDeviceName
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hContext | UINT_PTR | in | リソースマネージャーコンテキストを識別するハンドルです。リソースマネージャーコンテキストは、事前に呼び出した SCardEstablishContext によって設定されます。このパラメーターを NULL にすることはできません。 |
| szReaderName | LPCWSTR | in | リーダーに割り当てる表示名です。 |
| szDeviceName | LPCWSTR | in | スマートカードリーダーのシステム名です(例: "MyReader 01")。 |
戻り値の型: INT
公式ドキュメント
既存のスマートカードリーダーに新しい名前を割り当てます。(Unicode)
戻り値
この関数は、成功したか失敗したかに応じて異なる値を返します。
| 戻り値 | 説明 |
|---|---|
|
SCARD_S_SUCCESS。 |
|
エラーコード。詳細については、 スマートカードの戻り値を参照してください。 |
解説(Remarks)
システムにインストールされているすべてのリーダーは、そのシステム名によって自動的に登録されます。通常、SCardIntroduceReader は既存のリーダーの名前を変更する場合にのみ呼び出します。
SCardIntroduceReader 関数はデータベース管理関数です。その他のデータベース管理関数の詳細については、 スマートカードデータベース管理関数を参照してください。
リーダーを削除するには、 SCardForgetReader を使用します。
例
次の例は、スマートカードリーダーを登録する方法を示しています。
// This example renames the reader name.
// This is a two-step process (first add the new
// name, then forget the old name).
LPBYTE pbAttr = NULL;
DWORD cByte = SCARD_AUTOALLOCATE;
LONG lReturn;
// Step 1: Add the new reader name.
// The device name attribute is a necessary value.
// hCardHandle was set by a previous call to SCardConnect.
lReturn = SCardGetAttrib(hCardHandle,
SCARD_ATTR_DEVICE_SYSTEM_NAME,
(LPBYTE)&pbAttr,
&cByte);
if ( SCARD_S_SUCCESS != lReturn )
{
printf("Failed SCardGetAttrib\n");
exit(1); // Or other error action
}
// Add the reader name.
// hContext was set earlier by SCardEstablishContext.
lReturn = SCardIntroduceReader(hContext,
TEXT("My New Reader Name"),
(LPCTSTR)pbAttr );
if ( SCARD_S_SUCCESS != lReturn )
{
printf("Failed SCardIntroduceReader\n");
exit(1); // Or other error action
}
// Step 2: Forget the old reader name.
lReturn = SCardForgetReader(hContext,
(LPCTSTR)pbAttr );
if ( SCARD_S_SUCCESS != lReturn )
{
printf("Failed SCardForgetReader\n");
exit(1); // Or other error action
}
// Free the memory when done.
lReturn = SCardFreeMemory( hContext, pbAttr );
メモ
winscard.h ヘッダーは SCardIntroduceReader をエイリアスとして定義しており、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択します。エンコーディング非依存のエイリアスを、エンコーディング非依存でないコードと混在させて使用すると、不一致が生じてコンパイルエラーや実行時エラーの原因となることがあります。詳細については、関数プロトタイプの規則を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// WinSCard.dll (Unicode / -W)
#include <windows.h>
INT SCardIntroduceReaderW(
UINT_PTR hContext,
LPCWSTR szReaderName,
LPCWSTR szDeviceName
);[DllImport("WinSCard.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int SCardIntroduceReaderW(
UIntPtr hContext, // UINT_PTR
[MarshalAs(UnmanagedType.LPWStr)] string szReaderName, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string szDeviceName // LPCWSTR
);<DllImport("WinSCard.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SCardIntroduceReaderW(
hContext As UIntPtr, ' UINT_PTR
<MarshalAs(UnmanagedType.LPWStr)> szReaderName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> szDeviceName As String ' LPCWSTR
) As Integer
End Function' hContext : UINT_PTR
' szReaderName : LPCWSTR
' szDeviceName : LPCWSTR
Declare PtrSafe Function SCardIntroduceReaderW Lib "winscard" ( _
ByVal hContext As LongPtr, _
ByVal szReaderName As LongPtr, _
ByVal szDeviceName As LongPtr) 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
SCardIntroduceReaderW = ctypes.windll.winscard.SCardIntroduceReaderW
SCardIntroduceReaderW.restype = ctypes.c_int
SCardIntroduceReaderW.argtypes = [
ctypes.c_size_t, # hContext : UINT_PTR
wintypes.LPCWSTR, # szReaderName : LPCWSTR
wintypes.LPCWSTR, # szDeviceName : LPCWSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WinSCard.dll')
SCardIntroduceReaderW = Fiddle::Function.new(
lib['SCardIntroduceReaderW'],
[
Fiddle::TYPE_UINTPTR_T, # hContext : UINT_PTR
Fiddle::TYPE_VOIDP, # szReaderName : LPCWSTR
Fiddle::TYPE_VOIDP, # szDeviceName : LPCWSTR
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "winscard")]
extern "system" {
fn SCardIntroduceReaderW(
hContext: usize, // UINT_PTR
szReaderName: *const u16, // LPCWSTR
szDeviceName: *const u16 // LPCWSTR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WinSCard.dll", CharSet = CharSet.Unicode)]
public static extern int SCardIntroduceReaderW(UIntPtr hContext, [MarshalAs(UnmanagedType.LPWStr)] string szReaderName, [MarshalAs(UnmanagedType.LPWStr)] string szDeviceName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WinSCard_SCardIntroduceReaderW' -Namespace Win32 -PassThru
# $api::SCardIntroduceReaderW(hContext, szReaderName, szDeviceName)#uselib "WinSCard.dll"
#func global SCardIntroduceReaderW "SCardIntroduceReaderW" wptr, wptr, wptr
; SCardIntroduceReaderW hContext, szReaderName, szDeviceName ; 戻り値は stat
; hContext : UINT_PTR -> "wptr"
; szReaderName : LPCWSTR -> "wptr"
; szDeviceName : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WinSCard.dll"
#cfunc global SCardIntroduceReaderW "SCardIntroduceReaderW" sptr, wstr, wstr
; res = SCardIntroduceReaderW(hContext, szReaderName, szDeviceName)
; hContext : UINT_PTR -> "sptr"
; szReaderName : LPCWSTR -> "wstr"
; szDeviceName : LPCWSTR -> "wstr"; INT SCardIntroduceReaderW(UINT_PTR hContext, LPCWSTR szReaderName, LPCWSTR szDeviceName)
#uselib "WinSCard.dll"
#cfunc global SCardIntroduceReaderW "SCardIntroduceReaderW" intptr, wstr, wstr
; res = SCardIntroduceReaderW(hContext, szReaderName, szDeviceName)
; hContext : UINT_PTR -> "intptr"
; szReaderName : LPCWSTR -> "wstr"
; szDeviceName : LPCWSTR -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
winscard = windows.NewLazySystemDLL("WinSCard.dll")
procSCardIntroduceReaderW = winscard.NewProc("SCardIntroduceReaderW")
)
// hContext (UINT_PTR), szReaderName (LPCWSTR), szDeviceName (LPCWSTR)
r1, _, err := procSCardIntroduceReaderW.Call(
uintptr(hContext),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szReaderName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szDeviceName))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction SCardIntroduceReaderW(
hContext: NativeUInt; // UINT_PTR
szReaderName: PWideChar; // LPCWSTR
szDeviceName: PWideChar // LPCWSTR
): Integer; stdcall;
external 'WinSCard.dll' name 'SCardIntroduceReaderW';result := DllCall("WinSCard\SCardIntroduceReaderW"
, "UPtr", hContext ; UINT_PTR
, "WStr", szReaderName ; LPCWSTR
, "WStr", szDeviceName ; LPCWSTR
, "Int") ; return: INT●SCardIntroduceReaderW(hContext, szReaderName, szDeviceName) = DLL("WinSCard.dll", "int SCardIntroduceReaderW(int, char*, char*)")
# 呼び出し: SCardIntroduceReaderW(hContext, szReaderName, szDeviceName)
# hContext : UINT_PTR -> "int"
# szReaderName : LPCWSTR -> "char*"
# szDeviceName : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "winscard" fn SCardIntroduceReaderW(
hContext: usize, // UINT_PTR
szReaderName: [*c]const u16, // LPCWSTR
szDeviceName: [*c]const u16 // LPCWSTR
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SCardIntroduceReaderW(
hContext: uint, # UINT_PTR
szReaderName: WideCString, # LPCWSTR
szDeviceName: WideCString # LPCWSTR
): int32 {.importc: "SCardIntroduceReaderW", stdcall, dynlib: "WinSCard.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "winscard");
extern(Windows)
int SCardIntroduceReaderW(
size_t hContext, // UINT_PTR
const(wchar)* szReaderName, // LPCWSTR
const(wchar)* szDeviceName // LPCWSTR
);ccall((:SCardIntroduceReaderW, "WinSCard.dll"), stdcall, Int32,
(Csize_t, Cwstring, Cwstring),
hContext, szReaderName, szDeviceName)
# hContext : UINT_PTR -> Csize_t
# szReaderName : LPCWSTR -> Cwstring
# szDeviceName : LPCWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t SCardIntroduceReaderW(
uintptr_t hContext,
const uint16_t* szReaderName,
const uint16_t* szDeviceName);
]]
local winscard = ffi.load("winscard")
-- winscard.SCardIntroduceReaderW(hContext, szReaderName, szDeviceName)
-- hContext : UINT_PTR
-- szReaderName : LPCWSTR
-- szDeviceName : LPCWSTR
-- 構造体/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 SCardIntroduceReaderW = lib.func('__stdcall', 'SCardIntroduceReaderW', 'int32_t', ['uintptr_t', 'str16', 'str16']);
// SCardIntroduceReaderW(hContext, szReaderName, szDeviceName)
// hContext : UINT_PTR -> 'uintptr_t'
// szReaderName : LPCWSTR -> 'str16'
// szDeviceName : LPCWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WinSCard.dll", {
SCardIntroduceReaderW: { parameters: ["usize", "buffer", "buffer"], result: "i32" },
});
// lib.symbols.SCardIntroduceReaderW(hContext, szReaderName, szDeviceName)
// hContext : UINT_PTR -> "usize"
// szReaderName : LPCWSTR -> "buffer"
// szDeviceName : LPCWSTR -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SCardIntroduceReaderW(
size_t hContext,
const uint16_t* szReaderName,
const uint16_t* szDeviceName);
C, "WinSCard.dll");
// $ffi->SCardIntroduceReaderW(hContext, szReaderName, szDeviceName);
// hContext : UINT_PTR
// szReaderName : LPCWSTR
// szDeviceName : LPCWSTR
// 構造体/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 SCardIntroduceReaderW(
long hContext, // UINT_PTR
WString szReaderName, // LPCWSTR
WString szDeviceName // LPCWSTR
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("winscard")]
lib LibWinSCard
fun SCardIntroduceReaderW = SCardIntroduceReaderW(
hContext : LibC::SizeT, # UINT_PTR
szReaderName : UInt16*, # LPCWSTR
szDeviceName : UInt16* # LPCWSTR
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SCardIntroduceReaderWNative = Int32 Function(UintPtr, Pointer<Utf16>, Pointer<Utf16>);
typedef SCardIntroduceReaderWDart = int Function(int, Pointer<Utf16>, Pointer<Utf16>);
final SCardIntroduceReaderW = DynamicLibrary.open('WinSCard.dll')
.lookupFunction<SCardIntroduceReaderWNative, SCardIntroduceReaderWDart>('SCardIntroduceReaderW');
// hContext : UINT_PTR -> UintPtr
// szReaderName : LPCWSTR -> Pointer<Utf16>
// szDeviceName : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SCardIntroduceReaderW(
hContext: NativeUInt; // UINT_PTR
szReaderName: PWideChar; // LPCWSTR
szDeviceName: PWideChar // LPCWSTR
): Integer; stdcall;
external 'WinSCard.dll' name 'SCardIntroduceReaderW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SCardIntroduceReaderW"
c_SCardIntroduceReaderW :: CUIntPtr -> CWString -> CWString -> IO Int32
-- hContext : UINT_PTR -> CUIntPtr
-- szReaderName : LPCWSTR -> CWString
-- szDeviceName : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let scardintroducereaderw =
foreign "SCardIntroduceReaderW"
(size_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> returning int32_t)
(* hContext : UINT_PTR -> size_t *)
(* szReaderName : LPCWSTR -> (ptr uint16_t) *)
(* szDeviceName : LPCWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library winscard (t "WinSCard.dll"))
(cffi:use-foreign-library winscard)
(cffi:defcfun ("SCardIntroduceReaderW" scard-introduce-reader-w :convention :stdcall) :int32
(h-context :uint64) ; UINT_PTR
(sz-reader-name (:string :encoding :utf-16le)) ; LPCWSTR
(sz-device-name (:string :encoding :utf-16le))) ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SCardIntroduceReaderW = Win32::API::More->new('WinSCard',
'int SCardIntroduceReaderW(WPARAM hContext, LPCWSTR szReaderName, LPCWSTR szDeviceName)');
# my $ret = $SCardIntroduceReaderW->Call($hContext, $szReaderName, $szDeviceName);
# hContext : UINT_PTR -> WPARAM
# szReaderName : LPCWSTR -> LPCWSTR
# szDeviceName : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f SCardIntroduceReaderA (ANSI版) — 新しいスマートカードリーダーをシステムに登録する。
公式の関連項目
- f SCardEstablishContext — スマートカードリソースマネージャーへの接続コンテキストを確立する。
- f SCardForgetReaderW — 登録済みのスマートカードリーダーを削除する。
- f SCardIntroduceCardTypeW — 新しいスマートカード種別をシステムに登録する。
- f SCardIntroduceReaderGroupW — 新しいリーダーグループをシステムに登録する。