ホーム › Security.Credentials › SCardIntroduceReaderA
SCardIntroduceReaderA
関数新しいスマートカードリーダーをシステムに登録する。
シグネチャ
// WinSCard.dll (ANSI / -A)
#include <windows.h>
INT SCardIntroduceReaderA(
UINT_PTR hContext,
LPCSTR szReaderName,
LPCSTR szDeviceName
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hContext | UINT_PTR | in | リソースマネージャーコンテキストを識別するハンドルです。リソースマネージャーコンテキストは、事前の SCardEstablishContext の呼び出しによって設定されます。このパラメーターを NULL にすることはできません。 |
| szReaderName | LPCSTR | in | リーダーに割り当てる表示名です。 |
| szDeviceName | LPCSTR | in | スマートカードリーダーのシステム名です。たとえば "MyReader 01" のような名前です。 |
戻り値の型: INT
公式ドキュメント
既存のスマートカードリーダーに新しい名前を割り当てます。(ANSI)
戻り値
この関数は、成功するか失敗するかに応じて異なる値を返します。
| 戻り値コード | 説明 |
|---|---|
|
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 ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして SCardIntroduceReader を定義します。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、不一致が生じ、コンパイルエラーや実行時エラーの原因となることがあります。詳細については、関数プロトタイプの規約を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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 (ANSI / -A)
#include <windows.h>
INT SCardIntroduceReaderA(
UINT_PTR hContext,
LPCSTR szReaderName,
LPCSTR szDeviceName
);[DllImport("WinSCard.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern int SCardIntroduceReaderA(
UIntPtr hContext, // UINT_PTR
[MarshalAs(UnmanagedType.LPStr)] string szReaderName, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string szDeviceName // LPCSTR
);<DllImport("WinSCard.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SCardIntroduceReaderA(
hContext As UIntPtr, ' UINT_PTR
<MarshalAs(UnmanagedType.LPStr)> szReaderName As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> szDeviceName As String ' LPCSTR
) As Integer
End Function' hContext : UINT_PTR
' szReaderName : LPCSTR
' szDeviceName : LPCSTR
Declare PtrSafe Function SCardIntroduceReaderA Lib "winscard" ( _
ByVal hContext As LongPtr, _
ByVal szReaderName As String, _
ByVal szDeviceName As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SCardIntroduceReaderA = ctypes.windll.winscard.SCardIntroduceReaderA
SCardIntroduceReaderA.restype = ctypes.c_int
SCardIntroduceReaderA.argtypes = [
ctypes.c_size_t, # hContext : UINT_PTR
wintypes.LPCSTR, # szReaderName : LPCSTR
wintypes.LPCSTR, # szDeviceName : LPCSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WinSCard.dll')
SCardIntroduceReaderA = Fiddle::Function.new(
lib['SCardIntroduceReaderA'],
[
Fiddle::TYPE_UINTPTR_T, # hContext : UINT_PTR
Fiddle::TYPE_VOIDP, # szReaderName : LPCSTR
Fiddle::TYPE_VOIDP, # szDeviceName : LPCSTR
],
Fiddle::TYPE_INT)#[link(name = "winscard")]
extern "system" {
fn SCardIntroduceReaderA(
hContext: usize, // UINT_PTR
szReaderName: *const u8, // LPCSTR
szDeviceName: *const u8 // LPCSTR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WinSCard.dll", CharSet = CharSet.Ansi)]
public static extern int SCardIntroduceReaderA(UIntPtr hContext, [MarshalAs(UnmanagedType.LPStr)] string szReaderName, [MarshalAs(UnmanagedType.LPStr)] string szDeviceName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WinSCard_SCardIntroduceReaderA' -Namespace Win32 -PassThru
# $api::SCardIntroduceReaderA(hContext, szReaderName, szDeviceName)#uselib "WinSCard.dll"
#func global SCardIntroduceReaderA "SCardIntroduceReaderA" sptr, sptr, sptr
; SCardIntroduceReaderA hContext, szReaderName, szDeviceName ; 戻り値は stat
; hContext : UINT_PTR -> "sptr"
; szReaderName : LPCSTR -> "sptr"
; szDeviceName : LPCSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WinSCard.dll"
#cfunc global SCardIntroduceReaderA "SCardIntroduceReaderA" sptr, str, str
; res = SCardIntroduceReaderA(hContext, szReaderName, szDeviceName)
; hContext : UINT_PTR -> "sptr"
; szReaderName : LPCSTR -> "str"
; szDeviceName : LPCSTR -> "str"; INT SCardIntroduceReaderA(UINT_PTR hContext, LPCSTR szReaderName, LPCSTR szDeviceName)
#uselib "WinSCard.dll"
#cfunc global SCardIntroduceReaderA "SCardIntroduceReaderA" intptr, str, str
; res = SCardIntroduceReaderA(hContext, szReaderName, szDeviceName)
; hContext : UINT_PTR -> "intptr"
; szReaderName : LPCSTR -> "str"
; szDeviceName : LPCSTR -> "str"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
winscard = windows.NewLazySystemDLL("WinSCard.dll")
procSCardIntroduceReaderA = winscard.NewProc("SCardIntroduceReaderA")
)
// hContext (UINT_PTR), szReaderName (LPCSTR), szDeviceName (LPCSTR)
r1, _, err := procSCardIntroduceReaderA.Call(
uintptr(hContext),
uintptr(unsafe.Pointer(windows.BytePtrFromString(szReaderName))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(szDeviceName))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction SCardIntroduceReaderA(
hContext: NativeUInt; // UINT_PTR
szReaderName: PAnsiChar; // LPCSTR
szDeviceName: PAnsiChar // LPCSTR
): Integer; stdcall;
external 'WinSCard.dll' name 'SCardIntroduceReaderA';result := DllCall("WinSCard\SCardIntroduceReaderA"
, "UPtr", hContext ; UINT_PTR
, "AStr", szReaderName ; LPCSTR
, "AStr", szDeviceName ; LPCSTR
, "Int") ; return: INT●SCardIntroduceReaderA(hContext, szReaderName, szDeviceName) = DLL("WinSCard.dll", "int SCardIntroduceReaderA(int, char*, char*)")
# 呼び出し: SCardIntroduceReaderA(hContext, szReaderName, szDeviceName)
# hContext : UINT_PTR -> "int"
# szReaderName : LPCSTR -> "char*"
# szDeviceName : LPCSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "winscard" fn SCardIntroduceReaderA(
hContext: usize, // UINT_PTR
szReaderName: [*c]const u8, // LPCSTR
szDeviceName: [*c]const u8 // LPCSTR
) callconv(std.os.windows.WINAPI) i32;proc SCardIntroduceReaderA(
hContext: uint, # UINT_PTR
szReaderName: cstring, # LPCSTR
szDeviceName: cstring # LPCSTR
): int32 {.importc: "SCardIntroduceReaderA", stdcall, dynlib: "WinSCard.dll".}pragma(lib, "winscard");
extern(Windows)
int SCardIntroduceReaderA(
size_t hContext, // UINT_PTR
const(char)* szReaderName, // LPCSTR
const(char)* szDeviceName // LPCSTR
);ccall((:SCardIntroduceReaderA, "WinSCard.dll"), stdcall, Int32,
(Csize_t, Cstring, Cstring),
hContext, szReaderName, szDeviceName)
# hContext : UINT_PTR -> Csize_t
# szReaderName : LPCSTR -> Cstring
# szDeviceName : LPCSTR -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SCardIntroduceReaderA(
uintptr_t hContext,
const char* szReaderName,
const char* szDeviceName);
]]
local winscard = ffi.load("winscard")
-- winscard.SCardIntroduceReaderA(hContext, szReaderName, szDeviceName)
-- hContext : UINT_PTR
-- szReaderName : LPCSTR
-- szDeviceName : LPCSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WinSCard.dll');
const SCardIntroduceReaderA = lib.func('__stdcall', 'SCardIntroduceReaderA', 'int32_t', ['uintptr_t', 'str', 'str']);
// SCardIntroduceReaderA(hContext, szReaderName, szDeviceName)
// hContext : UINT_PTR -> 'uintptr_t'
// szReaderName : LPCSTR -> 'str'
// szDeviceName : LPCSTR -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WinSCard.dll", {
SCardIntroduceReaderA: { parameters: ["usize", "buffer", "buffer"], result: "i32" },
});
// lib.symbols.SCardIntroduceReaderA(hContext, szReaderName, szDeviceName)
// hContext : UINT_PTR -> "usize"
// szReaderName : LPCSTR -> "buffer"
// szDeviceName : LPCSTR -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SCardIntroduceReaderA(
size_t hContext,
const char* szReaderName,
const char* szDeviceName);
C, "WinSCard.dll");
// $ffi->SCardIntroduceReaderA(hContext, szReaderName, szDeviceName);
// hContext : UINT_PTR
// szReaderName : LPCSTR
// szDeviceName : LPCSTR
// 構造体/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 SCardIntroduceReaderA(
long hContext, // UINT_PTR
String szReaderName, // LPCSTR
String szDeviceName // LPCSTR
);
}@[Link("winscard")]
lib LibWinSCard
fun SCardIntroduceReaderA = SCardIntroduceReaderA(
hContext : LibC::SizeT, # UINT_PTR
szReaderName : UInt8*, # LPCSTR
szDeviceName : UInt8* # LPCSTR
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SCardIntroduceReaderANative = Int32 Function(UintPtr, Pointer<Utf8>, Pointer<Utf8>);
typedef SCardIntroduceReaderADart = int Function(int, Pointer<Utf8>, Pointer<Utf8>);
final SCardIntroduceReaderA = DynamicLibrary.open('WinSCard.dll')
.lookupFunction<SCardIntroduceReaderANative, SCardIntroduceReaderADart>('SCardIntroduceReaderA');
// hContext : UINT_PTR -> UintPtr
// szReaderName : LPCSTR -> Pointer<Utf8>
// szDeviceName : LPCSTR -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SCardIntroduceReaderA(
hContext: NativeUInt; // UINT_PTR
szReaderName: PAnsiChar; // LPCSTR
szDeviceName: PAnsiChar // LPCSTR
): Integer; stdcall;
external 'WinSCard.dll' name 'SCardIntroduceReaderA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SCardIntroduceReaderA"
c_SCardIntroduceReaderA :: CUIntPtr -> CString -> CString -> IO Int32
-- hContext : UINT_PTR -> CUIntPtr
-- szReaderName : LPCSTR -> CString
-- szDeviceName : LPCSTR -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let scardintroducereadera =
foreign "SCardIntroduceReaderA"
(size_t @-> string @-> string @-> returning int32_t)
(* hContext : UINT_PTR -> size_t *)
(* szReaderName : LPCSTR -> string *)
(* szDeviceName : LPCSTR -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library winscard (t "WinSCard.dll"))
(cffi:use-foreign-library winscard)
(cffi:defcfun ("SCardIntroduceReaderA" scard-introduce-reader-a :convention :stdcall) :int32
(h-context :uint64) ; UINT_PTR
(sz-reader-name :string) ; LPCSTR
(sz-device-name :string)) ; LPCSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SCardIntroduceReaderA = Win32::API::More->new('WinSCard',
'int SCardIntroduceReaderA(WPARAM hContext, LPCSTR szReaderName, LPCSTR szDeviceName)');
# my $ret = $SCardIntroduceReaderA->Call($hContext, $szReaderName, $szDeviceName);
# hContext : UINT_PTR -> WPARAM
# szReaderName : LPCSTR -> LPCSTR
# szDeviceName : LPCSTR -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SCardIntroduceReaderW (Unicode版) — 新しいスマートカードリーダーをシステムに登録する。
公式の関連項目
- f SCardEstablishContext — スマートカードリソースマネージャーへの接続コンテキストを確立する。
- f SCardForgetReaderA — 登録済みのスマートカードリーダーを削除する。
- f SCardIntroduceCardTypeA — 新しいスマートカード種別をシステムに登録する。
- f SCardIntroduceReaderGroupA — 新しいリーダーグループをシステムに登録する。