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

CredReadDomainCredentialsW

関数
対象情報に一致するドメイン資格情報を読み取る。
DLLADVAPI32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL CredReadDomainCredentialsW(
    CREDENTIAL_TARGET_INFORMATIONW* TargetInfo,
    DWORD Flags,
    DWORD* Count,
    CREDENTIALW*** Credential
);

パラメーター

名前方向
TargetInfoCREDENTIAL_TARGET_INFORMATIONW*in
FlagsDWORDin
CountDWORD*out
CredentialCREDENTIALW***out

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL CredReadDomainCredentialsW(
    CREDENTIAL_TARGET_INFORMATIONW* TargetInfo,
    DWORD Flags,
    DWORD* Count,
    CREDENTIALW*** Credential
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool CredReadDomainCredentialsW(
    IntPtr TargetInfo,   // CREDENTIAL_TARGET_INFORMATIONW*
    uint Flags,   // DWORD
    out uint Count,   // DWORD* out
    IntPtr Credential   // CREDENTIALW*** out
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CredReadDomainCredentialsW(
    TargetInfo As IntPtr,   ' CREDENTIAL_TARGET_INFORMATIONW*
    Flags As UInteger,   ' DWORD
    <Out> ByRef Count As UInteger,   ' DWORD* out
    Credential As IntPtr   ' CREDENTIALW*** out
) As Boolean
End Function
' TargetInfo : CREDENTIAL_TARGET_INFORMATIONW*
' Flags : DWORD
' Count : DWORD* out
' Credential : CREDENTIALW*** out
Declare PtrSafe Function CredReadDomainCredentialsW Lib "advapi32" ( _
    ByVal TargetInfo As LongPtr, _
    ByVal Flags As Long, _
    ByRef Count As Long, _
    ByVal Credential 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

CredReadDomainCredentialsW = ctypes.windll.advapi32.CredReadDomainCredentialsW
CredReadDomainCredentialsW.restype = wintypes.BOOL
CredReadDomainCredentialsW.argtypes = [
    ctypes.c_void_p,  # TargetInfo : CREDENTIAL_TARGET_INFORMATIONW*
    wintypes.DWORD,  # Flags : DWORD
    ctypes.POINTER(wintypes.DWORD),  # Count : DWORD* out
    ctypes.c_void_p,  # Credential : CREDENTIALW*** out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
CredReadDomainCredentialsW = Fiddle::Function.new(
  lib['CredReadDomainCredentialsW'],
  [
    Fiddle::TYPE_VOIDP,  # TargetInfo : CREDENTIAL_TARGET_INFORMATIONW*
    -Fiddle::TYPE_INT,  # Flags : DWORD
    Fiddle::TYPE_VOIDP,  # Count : DWORD* out
    Fiddle::TYPE_VOIDP,  # Credential : CREDENTIALW*** out
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "advapi32")]
extern "system" {
    fn CredReadDomainCredentialsW(
        TargetInfo: *mut CREDENTIAL_TARGET_INFORMATIONW,  // CREDENTIAL_TARGET_INFORMATIONW*
        Flags: u32,  // DWORD
        Count: *mut u32,  // DWORD* out
        Credential: *mut *mut *mut CREDENTIALW  // CREDENTIALW*** out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool CredReadDomainCredentialsW(IntPtr TargetInfo, uint Flags, out uint Count, IntPtr Credential);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_CredReadDomainCredentialsW' -Namespace Win32 -PassThru
# $api::CredReadDomainCredentialsW(TargetInfo, Flags, Count, Credential)
#uselib "ADVAPI32.dll"
#func global CredReadDomainCredentialsW "CredReadDomainCredentialsW" wptr, wptr, wptr, wptr
; CredReadDomainCredentialsW varptr(TargetInfo), Flags, varptr(Count), varptr(Credential)   ; 戻り値は stat
; TargetInfo : CREDENTIAL_TARGET_INFORMATIONW* -> "wptr"
; Flags : DWORD -> "wptr"
; Count : DWORD* out -> "wptr"
; Credential : CREDENTIALW*** out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global CredReadDomainCredentialsW "CredReadDomainCredentialsW" var, int, var, var
; res = CredReadDomainCredentialsW(TargetInfo, Flags, Count, Credential)
; TargetInfo : CREDENTIAL_TARGET_INFORMATIONW* -> "var"
; Flags : DWORD -> "int"
; Count : DWORD* out -> "var"
; Credential : CREDENTIALW*** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL CredReadDomainCredentialsW(CREDENTIAL_TARGET_INFORMATIONW* TargetInfo, DWORD Flags, DWORD* Count, CREDENTIALW*** Credential)
#uselib "ADVAPI32.dll"
#cfunc global CredReadDomainCredentialsW "CredReadDomainCredentialsW" var, int, var, var
; res = CredReadDomainCredentialsW(TargetInfo, Flags, Count, Credential)
; TargetInfo : CREDENTIAL_TARGET_INFORMATIONW* -> "var"
; Flags : DWORD -> "int"
; Count : DWORD* out -> "var"
; Credential : CREDENTIALW*** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procCredReadDomainCredentialsW = advapi32.NewProc("CredReadDomainCredentialsW")
)

// TargetInfo (CREDENTIAL_TARGET_INFORMATIONW*), Flags (DWORD), Count (DWORD* out), Credential (CREDENTIALW*** out)
r1, _, err := procCredReadDomainCredentialsW.Call(
	uintptr(TargetInfo),
	uintptr(Flags),
	uintptr(Count),
	uintptr(Credential),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function CredReadDomainCredentialsW(
  TargetInfo: Pointer;   // CREDENTIAL_TARGET_INFORMATIONW*
  Flags: DWORD;   // DWORD
  Count: Pointer;   // DWORD* out
  Credential: Pointer   // CREDENTIALW*** out
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'CredReadDomainCredentialsW';
result := DllCall("ADVAPI32\CredReadDomainCredentialsW"
    , "Ptr", TargetInfo   ; CREDENTIAL_TARGET_INFORMATIONW*
    , "UInt", Flags   ; DWORD
    , "Ptr", Count   ; DWORD* out
    , "Ptr", Credential   ; CREDENTIALW*** out
    , "Int")   ; return: BOOL
●CredReadDomainCredentialsW(TargetInfo, Flags, Count, Credential) = DLL("ADVAPI32.dll", "bool CredReadDomainCredentialsW(void*, dword, void*, void*)")
# 呼び出し: CredReadDomainCredentialsW(TargetInfo, Flags, Count, Credential)
# TargetInfo : CREDENTIAL_TARGET_INFORMATIONW* -> "void*"
# Flags : DWORD -> "dword"
# Count : DWORD* out -> "void*"
# Credential : CREDENTIALW*** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。