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

SCardIntroduceReaderW

関数
新しいスマートカードリーダーをシステムに登録する。
DLLWinSCard.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

INT SCardIntroduceReaderW(
    UINT_PTR hContext,
    LPCWSTR szReaderName,
    LPCWSTR szDeviceName
);

パラメーター

名前方向
hContextUINT_PTRin
szReaderNameLPCWSTRin
szDeviceNameLPCWSTRin

戻り値の型: INT

各言語での呼び出し定義

// 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   // INT
function 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 版の利用を推奨。