SCardForgetCardTypeW
関数シグネチャ
// WinSCard.dll (Unicode / -W)
#include <windows.h>
INT SCardForgetCardTypeW(
UINT_PTR hContext,
LPCWSTR szCardName
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hContext | UINT_PTR | in | リソースマネージャーコンテキストを識別するハンドルです。リソースマネージャーコンテキストは、事前に SCardEstablishContext を呼び出して設定します。このパラメーターを NULL にすることはできません。 |
| szCardName | LPCWSTR | in | スマートカードデータベースから削除するカードの表示名です。 |
戻り値の型: INT
公式ドキュメント
導入済みのスマートカードをスマートカードサブシステムから削除します。(Unicode)
戻り値
この関数は、成功するか失敗するかに応じて異なる値を返します。
| 戻り値コード | 説明 |
|---|---|
|
SCARD_S_SUCCESS。 |
|
エラーコード。詳細については、 Smart Card Return Values を参照してください。 |
解説(Remarks)
この関数はリダイレクトされませんが、リモートデスクトップセッション内で SCardForgetCardType 関数を呼び出してもエラーにはなりません。これは、結果がローカルコンピューターではなくリモートコンピューターから返されることを意味するだけです。
SCardForgetCardType 関数はデータベース管理関数です。その他のデータベース管理関数の詳細については、 Smart Card Database Management Functions を参照してください。
例
次の例では、指定されたカードの種類をシステムから削除します。この例では、lReturn が LONG 型の有効な変数であり、hContext が以前の SCardEstablishContext 関数の呼び出しで取得した有効なハンドルであり、"MyCardName" が事前に SCardIntroduceCardType 関数の呼び出しによって導入されていることを前提としています。
lReturn = SCardForgetCardType(hContext,
L"MyCardName");
if ( SCARD_S_SUCCESS != lReturn )
printf("Failed SCardForgetCardType\n");
winscard.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして SCardForgetCardType を定義します。エンコーディング非依存のエイリアスを、エンコーディング非依存でないコードと混在させて使用すると、不一致が生じてコンパイルエラーまたは実行時エラーを引き起こす可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// WinSCard.dll (Unicode / -W)
#include <windows.h>
INT SCardForgetCardTypeW(
UINT_PTR hContext,
LPCWSTR szCardName
);[DllImport("WinSCard.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int SCardForgetCardTypeW(
UIntPtr hContext, // UINT_PTR
[MarshalAs(UnmanagedType.LPWStr)] string szCardName // LPCWSTR
);<DllImport("WinSCard.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SCardForgetCardTypeW(
hContext As UIntPtr, ' UINT_PTR
<MarshalAs(UnmanagedType.LPWStr)> szCardName As String ' LPCWSTR
) As Integer
End Function' hContext : UINT_PTR
' szCardName : LPCWSTR
Declare PtrSafe Function SCardForgetCardTypeW Lib "winscard" ( _
ByVal hContext As LongPtr, _
ByVal szCardName 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
SCardForgetCardTypeW = ctypes.windll.winscard.SCardForgetCardTypeW
SCardForgetCardTypeW.restype = ctypes.c_int
SCardForgetCardTypeW.argtypes = [
ctypes.c_size_t, # hContext : UINT_PTR
wintypes.LPCWSTR, # szCardName : LPCWSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WinSCard.dll')
SCardForgetCardTypeW = Fiddle::Function.new(
lib['SCardForgetCardTypeW'],
[
Fiddle::TYPE_UINTPTR_T, # hContext : UINT_PTR
Fiddle::TYPE_VOIDP, # szCardName : LPCWSTR
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "winscard")]
extern "system" {
fn SCardForgetCardTypeW(
hContext: usize, // UINT_PTR
szCardName: *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 SCardForgetCardTypeW(UIntPtr hContext, [MarshalAs(UnmanagedType.LPWStr)] string szCardName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WinSCard_SCardForgetCardTypeW' -Namespace Win32 -PassThru
# $api::SCardForgetCardTypeW(hContext, szCardName)#uselib "WinSCard.dll"
#func global SCardForgetCardTypeW "SCardForgetCardTypeW" wptr, wptr
; SCardForgetCardTypeW hContext, szCardName ; 戻り値は stat
; hContext : UINT_PTR -> "wptr"
; szCardName : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WinSCard.dll"
#cfunc global SCardForgetCardTypeW "SCardForgetCardTypeW" sptr, wstr
; res = SCardForgetCardTypeW(hContext, szCardName)
; hContext : UINT_PTR -> "sptr"
; szCardName : LPCWSTR -> "wstr"; INT SCardForgetCardTypeW(UINT_PTR hContext, LPCWSTR szCardName)
#uselib "WinSCard.dll"
#cfunc global SCardForgetCardTypeW "SCardForgetCardTypeW" intptr, wstr
; res = SCardForgetCardTypeW(hContext, szCardName)
; hContext : UINT_PTR -> "intptr"
; szCardName : LPCWSTR -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
winscard = windows.NewLazySystemDLL("WinSCard.dll")
procSCardForgetCardTypeW = winscard.NewProc("SCardForgetCardTypeW")
)
// hContext (UINT_PTR), szCardName (LPCWSTR)
r1, _, err := procSCardForgetCardTypeW.Call(
uintptr(hContext),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szCardName))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction SCardForgetCardTypeW(
hContext: NativeUInt; // UINT_PTR
szCardName: PWideChar // LPCWSTR
): Integer; stdcall;
external 'WinSCard.dll' name 'SCardForgetCardTypeW';result := DllCall("WinSCard\SCardForgetCardTypeW"
, "UPtr", hContext ; UINT_PTR
, "WStr", szCardName ; LPCWSTR
, "Int") ; return: INT●SCardForgetCardTypeW(hContext, szCardName) = DLL("WinSCard.dll", "int SCardForgetCardTypeW(int, char*)")
# 呼び出し: SCardForgetCardTypeW(hContext, szCardName)
# hContext : UINT_PTR -> "int"
# szCardName : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "winscard" fn SCardForgetCardTypeW(
hContext: usize, // UINT_PTR
szCardName: [*c]const u16 // LPCWSTR
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SCardForgetCardTypeW(
hContext: uint, # UINT_PTR
szCardName: WideCString # LPCWSTR
): int32 {.importc: "SCardForgetCardTypeW", stdcall, dynlib: "WinSCard.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "winscard");
extern(Windows)
int SCardForgetCardTypeW(
size_t hContext, // UINT_PTR
const(wchar)* szCardName // LPCWSTR
);ccall((:SCardForgetCardTypeW, "WinSCard.dll"), stdcall, Int32,
(Csize_t, Cwstring),
hContext, szCardName)
# hContext : UINT_PTR -> Csize_t
# szCardName : LPCWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t SCardForgetCardTypeW(
uintptr_t hContext,
const uint16_t* szCardName);
]]
local winscard = ffi.load("winscard")
-- winscard.SCardForgetCardTypeW(hContext, szCardName)
-- hContext : UINT_PTR
-- szCardName : 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 SCardForgetCardTypeW = lib.func('__stdcall', 'SCardForgetCardTypeW', 'int32_t', ['uintptr_t', 'str16']);
// SCardForgetCardTypeW(hContext, szCardName)
// hContext : UINT_PTR -> 'uintptr_t'
// szCardName : LPCWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WinSCard.dll", {
SCardForgetCardTypeW: { parameters: ["usize", "buffer"], result: "i32" },
});
// lib.symbols.SCardForgetCardTypeW(hContext, szCardName)
// hContext : UINT_PTR -> "usize"
// szCardName : LPCWSTR -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SCardForgetCardTypeW(
size_t hContext,
const uint16_t* szCardName);
C, "WinSCard.dll");
// $ffi->SCardForgetCardTypeW(hContext, szCardName);
// hContext : UINT_PTR
// szCardName : 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 SCardForgetCardTypeW(
long hContext, // UINT_PTR
WString szCardName // LPCWSTR
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("winscard")]
lib LibWinSCard
fun SCardForgetCardTypeW = SCardForgetCardTypeW(
hContext : LibC::SizeT, # UINT_PTR
szCardName : 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 SCardForgetCardTypeWNative = Int32 Function(UintPtr, Pointer<Utf16>);
typedef SCardForgetCardTypeWDart = int Function(int, Pointer<Utf16>);
final SCardForgetCardTypeW = DynamicLibrary.open('WinSCard.dll')
.lookupFunction<SCardForgetCardTypeWNative, SCardForgetCardTypeWDart>('SCardForgetCardTypeW');
// hContext : UINT_PTR -> UintPtr
// szCardName : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SCardForgetCardTypeW(
hContext: NativeUInt; // UINT_PTR
szCardName: PWideChar // LPCWSTR
): Integer; stdcall;
external 'WinSCard.dll' name 'SCardForgetCardTypeW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SCardForgetCardTypeW"
c_SCardForgetCardTypeW :: CUIntPtr -> CWString -> IO Int32
-- hContext : UINT_PTR -> CUIntPtr
-- szCardName : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let scardforgetcardtypew =
foreign "SCardForgetCardTypeW"
(size_t @-> (ptr uint16_t) @-> returning int32_t)
(* hContext : UINT_PTR -> size_t *)
(* szCardName : 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 ("SCardForgetCardTypeW" scard-forget-card-type-w :convention :stdcall) :int32
(h-context :uint64) ; UINT_PTR
(sz-card-name (:string :encoding :utf-16le))) ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SCardForgetCardTypeW = Win32::API::More->new('WinSCard',
'int SCardForgetCardTypeW(WPARAM hContext, LPCWSTR szCardName)');
# my $ret = $SCardForgetCardTypeW->Call($hContext, $szCardName);
# hContext : UINT_PTR -> WPARAM
# szCardName : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f SCardForgetCardTypeA (ANSI版) — 登録済みのスマートカード種別を削除する。
- f SCardEstablishContext — スマートカードリソースマネージャーへの接続コンテキストを確立する。
- f SCardForgetReaderW — 登録済みのスマートカードリーダーを削除する。
- f SCardForgetReaderGroupW — 登録済みのリーダーグループをシステムから削除する。
- f SCardIntroduceCardTypeW — 新しいスマートカード種別をシステムに登録する。