ホーム › Security.Credentials › CredPackAuthenticationBufferA
CredPackAuthenticationBufferA
関数ユーザー名とパスワードを認証バッファにパックする。
シグネチャ
// credui.dll (ANSI / -A)
#include <windows.h>
BOOL CredPackAuthenticationBufferA(
CRED_PACK_FLAGS dwFlags,
LPSTR pszUserName,
LPSTR pszPassword,
BYTE* pPackedCredentials, // optional
DWORD* pcbPackedCredentials
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| dwFlags | CRED_PACK_FLAGS | in |
| pszUserName | LPSTR | in |
| pszPassword | LPSTR | in |
| pPackedCredentials | BYTE* | outoptional |
| pcbPackedCredentials | DWORD* | inout |
戻り値の型: BOOL
各言語での呼び出し定義
// credui.dll (ANSI / -A)
#include <windows.h>
BOOL CredPackAuthenticationBufferA(
CRED_PACK_FLAGS dwFlags,
LPSTR pszUserName,
LPSTR pszPassword,
BYTE* pPackedCredentials, // optional
DWORD* pcbPackedCredentials
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("credui.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool CredPackAuthenticationBufferA(
uint dwFlags, // CRED_PACK_FLAGS
[MarshalAs(UnmanagedType.LPStr)] string pszUserName, // LPSTR
[MarshalAs(UnmanagedType.LPStr)] string pszPassword, // LPSTR
IntPtr pPackedCredentials, // BYTE* optional, out
ref uint pcbPackedCredentials // DWORD* in/out
);<DllImport("credui.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CredPackAuthenticationBufferA(
dwFlags As UInteger, ' CRED_PACK_FLAGS
<MarshalAs(UnmanagedType.LPStr)> pszUserName As String, ' LPSTR
<MarshalAs(UnmanagedType.LPStr)> pszPassword As String, ' LPSTR
pPackedCredentials As IntPtr, ' BYTE* optional, out
ByRef pcbPackedCredentials As UInteger ' DWORD* in/out
) As Boolean
End Function' dwFlags : CRED_PACK_FLAGS
' pszUserName : LPSTR
' pszPassword : LPSTR
' pPackedCredentials : BYTE* optional, out
' pcbPackedCredentials : DWORD* in/out
Declare PtrSafe Function CredPackAuthenticationBufferA Lib "credui" ( _
ByVal dwFlags As Long, _
ByVal pszUserName As String, _
ByVal pszPassword As String, _
ByVal pPackedCredentials As LongPtr, _
ByRef pcbPackedCredentials As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CredPackAuthenticationBufferA = ctypes.windll.credui.CredPackAuthenticationBufferA
CredPackAuthenticationBufferA.restype = wintypes.BOOL
CredPackAuthenticationBufferA.argtypes = [
wintypes.DWORD, # dwFlags : CRED_PACK_FLAGS
wintypes.LPCSTR, # pszUserName : LPSTR
wintypes.LPCSTR, # pszPassword : LPSTR
ctypes.POINTER(ctypes.c_ubyte), # pPackedCredentials : BYTE* optional, out
ctypes.POINTER(wintypes.DWORD), # pcbPackedCredentials : DWORD* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('credui.dll')
CredPackAuthenticationBufferA = Fiddle::Function.new(
lib['CredPackAuthenticationBufferA'],
[
-Fiddle::TYPE_INT, # dwFlags : CRED_PACK_FLAGS
Fiddle::TYPE_VOIDP, # pszUserName : LPSTR
Fiddle::TYPE_VOIDP, # pszPassword : LPSTR
Fiddle::TYPE_VOIDP, # pPackedCredentials : BYTE* optional, out
Fiddle::TYPE_VOIDP, # pcbPackedCredentials : DWORD* in/out
],
Fiddle::TYPE_INT)#[link(name = "credui")]
extern "system" {
fn CredPackAuthenticationBufferA(
dwFlags: u32, // CRED_PACK_FLAGS
pszUserName: *mut u8, // LPSTR
pszPassword: *mut u8, // LPSTR
pPackedCredentials: *mut u8, // BYTE* optional, out
pcbPackedCredentials: *mut u32 // DWORD* in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("credui.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool CredPackAuthenticationBufferA(uint dwFlags, [MarshalAs(UnmanagedType.LPStr)] string pszUserName, [MarshalAs(UnmanagedType.LPStr)] string pszPassword, IntPtr pPackedCredentials, ref uint pcbPackedCredentials);
"@
$api = Add-Type -MemberDefinition $sig -Name 'credui_CredPackAuthenticationBufferA' -Namespace Win32 -PassThru
# $api::CredPackAuthenticationBufferA(dwFlags, pszUserName, pszPassword, pPackedCredentials, pcbPackedCredentials)#uselib "credui.dll"
#func global CredPackAuthenticationBufferA "CredPackAuthenticationBufferA" sptr, sptr, sptr, sptr, sptr
; CredPackAuthenticationBufferA dwFlags, pszUserName, pszPassword, varptr(pPackedCredentials), varptr(pcbPackedCredentials) ; 戻り値は stat
; dwFlags : CRED_PACK_FLAGS -> "sptr"
; pszUserName : LPSTR -> "sptr"
; pszPassword : LPSTR -> "sptr"
; pPackedCredentials : BYTE* optional, out -> "sptr"
; pcbPackedCredentials : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "credui.dll" #cfunc global CredPackAuthenticationBufferA "CredPackAuthenticationBufferA" int, str, str, var, var ; res = CredPackAuthenticationBufferA(dwFlags, pszUserName, pszPassword, pPackedCredentials, pcbPackedCredentials) ; dwFlags : CRED_PACK_FLAGS -> "int" ; pszUserName : LPSTR -> "str" ; pszPassword : LPSTR -> "str" ; pPackedCredentials : BYTE* optional, out -> "var" ; pcbPackedCredentials : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "credui.dll" #cfunc global CredPackAuthenticationBufferA "CredPackAuthenticationBufferA" int, str, str, sptr, sptr ; res = CredPackAuthenticationBufferA(dwFlags, pszUserName, pszPassword, varptr(pPackedCredentials), varptr(pcbPackedCredentials)) ; dwFlags : CRED_PACK_FLAGS -> "int" ; pszUserName : LPSTR -> "str" ; pszPassword : LPSTR -> "str" ; pPackedCredentials : BYTE* optional, out -> "sptr" ; pcbPackedCredentials : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL CredPackAuthenticationBufferA(CRED_PACK_FLAGS dwFlags, LPSTR pszUserName, LPSTR pszPassword, BYTE* pPackedCredentials, DWORD* pcbPackedCredentials) #uselib "credui.dll" #cfunc global CredPackAuthenticationBufferA "CredPackAuthenticationBufferA" int, str, str, var, var ; res = CredPackAuthenticationBufferA(dwFlags, pszUserName, pszPassword, pPackedCredentials, pcbPackedCredentials) ; dwFlags : CRED_PACK_FLAGS -> "int" ; pszUserName : LPSTR -> "str" ; pszPassword : LPSTR -> "str" ; pPackedCredentials : BYTE* optional, out -> "var" ; pcbPackedCredentials : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL CredPackAuthenticationBufferA(CRED_PACK_FLAGS dwFlags, LPSTR pszUserName, LPSTR pszPassword, BYTE* pPackedCredentials, DWORD* pcbPackedCredentials) #uselib "credui.dll" #cfunc global CredPackAuthenticationBufferA "CredPackAuthenticationBufferA" int, str, str, intptr, intptr ; res = CredPackAuthenticationBufferA(dwFlags, pszUserName, pszPassword, varptr(pPackedCredentials), varptr(pcbPackedCredentials)) ; dwFlags : CRED_PACK_FLAGS -> "int" ; pszUserName : LPSTR -> "str" ; pszPassword : LPSTR -> "str" ; pPackedCredentials : BYTE* optional, out -> "intptr" ; pcbPackedCredentials : DWORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
credui = windows.NewLazySystemDLL("credui.dll")
procCredPackAuthenticationBufferA = credui.NewProc("CredPackAuthenticationBufferA")
)
// dwFlags (CRED_PACK_FLAGS), pszUserName (LPSTR), pszPassword (LPSTR), pPackedCredentials (BYTE* optional, out), pcbPackedCredentials (DWORD* in/out)
r1, _, err := procCredPackAuthenticationBufferA.Call(
uintptr(dwFlags),
uintptr(unsafe.Pointer(windows.BytePtrFromString(pszUserName))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(pszPassword))),
uintptr(pPackedCredentials),
uintptr(pcbPackedCredentials),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CredPackAuthenticationBufferA(
dwFlags: DWORD; // CRED_PACK_FLAGS
pszUserName: PAnsiChar; // LPSTR
pszPassword: PAnsiChar; // LPSTR
pPackedCredentials: Pointer; // BYTE* optional, out
pcbPackedCredentials: Pointer // DWORD* in/out
): BOOL; stdcall;
external 'credui.dll' name 'CredPackAuthenticationBufferA';result := DllCall("credui\CredPackAuthenticationBufferA"
, "UInt", dwFlags ; CRED_PACK_FLAGS
, "AStr", pszUserName ; LPSTR
, "AStr", pszPassword ; LPSTR
, "Ptr", pPackedCredentials ; BYTE* optional, out
, "Ptr", pcbPackedCredentials ; DWORD* in/out
, "Int") ; return: BOOL●CredPackAuthenticationBufferA(dwFlags, pszUserName, pszPassword, pPackedCredentials, pcbPackedCredentials) = DLL("credui.dll", "bool CredPackAuthenticationBufferA(dword, char*, char*, void*, void*)")
# 呼び出し: CredPackAuthenticationBufferA(dwFlags, pszUserName, pszPassword, pPackedCredentials, pcbPackedCredentials)
# dwFlags : CRED_PACK_FLAGS -> "dword"
# pszUserName : LPSTR -> "char*"
# pszPassword : LPSTR -> "char*"
# pPackedCredentials : BYTE* optional, out -> "void*"
# pcbPackedCredentials : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。