ホーム › Security.Credentials › CredUIConfirmCredentialsW
CredUIConfirmCredentialsW
関数入力された資格情報の有効性を確認し保存可否を確定する。
シグネチャ
// credui.dll (Unicode / -W)
#include <windows.h>
DWORD CredUIConfirmCredentialsW(
LPCWSTR pszTargetName,
BOOL bConfirm
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszTargetName | LPCWSTR | in | 資格情報の対象の名前(通常はドメイン名またはサーバーアプリケーション名)を含む、null で終わる文字列へのポインターです。これは CredUIPromptForCredentials または CredUICmdLinePromptForCredentials に pszTargetName として渡した値と同じである必要があります。 |
| bConfirm | BOOL | in | プロンプト関数から返された資格情報が有効かどうかを指定します。TRUE の場合、資格情報は CredUIPromptForCredentials または CredUICmdLinePromptForCredentials で定義されたとおりに資格情報マネージャーに格納されます。FALSE の場合、資格情報は格納されず、各種のメモリがクリーンアップされます。 |
戻り値の型: DWORD
公式ドキュメント
CredUIPromptForCredentials または CredUICmdLinePromptForCredentials の後に呼び出され、取得した資格情報の有効性を確認します。(Unicode)
戻り値
操作の状態が返されます。呼び出し元はこの状態を調べて、資格情報の確認操作が成功したかどうかを判断できます。アプリケーションのリソースへの接続は既に行われているため、ほとんどのアプリケーションはこの状態コードを無視します。操作が失敗するのは、確認待ちの資格情報の一覧に該当する資格情報が見つからなかった場合、または資格情報の書き込みや削除の試行が失敗した場合です。一覧に資格情報が見つからない原因としては、資格情報がそもそもキューに登録されていなかった場合や、キューに登録された資格情報が多すぎた場合が考えられます。キューに登録できる資格情報は最大 5 件で、新しい資格情報がキューに登録されると古いものから破棄されます。
| 戻り値 | 説明 |
|---|---|
|
確認操作が成功しました。 |
| 対象の資格情報が確認待ちの一覧に見つかりませんでした。 | |
| 待機中の資格情報に無効または不整合なデータが含まれていたため、確認の試行が失敗しました。 |
解説(Remarks)
メモ
wincred.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして CredUIConfirmCredentials を定義します。エンコーディング中立のエイリアスを、エンコーディング中立でないコードと混在させて使用すると、不一致が生じてコンパイルエラーまたは実行時エラーを引き起こす可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// credui.dll (Unicode / -W)
#include <windows.h>
DWORD CredUIConfirmCredentialsW(
LPCWSTR pszTargetName,
BOOL bConfirm
);[DllImport("credui.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint CredUIConfirmCredentialsW(
[MarshalAs(UnmanagedType.LPWStr)] string pszTargetName, // LPCWSTR
bool bConfirm // BOOL
);<DllImport("credui.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function CredUIConfirmCredentialsW(
<MarshalAs(UnmanagedType.LPWStr)> pszTargetName As String, ' LPCWSTR
bConfirm As Boolean ' BOOL
) As UInteger
End Function' pszTargetName : LPCWSTR
' bConfirm : BOOL
Declare PtrSafe Function CredUIConfirmCredentialsW Lib "credui" ( _
ByVal pszTargetName As LongPtr, _
ByVal bConfirm As Long) 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
CredUIConfirmCredentialsW = ctypes.windll.credui.CredUIConfirmCredentialsW
CredUIConfirmCredentialsW.restype = wintypes.DWORD
CredUIConfirmCredentialsW.argtypes = [
wintypes.LPCWSTR, # pszTargetName : LPCWSTR
wintypes.BOOL, # bConfirm : BOOL
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('credui.dll')
CredUIConfirmCredentialsW = Fiddle::Function.new(
lib['CredUIConfirmCredentialsW'],
[
Fiddle::TYPE_VOIDP, # pszTargetName : LPCWSTR
Fiddle::TYPE_INT, # bConfirm : BOOL
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "credui")]
extern "system" {
fn CredUIConfirmCredentialsW(
pszTargetName: *const u16, // LPCWSTR
bConfirm: i32 // BOOL
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("credui.dll", CharSet = CharSet.Unicode)]
public static extern uint CredUIConfirmCredentialsW([MarshalAs(UnmanagedType.LPWStr)] string pszTargetName, bool bConfirm);
"@
$api = Add-Type -MemberDefinition $sig -Name 'credui_CredUIConfirmCredentialsW' -Namespace Win32 -PassThru
# $api::CredUIConfirmCredentialsW(pszTargetName, bConfirm)#uselib "credui.dll"
#func global CredUIConfirmCredentialsW "CredUIConfirmCredentialsW" wptr, wptr
; CredUIConfirmCredentialsW pszTargetName, bConfirm ; 戻り値は stat
; pszTargetName : LPCWSTR -> "wptr"
; bConfirm : BOOL -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "credui.dll"
#cfunc global CredUIConfirmCredentialsW "CredUIConfirmCredentialsW" wstr, int
; res = CredUIConfirmCredentialsW(pszTargetName, bConfirm)
; pszTargetName : LPCWSTR -> "wstr"
; bConfirm : BOOL -> "int"; DWORD CredUIConfirmCredentialsW(LPCWSTR pszTargetName, BOOL bConfirm)
#uselib "credui.dll"
#cfunc global CredUIConfirmCredentialsW "CredUIConfirmCredentialsW" wstr, int
; res = CredUIConfirmCredentialsW(pszTargetName, bConfirm)
; pszTargetName : LPCWSTR -> "wstr"
; bConfirm : BOOL -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
credui = windows.NewLazySystemDLL("credui.dll")
procCredUIConfirmCredentialsW = credui.NewProc("CredUIConfirmCredentialsW")
)
// pszTargetName (LPCWSTR), bConfirm (BOOL)
r1, _, err := procCredUIConfirmCredentialsW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszTargetName))),
uintptr(bConfirm),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction CredUIConfirmCredentialsW(
pszTargetName: PWideChar; // LPCWSTR
bConfirm: BOOL // BOOL
): DWORD; stdcall;
external 'credui.dll' name 'CredUIConfirmCredentialsW';result := DllCall("credui\CredUIConfirmCredentialsW"
, "WStr", pszTargetName ; LPCWSTR
, "Int", bConfirm ; BOOL
, "UInt") ; return: DWORD●CredUIConfirmCredentialsW(pszTargetName, bConfirm) = DLL("credui.dll", "dword CredUIConfirmCredentialsW(char*, bool)")
# 呼び出し: CredUIConfirmCredentialsW(pszTargetName, bConfirm)
# pszTargetName : LPCWSTR -> "char*"
# bConfirm : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "credui" fn CredUIConfirmCredentialsW(
pszTargetName: [*c]const u16, // LPCWSTR
bConfirm: i32 // BOOL
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc CredUIConfirmCredentialsW(
pszTargetName: WideCString, # LPCWSTR
bConfirm: int32 # BOOL
): uint32 {.importc: "CredUIConfirmCredentialsW", stdcall, dynlib: "credui.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "credui");
extern(Windows)
uint CredUIConfirmCredentialsW(
const(wchar)* pszTargetName, // LPCWSTR
int bConfirm // BOOL
);ccall((:CredUIConfirmCredentialsW, "credui.dll"), stdcall, UInt32,
(Cwstring, Int32),
pszTargetName, bConfirm)
# pszTargetName : LPCWSTR -> Cwstring
# bConfirm : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t CredUIConfirmCredentialsW(
const uint16_t* pszTargetName,
int32_t bConfirm);
]]
local credui = ffi.load("credui")
-- credui.CredUIConfirmCredentialsW(pszTargetName, bConfirm)
-- pszTargetName : LPCWSTR
-- bConfirm : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('credui.dll');
const CredUIConfirmCredentialsW = lib.func('__stdcall', 'CredUIConfirmCredentialsW', 'uint32_t', ['str16', 'int32_t']);
// CredUIConfirmCredentialsW(pszTargetName, bConfirm)
// pszTargetName : LPCWSTR -> 'str16'
// bConfirm : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("credui.dll", {
CredUIConfirmCredentialsW: { parameters: ["buffer", "i32"], result: "u32" },
});
// lib.symbols.CredUIConfirmCredentialsW(pszTargetName, bConfirm)
// pszTargetName : LPCWSTR -> "buffer"
// bConfirm : BOOL -> "i32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t CredUIConfirmCredentialsW(
const uint16_t* pszTargetName,
int32_t bConfirm);
C, "credui.dll");
// $ffi->CredUIConfirmCredentialsW(pszTargetName, bConfirm);
// pszTargetName : LPCWSTR
// bConfirm : BOOL
// 構造体/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 Credui extends StdCallLibrary {
Credui INSTANCE = Native.load("credui", Credui.class, W32APIOptions.UNICODE_OPTIONS);
int CredUIConfirmCredentialsW(
WString pszTargetName, // LPCWSTR
boolean bConfirm // BOOL
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("credui")]
lib Libcredui
fun CredUIConfirmCredentialsW = CredUIConfirmCredentialsW(
pszTargetName : UInt16*, # LPCWSTR
bConfirm : Int32 # BOOL
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CredUIConfirmCredentialsWNative = Uint32 Function(Pointer<Utf16>, Int32);
typedef CredUIConfirmCredentialsWDart = int Function(Pointer<Utf16>, int);
final CredUIConfirmCredentialsW = DynamicLibrary.open('credui.dll')
.lookupFunction<CredUIConfirmCredentialsWNative, CredUIConfirmCredentialsWDart>('CredUIConfirmCredentialsW');
// pszTargetName : LPCWSTR -> Pointer<Utf16>
// bConfirm : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CredUIConfirmCredentialsW(
pszTargetName: PWideChar; // LPCWSTR
bConfirm: BOOL // BOOL
): DWORD; stdcall;
external 'credui.dll' name 'CredUIConfirmCredentialsW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CredUIConfirmCredentialsW"
c_CredUIConfirmCredentialsW :: CWString -> CInt -> IO Word32
-- pszTargetName : LPCWSTR -> CWString
-- bConfirm : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let creduiconfirmcredentialsw =
foreign "CredUIConfirmCredentialsW"
((ptr uint16_t) @-> int32_t @-> returning uint32_t)
(* pszTargetName : LPCWSTR -> (ptr uint16_t) *)
(* bConfirm : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library credui (t "credui.dll"))
(cffi:use-foreign-library credui)
(cffi:defcfun ("CredUIConfirmCredentialsW" cred-uiconfirm-credentials-w :convention :stdcall) :uint32
(psz-target-name (:string :encoding :utf-16le)) ; LPCWSTR
(b-confirm :int32)) ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CredUIConfirmCredentialsW = Win32::API::More->new('credui',
'DWORD CredUIConfirmCredentialsW(LPCWSTR pszTargetName, BOOL bConfirm)');
# my $ret = $CredUIConfirmCredentialsW->Call($pszTargetName, $bConfirm);
# pszTargetName : LPCWSTR -> LPCWSTR
# bConfirm : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f CredUIConfirmCredentialsA (ANSI版) — 入力された資格情報の有効性を確認し保存可否を確定する。