ホーム › Security.Credentials › CredProtectA
CredProtectA
関数資格情報文字列を暗号化して保護する。
シグネチャ
// ADVAPI32.dll (ANSI / -A)
#include <windows.h>
BOOL CredProtectA(
BOOL fAsSelf,
LPSTR pszCredentials,
DWORD cchCredentials,
LPSTR pszProtectedCredentials,
DWORD* pcchMaxChars,
CRED_PROTECTION_TYPE* ProtectionType // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| fAsSelf | BOOL | in | 資格情報を現在のプロセスのセキュリティコンテキストで暗号化することを指定するには TRUE を設定します。資格情報を呼び出し元スレッドのセキュリティコンテキストで暗号化することを指定するには FALSE を設定します。 |
| pszCredentials | LPSTR | in | 暗号化する資格情報を指定する文字列へのポインターです。この関数は cchCredentials パラメーターで指定された文字数を暗号化します。 |
| cchCredentials | DWORD | in | pszCredentials バッファーのサイズ(文字数)です。 |
| pszProtectedCredentials | LPSTR | out | 出力時に、暗号化された資格情報を受け取る文字列へのポインターです。 |
| pcchMaxChars | DWORD* | inout | pszProtectedCredentials バッファーのサイズ(文字数)です。出力時に、pszProtectedCredentials が暗号化された資格情報を受け取るのに十分なサイズでない場合、このパラメーターは pszProtectedCredentials バッファーに必要なサイズ(文字数)を指定します。 |
| ProtectionType | CRED_PROTECTION_TYPE* | outoptional | 出力時に、提供される保護の種類を指定する CRED_PROTECTION_TYPE 列挙型へのポインターです。 |
戻り値の型: BOOL
公式ドキュメント
指定された資格情報を、現在のセキュリティコンテキストのみが復号できるように暗号化します。(ANSI)
戻り値
関数が成功した場合は TRUE、それ以外の場合は FALSE を返します。
拡張エラー情報を取得するには、 GetLastError 関数を呼び出してください。
解説(Remarks)
CredProtect 関数の出力は整合性が保護されていない点に注意してください。そのため、出力が変更された場合でも CredUnprotect 関数は更新されず、誤った結果を生成する可能性があります。
メモ
wincred.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして CredProtect を定義します。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、コンパイルエラーまたは実行時エラーを引き起こす不一致につながる可能性があります。詳細については、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)
各言語での呼び出し定義
// ADVAPI32.dll (ANSI / -A)
#include <windows.h>
BOOL CredProtectA(
BOOL fAsSelf,
LPSTR pszCredentials,
DWORD cchCredentials,
LPSTR pszProtectedCredentials,
DWORD* pcchMaxChars,
CRED_PROTECTION_TYPE* ProtectionType // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool CredProtectA(
bool fAsSelf, // BOOL
[MarshalAs(UnmanagedType.LPStr)] string pszCredentials, // LPSTR
uint cchCredentials, // DWORD
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszProtectedCredentials, // LPSTR out
ref uint pcchMaxChars, // DWORD* in/out
IntPtr ProtectionType // CRED_PROTECTION_TYPE* optional, out
);<DllImport("ADVAPI32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CredProtectA(
fAsSelf As Boolean, ' BOOL
<MarshalAs(UnmanagedType.LPStr)> pszCredentials As String, ' LPSTR
cchCredentials As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPStr)> pszProtectedCredentials As System.Text.StringBuilder, ' LPSTR out
ByRef pcchMaxChars As UInteger, ' DWORD* in/out
ProtectionType As IntPtr ' CRED_PROTECTION_TYPE* optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' fAsSelf : BOOL
' pszCredentials : LPSTR
' cchCredentials : DWORD
' pszProtectedCredentials : LPSTR out
' pcchMaxChars : DWORD* in/out
' ProtectionType : CRED_PROTECTION_TYPE* optional, out
Declare PtrSafe Function CredProtectA Lib "advapi32" ( _
ByVal fAsSelf As Long, _
ByVal pszCredentials As String, _
ByVal cchCredentials As Long, _
ByVal pszProtectedCredentials As String, _
ByRef pcchMaxChars As Long, _
ByVal ProtectionType As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CredProtectA = ctypes.windll.advapi32.CredProtectA
CredProtectA.restype = wintypes.BOOL
CredProtectA.argtypes = [
wintypes.BOOL, # fAsSelf : BOOL
wintypes.LPCSTR, # pszCredentials : LPSTR
wintypes.DWORD, # cchCredentials : DWORD
wintypes.LPSTR, # pszProtectedCredentials : LPSTR out
ctypes.POINTER(wintypes.DWORD), # pcchMaxChars : DWORD* in/out
ctypes.c_void_p, # ProtectionType : CRED_PROTECTION_TYPE* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
CredProtectA = Fiddle::Function.new(
lib['CredProtectA'],
[
Fiddle::TYPE_INT, # fAsSelf : BOOL
Fiddle::TYPE_VOIDP, # pszCredentials : LPSTR
-Fiddle::TYPE_INT, # cchCredentials : DWORD
Fiddle::TYPE_VOIDP, # pszProtectedCredentials : LPSTR out
Fiddle::TYPE_VOIDP, # pcchMaxChars : DWORD* in/out
Fiddle::TYPE_VOIDP, # ProtectionType : CRED_PROTECTION_TYPE* optional, out
],
Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn CredProtectA(
fAsSelf: i32, // BOOL
pszCredentials: *mut u8, // LPSTR
cchCredentials: u32, // DWORD
pszProtectedCredentials: *mut u8, // LPSTR out
pcchMaxChars: *mut u32, // DWORD* in/out
ProtectionType: *mut i32 // CRED_PROTECTION_TYPE* optional, 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 CredProtectA(bool fAsSelf, [MarshalAs(UnmanagedType.LPStr)] string pszCredentials, uint cchCredentials, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszProtectedCredentials, ref uint pcchMaxChars, IntPtr ProtectionType);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_CredProtectA' -Namespace Win32 -PassThru
# $api::CredProtectA(fAsSelf, pszCredentials, cchCredentials, pszProtectedCredentials, pcchMaxChars, ProtectionType)#uselib "ADVAPI32.dll"
#func global CredProtectA "CredProtectA" sptr, sptr, sptr, sptr, sptr, sptr
; CredProtectA fAsSelf, pszCredentials, cchCredentials, varptr(pszProtectedCredentials), varptr(pcchMaxChars), varptr(ProtectionType) ; 戻り値は stat
; fAsSelf : BOOL -> "sptr"
; pszCredentials : LPSTR -> "sptr"
; cchCredentials : DWORD -> "sptr"
; pszProtectedCredentials : LPSTR out -> "sptr"
; pcchMaxChars : DWORD* in/out -> "sptr"
; ProtectionType : CRED_PROTECTION_TYPE* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ADVAPI32.dll" #cfunc global CredProtectA "CredProtectA" int, str, int, var, var, var ; res = CredProtectA(fAsSelf, pszCredentials, cchCredentials, pszProtectedCredentials, pcchMaxChars, ProtectionType) ; fAsSelf : BOOL -> "int" ; pszCredentials : LPSTR -> "str" ; cchCredentials : DWORD -> "int" ; pszProtectedCredentials : LPSTR out -> "var" ; pcchMaxChars : DWORD* in/out -> "var" ; ProtectionType : CRED_PROTECTION_TYPE* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global CredProtectA "CredProtectA" int, str, int, sptr, sptr, sptr ; res = CredProtectA(fAsSelf, pszCredentials, cchCredentials, varptr(pszProtectedCredentials), varptr(pcchMaxChars), varptr(ProtectionType)) ; fAsSelf : BOOL -> "int" ; pszCredentials : LPSTR -> "str" ; cchCredentials : DWORD -> "int" ; pszProtectedCredentials : LPSTR out -> "sptr" ; pcchMaxChars : DWORD* in/out -> "sptr" ; ProtectionType : CRED_PROTECTION_TYPE* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL CredProtectA(BOOL fAsSelf, LPSTR pszCredentials, DWORD cchCredentials, LPSTR pszProtectedCredentials, DWORD* pcchMaxChars, CRED_PROTECTION_TYPE* ProtectionType) #uselib "ADVAPI32.dll" #cfunc global CredProtectA "CredProtectA" int, str, int, var, var, var ; res = CredProtectA(fAsSelf, pszCredentials, cchCredentials, pszProtectedCredentials, pcchMaxChars, ProtectionType) ; fAsSelf : BOOL -> "int" ; pszCredentials : LPSTR -> "str" ; cchCredentials : DWORD -> "int" ; pszProtectedCredentials : LPSTR out -> "var" ; pcchMaxChars : DWORD* in/out -> "var" ; ProtectionType : CRED_PROTECTION_TYPE* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL CredProtectA(BOOL fAsSelf, LPSTR pszCredentials, DWORD cchCredentials, LPSTR pszProtectedCredentials, DWORD* pcchMaxChars, CRED_PROTECTION_TYPE* ProtectionType) #uselib "ADVAPI32.dll" #cfunc global CredProtectA "CredProtectA" int, str, int, intptr, intptr, intptr ; res = CredProtectA(fAsSelf, pszCredentials, cchCredentials, varptr(pszProtectedCredentials), varptr(pcchMaxChars), varptr(ProtectionType)) ; fAsSelf : BOOL -> "int" ; pszCredentials : LPSTR -> "str" ; cchCredentials : DWORD -> "int" ; pszProtectedCredentials : LPSTR out -> "intptr" ; pcchMaxChars : DWORD* in/out -> "intptr" ; ProtectionType : CRED_PROTECTION_TYPE* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procCredProtectA = advapi32.NewProc("CredProtectA")
)
// fAsSelf (BOOL), pszCredentials (LPSTR), cchCredentials (DWORD), pszProtectedCredentials (LPSTR out), pcchMaxChars (DWORD* in/out), ProtectionType (CRED_PROTECTION_TYPE* optional, out)
r1, _, err := procCredProtectA.Call(
uintptr(fAsSelf),
uintptr(unsafe.Pointer(windows.BytePtrFromString(pszCredentials))),
uintptr(cchCredentials),
uintptr(pszProtectedCredentials),
uintptr(pcchMaxChars),
uintptr(ProtectionType),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CredProtectA(
fAsSelf: BOOL; // BOOL
pszCredentials: PAnsiChar; // LPSTR
cchCredentials: DWORD; // DWORD
pszProtectedCredentials: PAnsiChar; // LPSTR out
pcchMaxChars: Pointer; // DWORD* in/out
ProtectionType: Pointer // CRED_PROTECTION_TYPE* optional, out
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'CredProtectA';result := DllCall("ADVAPI32\CredProtectA"
, "Int", fAsSelf ; BOOL
, "AStr", pszCredentials ; LPSTR
, "UInt", cchCredentials ; DWORD
, "Ptr", pszProtectedCredentials ; LPSTR out
, "Ptr", pcchMaxChars ; DWORD* in/out
, "Ptr", ProtectionType ; CRED_PROTECTION_TYPE* optional, out
, "Int") ; return: BOOL●CredProtectA(fAsSelf, pszCredentials, cchCredentials, pszProtectedCredentials, pcchMaxChars, ProtectionType) = DLL("ADVAPI32.dll", "bool CredProtectA(bool, char*, dword, char*, void*, void*)")
# 呼び出し: CredProtectA(fAsSelf, pszCredentials, cchCredentials, pszProtectedCredentials, pcchMaxChars, ProtectionType)
# fAsSelf : BOOL -> "bool"
# pszCredentials : LPSTR -> "char*"
# cchCredentials : DWORD -> "dword"
# pszProtectedCredentials : LPSTR out -> "char*"
# pcchMaxChars : DWORD* in/out -> "void*"
# ProtectionType : CRED_PROTECTION_TYPE* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "advapi32" fn CredProtectA(
fAsSelf: i32, // BOOL
pszCredentials: [*c]const u8, // LPSTR
cchCredentials: u32, // DWORD
pszProtectedCredentials: [*c]u8, // LPSTR out
pcchMaxChars: [*c]u32, // DWORD* in/out
ProtectionType: [*c]i32 // CRED_PROTECTION_TYPE* optional, out
) callconv(std.os.windows.WINAPI) i32;proc CredProtectA(
fAsSelf: int32, # BOOL
pszCredentials: cstring, # LPSTR
cchCredentials: uint32, # DWORD
pszProtectedCredentials: ptr char, # LPSTR out
pcchMaxChars: ptr uint32, # DWORD* in/out
ProtectionType: ptr int32 # CRED_PROTECTION_TYPE* optional, out
): int32 {.importc: "CredProtectA", stdcall, dynlib: "ADVAPI32.dll".}pragma(lib, "advapi32");
extern(Windows)
int CredProtectA(
int fAsSelf, // BOOL
const(char)* pszCredentials, // LPSTR
uint cchCredentials, // DWORD
char* pszProtectedCredentials, // LPSTR out
uint* pcchMaxChars, // DWORD* in/out
int* ProtectionType // CRED_PROTECTION_TYPE* optional, out
);ccall((:CredProtectA, "ADVAPI32.dll"), stdcall, Int32,
(Int32, Cstring, UInt32, Ptr{UInt8}, Ptr{UInt32}, Ptr{Int32}),
fAsSelf, pszCredentials, cchCredentials, pszProtectedCredentials, pcchMaxChars, ProtectionType)
# fAsSelf : BOOL -> Int32
# pszCredentials : LPSTR -> Cstring
# cchCredentials : DWORD -> UInt32
# pszProtectedCredentials : LPSTR out -> Ptr{UInt8}
# pcchMaxChars : DWORD* in/out -> Ptr{UInt32}
# ProtectionType : CRED_PROTECTION_TYPE* optional, out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CredProtectA(
int32_t fAsSelf,
const char* pszCredentials,
uint32_t cchCredentials,
char* pszProtectedCredentials,
uint32_t* pcchMaxChars,
int32_t* ProtectionType);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.CredProtectA(fAsSelf, pszCredentials, cchCredentials, pszProtectedCredentials, pcchMaxChars, ProtectionType)
-- fAsSelf : BOOL
-- pszCredentials : LPSTR
-- cchCredentials : DWORD
-- pszProtectedCredentials : LPSTR out
-- pcchMaxChars : DWORD* in/out
-- ProtectionType : CRED_PROTECTION_TYPE* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const CredProtectA = lib.func('__stdcall', 'CredProtectA', 'int32_t', ['int32_t', 'str', 'uint32_t', 'char *', 'uint32_t *', 'int32_t *']);
// CredProtectA(fAsSelf, pszCredentials, cchCredentials, pszProtectedCredentials, pcchMaxChars, ProtectionType)
// fAsSelf : BOOL -> 'int32_t'
// pszCredentials : LPSTR -> 'str'
// cchCredentials : DWORD -> 'uint32_t'
// pszProtectedCredentials : LPSTR out -> 'char *'
// pcchMaxChars : DWORD* in/out -> 'uint32_t *'
// ProtectionType : CRED_PROTECTION_TYPE* optional, out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
CredProtectA: { parameters: ["i32", "buffer", "u32", "buffer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.CredProtectA(fAsSelf, pszCredentials, cchCredentials, pszProtectedCredentials, pcchMaxChars, ProtectionType)
// fAsSelf : BOOL -> "i32"
// pszCredentials : LPSTR -> "buffer"
// cchCredentials : DWORD -> "u32"
// pszProtectedCredentials : LPSTR out -> "buffer"
// pcchMaxChars : DWORD* in/out -> "pointer"
// ProtectionType : CRED_PROTECTION_TYPE* optional, out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CredProtectA(
int32_t fAsSelf,
const char* pszCredentials,
uint32_t cchCredentials,
char* pszProtectedCredentials,
uint32_t* pcchMaxChars,
int32_t* ProtectionType);
C, "ADVAPI32.dll");
// $ffi->CredProtectA(fAsSelf, pszCredentials, cchCredentials, pszProtectedCredentials, pcchMaxChars, ProtectionType);
// fAsSelf : BOOL
// pszCredentials : LPSTR
// cchCredentials : DWORD
// pszProtectedCredentials : LPSTR out
// pcchMaxChars : DWORD* in/out
// ProtectionType : CRED_PROTECTION_TYPE* optional, out
// 構造体/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 Advapi32 extends StdCallLibrary {
Advapi32 INSTANCE = Native.load("advapi32", Advapi32.class, W32APIOptions.ASCII_OPTIONS);
boolean CredProtectA(
boolean fAsSelf, // BOOL
String pszCredentials, // LPSTR
int cchCredentials, // DWORD
byte[] pszProtectedCredentials, // LPSTR out
IntByReference pcchMaxChars, // DWORD* in/out
IntByReference ProtectionType // CRED_PROTECTION_TYPE* optional, out
);
}@[Link("advapi32")]
lib LibADVAPI32
fun CredProtectA = CredProtectA(
fAsSelf : Int32, # BOOL
pszCredentials : UInt8*, # LPSTR
cchCredentials : UInt32, # DWORD
pszProtectedCredentials : UInt8*, # LPSTR out
pcchMaxChars : UInt32*, # DWORD* in/out
ProtectionType : Int32* # CRED_PROTECTION_TYPE* optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CredProtectANative = Int32 Function(Int32, Pointer<Utf8>, Uint32, Pointer<Utf8>, Pointer<Uint32>, Pointer<Int32>);
typedef CredProtectADart = int Function(int, Pointer<Utf8>, int, Pointer<Utf8>, Pointer<Uint32>, Pointer<Int32>);
final CredProtectA = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<CredProtectANative, CredProtectADart>('CredProtectA');
// fAsSelf : BOOL -> Int32
// pszCredentials : LPSTR -> Pointer<Utf8>
// cchCredentials : DWORD -> Uint32
// pszProtectedCredentials : LPSTR out -> Pointer<Utf8>
// pcchMaxChars : DWORD* in/out -> Pointer<Uint32>
// ProtectionType : CRED_PROTECTION_TYPE* optional, out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CredProtectA(
fAsSelf: BOOL; // BOOL
pszCredentials: PAnsiChar; // LPSTR
cchCredentials: DWORD; // DWORD
pszProtectedCredentials: PAnsiChar; // LPSTR out
pcchMaxChars: Pointer; // DWORD* in/out
ProtectionType: Pointer // CRED_PROTECTION_TYPE* optional, out
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'CredProtectA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CredProtectA"
c_CredProtectA :: CInt -> CString -> Word32 -> CString -> Ptr Word32 -> Ptr Int32 -> IO CInt
-- fAsSelf : BOOL -> CInt
-- pszCredentials : LPSTR -> CString
-- cchCredentials : DWORD -> Word32
-- pszProtectedCredentials : LPSTR out -> CString
-- pcchMaxChars : DWORD* in/out -> Ptr Word32
-- ProtectionType : CRED_PROTECTION_TYPE* optional, out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let credprotecta =
foreign "CredProtectA"
(int32_t @-> string @-> uint32_t @-> string @-> (ptr uint32_t) @-> (ptr int32_t) @-> returning int32_t)
(* fAsSelf : BOOL -> int32_t *)
(* pszCredentials : LPSTR -> string *)
(* cchCredentials : DWORD -> uint32_t *)
(* pszProtectedCredentials : LPSTR out -> string *)
(* pcchMaxChars : DWORD* in/out -> (ptr uint32_t) *)
(* ProtectionType : CRED_PROTECTION_TYPE* optional, out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)
(cffi:defcfun ("CredProtectA" cred-protect-a :convention :stdcall) :int32
(f-as-self :int32) ; BOOL
(psz-credentials :string) ; LPSTR
(cch-credentials :uint32) ; DWORD
(psz-protected-credentials :pointer) ; LPSTR out
(pcch-max-chars :pointer) ; DWORD* in/out
(protection-type :pointer)) ; CRED_PROTECTION_TYPE* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CredProtectA = Win32::API::More->new('ADVAPI32',
'BOOL CredProtectA(BOOL fAsSelf, LPCSTR pszCredentials, DWORD cchCredentials, LPSTR pszProtectedCredentials, LPVOID pcchMaxChars, LPVOID ProtectionType)');
# my $ret = $CredProtectA->Call($fAsSelf, $pszCredentials, $cchCredentials, $pszProtectedCredentials, $pcchMaxChars, $ProtectionType);
# fAsSelf : BOOL -> BOOL
# pszCredentials : LPSTR -> LPCSTR
# cchCredentials : DWORD -> DWORD
# pszProtectedCredentials : LPSTR out -> LPSTR
# pcchMaxChars : DWORD* in/out -> LPVOID
# ProtectionType : CRED_PROTECTION_TYPE* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f CredProtectW (Unicode版) — 資格情報文字列を暗号化して保護する。