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

CredUIStoreSSOCredW

関数
シングルサインオン用の資格情報を保存する。
DLLcredui.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

// credui.dll
#include <windows.h>

DWORD CredUIStoreSSOCredW(
    LPCWSTR pszRealm,   // optional
    LPCWSTR pszUsername,
    LPCWSTR pszPassword,
    BOOL bPersist
);

パラメーター

名前方向説明
pszRealmLPCWSTRinoptionalレルムを指定する null 終端文字列へのポインターです。このパラメーターが NULL の場合は、既定のレルムが使用されます。
pszUsernameLPCWSTRinユーザー名を指定する null 終端文字列へのポインターです。
pszPasswordLPCWSTRinユーザーのパスワードを指定する null 終端文字列へのポインターです。パスワードの使用が終わったら、SecureZeroMemory 関数を呼び出してメモリからパスワードを消去してください。パスワードの保護方法の詳細については、Handling Passwords を参照してください。
bPersistBOOLin資格情報を永続化するかどうかを指定するブール値です。この値が TRUE の場合、資格情報は永続化されます。この値が FALSE の場合、資格情報は永続化されません。

戻り値の型: DWORD

公式ドキュメント

CredUIStoreSSOCredW 関数は、単一のログオン資格情報を格納します。

戻り値

戻り値は DWORD です。戻り値が ERROR_SUCCESS の場合は、関数が成功したことを示します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// credui.dll
#include <windows.h>

DWORD CredUIStoreSSOCredW(
    LPCWSTR pszRealm,   // optional
    LPCWSTR pszUsername,
    LPCWSTR pszPassword,
    BOOL bPersist
);
[DllImport("credui.dll", ExactSpelling = true)]
static extern uint CredUIStoreSSOCredW(
    [MarshalAs(UnmanagedType.LPWStr)] string pszRealm,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string pszUsername,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string pszPassword,   // LPCWSTR
    bool bPersist   // BOOL
);
<DllImport("credui.dll", ExactSpelling:=True)>
Public Shared Function CredUIStoreSSOCredW(
    <MarshalAs(UnmanagedType.LPWStr)> pszRealm As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> pszUsername As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> pszPassword As String,   ' LPCWSTR
    bPersist As Boolean   ' BOOL
) As UInteger
End Function
' pszRealm : LPCWSTR optional
' pszUsername : LPCWSTR
' pszPassword : LPCWSTR
' bPersist : BOOL
Declare PtrSafe Function CredUIStoreSSOCredW Lib "credui" ( _
    ByVal pszRealm As LongPtr, _
    ByVal pszUsername As LongPtr, _
    ByVal pszPassword As LongPtr, _
    ByVal bPersist As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CredUIStoreSSOCredW = ctypes.windll.credui.CredUIStoreSSOCredW
CredUIStoreSSOCredW.restype = wintypes.DWORD
CredUIStoreSSOCredW.argtypes = [
    wintypes.LPCWSTR,  # pszRealm : LPCWSTR optional
    wintypes.LPCWSTR,  # pszUsername : LPCWSTR
    wintypes.LPCWSTR,  # pszPassword : LPCWSTR
    wintypes.BOOL,  # bPersist : BOOL
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('credui.dll')
CredUIStoreSSOCredW = Fiddle::Function.new(
  lib['CredUIStoreSSOCredW'],
  [
    Fiddle::TYPE_VOIDP,  # pszRealm : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # pszUsername : LPCWSTR
    Fiddle::TYPE_VOIDP,  # pszPassword : LPCWSTR
    Fiddle::TYPE_INT,  # bPersist : BOOL
  ],
  -Fiddle::TYPE_INT)
#[link(name = "credui")]
extern "system" {
    fn CredUIStoreSSOCredW(
        pszRealm: *const u16,  // LPCWSTR optional
        pszUsername: *const u16,  // LPCWSTR
        pszPassword: *const u16,  // LPCWSTR
        bPersist: i32  // BOOL
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("credui.dll")]
public static extern uint CredUIStoreSSOCredW([MarshalAs(UnmanagedType.LPWStr)] string pszRealm, [MarshalAs(UnmanagedType.LPWStr)] string pszUsername, [MarshalAs(UnmanagedType.LPWStr)] string pszPassword, bool bPersist);
"@
$api = Add-Type -MemberDefinition $sig -Name 'credui_CredUIStoreSSOCredW' -Namespace Win32 -PassThru
# $api::CredUIStoreSSOCredW(pszRealm, pszUsername, pszPassword, bPersist)
#uselib "credui.dll"
#func global CredUIStoreSSOCredW "CredUIStoreSSOCredW" sptr, sptr, sptr, sptr
; CredUIStoreSSOCredW pszRealm, pszUsername, pszPassword, bPersist   ; 戻り値は stat
; pszRealm : LPCWSTR optional -> "sptr"
; pszUsername : LPCWSTR -> "sptr"
; pszPassword : LPCWSTR -> "sptr"
; bPersist : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "credui.dll"
#cfunc global CredUIStoreSSOCredW "CredUIStoreSSOCredW" wstr, wstr, wstr, int
; res = CredUIStoreSSOCredW(pszRealm, pszUsername, pszPassword, bPersist)
; pszRealm : LPCWSTR optional -> "wstr"
; pszUsername : LPCWSTR -> "wstr"
; pszPassword : LPCWSTR -> "wstr"
; bPersist : BOOL -> "int"
; DWORD CredUIStoreSSOCredW(LPCWSTR pszRealm, LPCWSTR pszUsername, LPCWSTR pszPassword, BOOL bPersist)
#uselib "credui.dll"
#cfunc global CredUIStoreSSOCredW "CredUIStoreSSOCredW" wstr, wstr, wstr, int
; res = CredUIStoreSSOCredW(pszRealm, pszUsername, pszPassword, bPersist)
; pszRealm : LPCWSTR optional -> "wstr"
; pszUsername : LPCWSTR -> "wstr"
; pszPassword : LPCWSTR -> "wstr"
; bPersist : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	credui = windows.NewLazySystemDLL("credui.dll")
	procCredUIStoreSSOCredW = credui.NewProc("CredUIStoreSSOCredW")
)

// pszRealm (LPCWSTR optional), pszUsername (LPCWSTR), pszPassword (LPCWSTR), bPersist (BOOL)
r1, _, err := procCredUIStoreSSOCredW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszRealm))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszUsername))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPassword))),
	uintptr(bPersist),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function CredUIStoreSSOCredW(
  pszRealm: PWideChar;   // LPCWSTR optional
  pszUsername: PWideChar;   // LPCWSTR
  pszPassword: PWideChar;   // LPCWSTR
  bPersist: BOOL   // BOOL
): DWORD; stdcall;
  external 'credui.dll' name 'CredUIStoreSSOCredW';
result := DllCall("credui\CredUIStoreSSOCredW"
    , "WStr", pszRealm   ; LPCWSTR optional
    , "WStr", pszUsername   ; LPCWSTR
    , "WStr", pszPassword   ; LPCWSTR
    , "Int", bPersist   ; BOOL
    , "UInt")   ; return: DWORD
●CredUIStoreSSOCredW(pszRealm, pszUsername, pszPassword, bPersist) = DLL("credui.dll", "dword CredUIStoreSSOCredW(char*, char*, char*, bool)")
# 呼び出し: CredUIStoreSSOCredW(pszRealm, pszUsername, pszPassword, bPersist)
# pszRealm : LPCWSTR optional -> "char*"
# pszUsername : LPCWSTR -> "char*"
# pszPassword : LPCWSTR -> "char*"
# bPersist : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "credui" fn CredUIStoreSSOCredW(
    pszRealm: [*c]const u16, // LPCWSTR optional
    pszUsername: [*c]const u16, // LPCWSTR
    pszPassword: [*c]const u16, // LPCWSTR
    bPersist: i32 // BOOL
) callconv(std.os.windows.WINAPI) u32;
proc CredUIStoreSSOCredW(
    pszRealm: WideCString,  # LPCWSTR optional
    pszUsername: WideCString,  # LPCWSTR
    pszPassword: WideCString,  # LPCWSTR
    bPersist: int32  # BOOL
): uint32 {.importc: "CredUIStoreSSOCredW", stdcall, dynlib: "credui.dll".}
pragma(lib, "credui");
extern(Windows)
uint CredUIStoreSSOCredW(
    const(wchar)* pszRealm,   // LPCWSTR optional
    const(wchar)* pszUsername,   // LPCWSTR
    const(wchar)* pszPassword,   // LPCWSTR
    int bPersist   // BOOL
);
ccall((:CredUIStoreSSOCredW, "credui.dll"), stdcall, UInt32,
      (Cwstring, Cwstring, Cwstring, Int32),
      pszRealm, pszUsername, pszPassword, bPersist)
# pszRealm : LPCWSTR optional -> Cwstring
# pszUsername : LPCWSTR -> Cwstring
# pszPassword : LPCWSTR -> Cwstring
# bPersist : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t CredUIStoreSSOCredW(
    const uint16_t* pszRealm,
    const uint16_t* pszUsername,
    const uint16_t* pszPassword,
    int32_t bPersist);
]]
local credui = ffi.load("credui")
-- credui.CredUIStoreSSOCredW(pszRealm, pszUsername, pszPassword, bPersist)
-- pszRealm : LPCWSTR optional
-- pszUsername : LPCWSTR
-- pszPassword : LPCWSTR
-- bPersist : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('credui.dll');
const CredUIStoreSSOCredW = lib.func('__stdcall', 'CredUIStoreSSOCredW', 'uint32_t', ['str16', 'str16', 'str16', 'int32_t']);
// CredUIStoreSSOCredW(pszRealm, pszUsername, pszPassword, bPersist)
// pszRealm : LPCWSTR optional -> 'str16'
// pszUsername : LPCWSTR -> 'str16'
// pszPassword : LPCWSTR -> 'str16'
// bPersist : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("credui.dll", {
  CredUIStoreSSOCredW: { parameters: ["buffer", "buffer", "buffer", "i32"], result: "u32" },
});
// lib.symbols.CredUIStoreSSOCredW(pszRealm, pszUsername, pszPassword, bPersist)
// pszRealm : LPCWSTR optional -> "buffer"
// pszUsername : LPCWSTR -> "buffer"
// pszPassword : LPCWSTR -> "buffer"
// bPersist : BOOL -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t CredUIStoreSSOCredW(
    const uint16_t* pszRealm,
    const uint16_t* pszUsername,
    const uint16_t* pszPassword,
    int32_t bPersist);
C, "credui.dll");
// $ffi->CredUIStoreSSOCredW(pszRealm, pszUsername, pszPassword, bPersist);
// pszRealm : LPCWSTR optional
// pszUsername : LPCWSTR
// pszPassword : LPCWSTR
// bPersist : 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);
    int CredUIStoreSSOCredW(
        WString pszRealm,   // LPCWSTR optional
        WString pszUsername,   // LPCWSTR
        WString pszPassword,   // LPCWSTR
        boolean bPersist   // BOOL
    );
}
@[Link("credui")]
lib Libcredui
  fun CredUIStoreSSOCredW = CredUIStoreSSOCredW(
    pszRealm : UInt16*,   # LPCWSTR optional
    pszUsername : UInt16*,   # LPCWSTR
    pszPassword : UInt16*,   # LPCWSTR
    bPersist : 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 CredUIStoreSSOCredWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Int32);
typedef CredUIStoreSSOCredWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, int);
final CredUIStoreSSOCredW = DynamicLibrary.open('credui.dll')
    .lookupFunction<CredUIStoreSSOCredWNative, CredUIStoreSSOCredWDart>('CredUIStoreSSOCredW');
// pszRealm : LPCWSTR optional -> Pointer<Utf16>
// pszUsername : LPCWSTR -> Pointer<Utf16>
// pszPassword : LPCWSTR -> Pointer<Utf16>
// bPersist : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CredUIStoreSSOCredW(
  pszRealm: PWideChar;   // LPCWSTR optional
  pszUsername: PWideChar;   // LPCWSTR
  pszPassword: PWideChar;   // LPCWSTR
  bPersist: BOOL   // BOOL
): DWORD; stdcall;
  external 'credui.dll' name 'CredUIStoreSSOCredW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CredUIStoreSSOCredW"
  c_CredUIStoreSSOCredW :: CWString -> CWString -> CWString -> CInt -> IO Word32
-- pszRealm : LPCWSTR optional -> CWString
-- pszUsername : LPCWSTR -> CWString
-- pszPassword : LPCWSTR -> CWString
-- bPersist : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let creduistoressocredw =
  foreign "CredUIStoreSSOCredW"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> int32_t @-> returning uint32_t)
(* pszRealm : LPCWSTR optional -> (ptr uint16_t) *)
(* pszUsername : LPCWSTR -> (ptr uint16_t) *)
(* pszPassword : LPCWSTR -> (ptr uint16_t) *)
(* bPersist : 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 ("CredUIStoreSSOCredW" cred-uistore-ssocred-w :convention :stdcall) :uint32
  (psz-realm (:string :encoding :utf-16le))   ; LPCWSTR optional
  (psz-username (:string :encoding :utf-16le))   ; LPCWSTR
  (psz-password (:string :encoding :utf-16le))   ; LPCWSTR
  (b-persist :int32))   ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CredUIStoreSSOCredW = Win32::API::More->new('credui',
    'DWORD CredUIStoreSSOCredW(LPCWSTR pszRealm, LPCWSTR pszUsername, LPCWSTR pszPassword, BOOL bPersist)');
# my $ret = $CredUIStoreSSOCredW->Call($pszRealm, $pszUsername, $pszPassword, $bPersist);
# pszRealm : LPCWSTR optional -> LPCWSTR
# pszUsername : LPCWSTR -> LPCWSTR
# pszPassword : LPCWSTR -> LPCWSTR
# bPersist : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目