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

SCardAddReaderToGroupW

関数
スマートカードリーダーを指定グループに追加する。
DLLWinSCard.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

INT SCardAddReaderToGroupW(
    UINT_PTR hContext,
    LPCWSTR szReaderName,
    LPCWSTR szGroupName
);

パラメーター

名前方向説明
hContextUINT_PTRinリソースマネージャーコンテキストを識別するハンドル。リソースマネージャーコンテキストは、事前の SCardEstablishContext の呼び出しによって設定されます。このパラメーターを NULL にすることはできません。
szReaderNameLPCWSTRin追加するリーダーの表示名。
szGroupNameLPCWSTRin

リーダーを追加するグループの表示名。

意味
SCARD_ALL_READERS
TEXT("SCard$AllReaders\000")
リーダーを列挙する際にグループ名が指定されなかった場合に使用されるグループ。リーダーがどのグループに属しているかに関係なく、すべてのリーダーのリストを返します。
SCARD_DEFAULT_READERS
TEXT("SCard$DefaultReaders\000")
リーダーがシステムに導入されたときに、すべてのリーダーが追加される既定のグループ。
SCARD_LOCAL_READERS
TEXT("SCard$LocalReaders\000")
使用されていないレガシー値。これは内部的に管理されるグループであり、リーダーグループ API を使用して変更することはできません。列挙のみを目的としています。
SCARD_SYSTEM_READERS
TEXT("SCard$SystemReaders\000")
使用されていないレガシー値。これは内部的に管理されるグループであり、リーダーグループ API を使用して変更することはできません。列挙のみを目的としています。

戻り値の型: INT

公式ドキュメント

リーダーをリーダーグループに追加します。(Unicode)

戻り値

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

戻り値 説明
成功
SCARD_S_SUCCESS。
失敗
エラーコード。詳細については、スマートカードの戻り値を参照してください。

解説(Remarks)

SCardAddReaderToGroup は、指定されたリーダーグループがまだ存在しない場合、それを自動的に作成します。

SCardAddReaderToGroup 関数はデータベース管理関数です。その他のデータベース管理関数の詳細については、スマートカードデータベース管理関数を参照してください。

次の例は、スマートカードリーダーをグループに追加する方法を示しています。この例では、lReturn が LONG 型の既存の変数であり、hContext が事前の SCardEstablishContext 関数の呼び出しから受け取った有効なハンドルであり、"MyReader" と "MyReaderGroup" がそれぞれ事前の SCardIntroduceReader 関数および SCardIntroduceReaderGroup 関数の呼び出しを通じてシステムに認識されていることを前提としています。


lReturn = SCardAddReaderToGroup( hContext, 
                                L"MyReader",
                                L"MyReaderGroup");
if ( SCARD_S_SUCCESS != lReturn )
    printf("Failed SCardAddReaderToGroup\n");
メモ

winscard.h ヘッダーは、SCardAddReaderToGroup を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング非依存のエイリアスの使用を、エンコーディング非依存ではないコードと混在させると、不一致が生じ、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規則を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は 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 SCardAddReaderToGroupW(
    UINT_PTR hContext,
    LPCWSTR szReaderName,
    LPCWSTR szGroupName
);
[DllImport("WinSCard.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int SCardAddReaderToGroupW(
    UIntPtr hContext,   // UINT_PTR
    [MarshalAs(UnmanagedType.LPWStr)] string szReaderName,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string szGroupName   // LPCWSTR
);
<DllImport("WinSCard.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SCardAddReaderToGroupW(
    hContext As UIntPtr,   ' UINT_PTR
    <MarshalAs(UnmanagedType.LPWStr)> szReaderName As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> szGroupName As String   ' LPCWSTR
) As Integer
End Function
' hContext : UINT_PTR
' szReaderName : LPCWSTR
' szGroupName : LPCWSTR
Declare PtrSafe Function SCardAddReaderToGroupW Lib "winscard" ( _
    ByVal hContext As LongPtr, _
    ByVal szReaderName As LongPtr, _
    ByVal szGroupName 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

SCardAddReaderToGroupW = ctypes.windll.winscard.SCardAddReaderToGroupW
SCardAddReaderToGroupW.restype = ctypes.c_int
SCardAddReaderToGroupW.argtypes = [
    ctypes.c_size_t,  # hContext : UINT_PTR
    wintypes.LPCWSTR,  # szReaderName : LPCWSTR
    wintypes.LPCWSTR,  # szGroupName : LPCWSTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WinSCard.dll')
SCardAddReaderToGroupW = Fiddle::Function.new(
  lib['SCardAddReaderToGroupW'],
  [
    Fiddle::TYPE_UINTPTR_T,  # hContext : UINT_PTR
    Fiddle::TYPE_VOIDP,  # szReaderName : LPCWSTR
    Fiddle::TYPE_VOIDP,  # szGroupName : LPCWSTR
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "winscard")]
extern "system" {
    fn SCardAddReaderToGroupW(
        hContext: usize,  // UINT_PTR
        szReaderName: *const u16,  // LPCWSTR
        szGroupName: *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 SCardAddReaderToGroupW(UIntPtr hContext, [MarshalAs(UnmanagedType.LPWStr)] string szReaderName, [MarshalAs(UnmanagedType.LPWStr)] string szGroupName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WinSCard_SCardAddReaderToGroupW' -Namespace Win32 -PassThru
# $api::SCardAddReaderToGroupW(hContext, szReaderName, szGroupName)
#uselib "WinSCard.dll"
#func global SCardAddReaderToGroupW "SCardAddReaderToGroupW" wptr, wptr, wptr
; SCardAddReaderToGroupW hContext, szReaderName, szGroupName   ; 戻り値は stat
; hContext : UINT_PTR -> "wptr"
; szReaderName : LPCWSTR -> "wptr"
; szGroupName : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WinSCard.dll"
#cfunc global SCardAddReaderToGroupW "SCardAddReaderToGroupW" sptr, wstr, wstr
; res = SCardAddReaderToGroupW(hContext, szReaderName, szGroupName)
; hContext : UINT_PTR -> "sptr"
; szReaderName : LPCWSTR -> "wstr"
; szGroupName : LPCWSTR -> "wstr"
; INT SCardAddReaderToGroupW(UINT_PTR hContext, LPCWSTR szReaderName, LPCWSTR szGroupName)
#uselib "WinSCard.dll"
#cfunc global SCardAddReaderToGroupW "SCardAddReaderToGroupW" intptr, wstr, wstr
; res = SCardAddReaderToGroupW(hContext, szReaderName, szGroupName)
; hContext : UINT_PTR -> "intptr"
; szReaderName : LPCWSTR -> "wstr"
; szGroupName : LPCWSTR -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winscard = windows.NewLazySystemDLL("WinSCard.dll")
	procSCardAddReaderToGroupW = winscard.NewProc("SCardAddReaderToGroupW")
)

// hContext (UINT_PTR), szReaderName (LPCWSTR), szGroupName (LPCWSTR)
r1, _, err := procSCardAddReaderToGroupW.Call(
	uintptr(hContext),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szReaderName))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szGroupName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function SCardAddReaderToGroupW(
  hContext: NativeUInt;   // UINT_PTR
  szReaderName: PWideChar;   // LPCWSTR
  szGroupName: PWideChar   // LPCWSTR
): Integer; stdcall;
  external 'WinSCard.dll' name 'SCardAddReaderToGroupW';
result := DllCall("WinSCard\SCardAddReaderToGroupW"
    , "UPtr", hContext   ; UINT_PTR
    , "WStr", szReaderName   ; LPCWSTR
    , "WStr", szGroupName   ; LPCWSTR
    , "Int")   ; return: INT
●SCardAddReaderToGroupW(hContext, szReaderName, szGroupName) = DLL("WinSCard.dll", "int SCardAddReaderToGroupW(int, char*, char*)")
# 呼び出し: SCardAddReaderToGroupW(hContext, szReaderName, szGroupName)
# hContext : UINT_PTR -> "int"
# szReaderName : LPCWSTR -> "char*"
# szGroupName : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

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

foreign import stdcall safe "SCardAddReaderToGroupW"
  c_SCardAddReaderToGroupW :: CUIntPtr -> CWString -> CWString -> IO Int32
-- hContext : UINT_PTR -> CUIntPtr
-- szReaderName : LPCWSTR -> CWString
-- szGroupName : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

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

関連項目

文字セット違い
公式の関連項目