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

CredUnprotectA

関数
保護された資格情報文字列を復号する。
DLLADVAPI32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

// ADVAPI32.dll  (ANSI / -A)
#include <windows.h>

BOOL CredUnprotectA(
    BOOL fAsSelf,
    LPSTR pszProtectedCredentials,
    DWORD cchProtectedCredentials,
    LPSTR pszCredentials,   // optional
    DWORD* pcchMaxChars
);

パラメーター

名前方向
fAsSelfBOOLin
pszProtectedCredentialsLPSTRin
cchProtectedCredentialsDWORDin
pszCredentialsLPSTRoutoptional
pcchMaxCharsDWORD*inout

戻り値の型: BOOL

各言語での呼び出し定義

// ADVAPI32.dll  (ANSI / -A)
#include <windows.h>

BOOL CredUnprotectA(
    BOOL fAsSelf,
    LPSTR pszProtectedCredentials,
    DWORD cchProtectedCredentials,
    LPSTR pszCredentials,   // optional
    DWORD* pcchMaxChars
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool CredUnprotectA(
    bool fAsSelf,   // BOOL
    [MarshalAs(UnmanagedType.LPStr)] string pszProtectedCredentials,   // LPSTR
    uint cchProtectedCredentials,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszCredentials,   // LPSTR optional, out
    ref uint pcchMaxChars   // DWORD* in/out
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CredUnprotectA(
    fAsSelf As Boolean,   ' BOOL
    <MarshalAs(UnmanagedType.LPStr)> pszProtectedCredentials As String,   ' LPSTR
    cchProtectedCredentials As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> pszCredentials As System.Text.StringBuilder,   ' LPSTR optional, out
    ByRef pcchMaxChars As UInteger   ' DWORD* in/out
) As Boolean
End Function
' fAsSelf : BOOL
' pszProtectedCredentials : LPSTR
' cchProtectedCredentials : DWORD
' pszCredentials : LPSTR optional, out
' pcchMaxChars : DWORD* in/out
Declare PtrSafe Function CredUnprotectA Lib "advapi32" ( _
    ByVal fAsSelf As Long, _
    ByVal pszProtectedCredentials As String, _
    ByVal cchProtectedCredentials As Long, _
    ByVal pszCredentials As String, _
    ByRef pcchMaxChars As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CredUnprotectA = ctypes.windll.advapi32.CredUnprotectA
CredUnprotectA.restype = wintypes.BOOL
CredUnprotectA.argtypes = [
    wintypes.BOOL,  # fAsSelf : BOOL
    wintypes.LPCSTR,  # pszProtectedCredentials : LPSTR
    wintypes.DWORD,  # cchProtectedCredentials : DWORD
    wintypes.LPSTR,  # pszCredentials : LPSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcchMaxChars : DWORD* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
CredUnprotectA = Fiddle::Function.new(
  lib['CredUnprotectA'],
  [
    Fiddle::TYPE_INT,  # fAsSelf : BOOL
    Fiddle::TYPE_VOIDP,  # pszProtectedCredentials : LPSTR
    -Fiddle::TYPE_INT,  # cchProtectedCredentials : DWORD
    Fiddle::TYPE_VOIDP,  # pszCredentials : LPSTR optional, out
    Fiddle::TYPE_VOIDP,  # pcchMaxChars : DWORD* in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn CredUnprotectA(
        fAsSelf: i32,  // BOOL
        pszProtectedCredentials: *mut u8,  // LPSTR
        cchProtectedCredentials: u32,  // DWORD
        pszCredentials: *mut u8,  // LPSTR optional, out
        pcchMaxChars: *mut u32  // DWORD* in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool CredUnprotectA(bool fAsSelf, [MarshalAs(UnmanagedType.LPStr)] string pszProtectedCredentials, uint cchProtectedCredentials, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszCredentials, ref uint pcchMaxChars);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_CredUnprotectA' -Namespace Win32 -PassThru
# $api::CredUnprotectA(fAsSelf, pszProtectedCredentials, cchProtectedCredentials, pszCredentials, pcchMaxChars)
#uselib "ADVAPI32.dll"
#func global CredUnprotectA "CredUnprotectA" sptr, sptr, sptr, sptr, sptr
; CredUnprotectA fAsSelf, pszProtectedCredentials, cchProtectedCredentials, varptr(pszCredentials), varptr(pcchMaxChars)   ; 戻り値は stat
; fAsSelf : BOOL -> "sptr"
; pszProtectedCredentials : LPSTR -> "sptr"
; cchProtectedCredentials : DWORD -> "sptr"
; pszCredentials : LPSTR optional, out -> "sptr"
; pcchMaxChars : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global CredUnprotectA "CredUnprotectA" int, str, int, var, var
; res = CredUnprotectA(fAsSelf, pszProtectedCredentials, cchProtectedCredentials, pszCredentials, pcchMaxChars)
; fAsSelf : BOOL -> "int"
; pszProtectedCredentials : LPSTR -> "str"
; cchProtectedCredentials : DWORD -> "int"
; pszCredentials : LPSTR optional, out -> "var"
; pcchMaxChars : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL CredUnprotectA(BOOL fAsSelf, LPSTR pszProtectedCredentials, DWORD cchProtectedCredentials, LPSTR pszCredentials, DWORD* pcchMaxChars)
#uselib "ADVAPI32.dll"
#cfunc global CredUnprotectA "CredUnprotectA" int, str, int, var, var
; res = CredUnprotectA(fAsSelf, pszProtectedCredentials, cchProtectedCredentials, pszCredentials, pcchMaxChars)
; fAsSelf : BOOL -> "int"
; pszProtectedCredentials : LPSTR -> "str"
; cchProtectedCredentials : DWORD -> "int"
; pszCredentials : LPSTR optional, out -> "var"
; pcchMaxChars : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procCredUnprotectA = advapi32.NewProc("CredUnprotectA")
)

// fAsSelf (BOOL), pszProtectedCredentials (LPSTR), cchProtectedCredentials (DWORD), pszCredentials (LPSTR optional, out), pcchMaxChars (DWORD* in/out)
r1, _, err := procCredUnprotectA.Call(
	uintptr(fAsSelf),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pszProtectedCredentials))),
	uintptr(cchProtectedCredentials),
	uintptr(pszCredentials),
	uintptr(pcchMaxChars),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function CredUnprotectA(
  fAsSelf: BOOL;   // BOOL
  pszProtectedCredentials: PAnsiChar;   // LPSTR
  cchProtectedCredentials: DWORD;   // DWORD
  pszCredentials: PAnsiChar;   // LPSTR optional, out
  pcchMaxChars: Pointer   // DWORD* in/out
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'CredUnprotectA';
result := DllCall("ADVAPI32\CredUnprotectA"
    , "Int", fAsSelf   ; BOOL
    , "AStr", pszProtectedCredentials   ; LPSTR
    , "UInt", cchProtectedCredentials   ; DWORD
    , "Ptr", pszCredentials   ; LPSTR optional, out
    , "Ptr", pcchMaxChars   ; DWORD* in/out
    , "Int")   ; return: BOOL
●CredUnprotectA(fAsSelf, pszProtectedCredentials, cchProtectedCredentials, pszCredentials, pcchMaxChars) = DLL("ADVAPI32.dll", "bool CredUnprotectA(bool, char*, dword, char*, void*)")
# 呼び出し: CredUnprotectA(fAsSelf, pszProtectedCredentials, cchProtectedCredentials, pszCredentials, pcchMaxChars)
# fAsSelf : BOOL -> "bool"
# pszProtectedCredentials : LPSTR -> "char*"
# cchProtectedCredentials : DWORD -> "dword"
# pszCredentials : LPSTR optional, out -> "char*"
# pcchMaxChars : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。