CredPackAuthenticationBufferW
関数シグネチャ
// credui.dll (Unicode / -W)
#include <windows.h>
BOOL CredPackAuthenticationBufferW(
CRED_PACK_FLAGS dwFlags,
LPWSTR pszUserName,
LPWSTR pszPassword,
BYTE* pPackedCredentials, // optional
DWORD* pcbPackedCredentials
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| dwFlags | CRED_PACK_FLAGS | in | 資格情報をどのようにパックするかを指定します。次のフラグの組み合わせを指定できます。
| ||||||||||
| pszUserName | LPWSTR | in | 変換するユーザー名を指定する null 終端文字列へのポインターです。ドメイン ユーザーの場合、文字列は次の形式である必要があります。 DomainName\UserName オンライン ID の場合、資格情報がプレーンテキストのパスワードであれば、ユーザー名の形式は ProviderName\UserName です。資格情報が SEC_WINNT_AUTH_IDENTITY_EX2 構造体の場合、ユーザー名は SspiEncodeAuthIdentityAsStrings 関数の呼び出しによって出力された UserName パラメーターであるエンコードされた文字列です。 スマート カードまたは証明書の資格情報の場合、ユーザー名は CertCredential オプションを指定した CredMarshalCredential 関数の呼び出しによって出力されたエンコードされた文字列です。 Windows Server 2008 R2、Windows 7、Windows Server 2008、Windows Vista: オンライン ID はサポートされていません。 | ||||||||||
| pszPassword | LPWSTR | in | 変換するパスワードを指定する null 終端文字列へのポインターです。 SEC_WINNT_AUTH_IDENTITY_EX2 資格情報の場合、パスワードは SspiEncodeAuthIdentityAsStrings 関数の呼び出しの ppszPackedCredentialsString 出力に含まれるエンコードされた文字列です。 スマート カードの資格情報の場合、これはスマート カードの PIN です。 Windows Server 2008 R2、Windows 7、Windows Server 2008、Windows Vista: オンライン ID はサポートされていません。 | ||||||||||
| pPackedCredentials | BYTE* | outoptional | 出力時にパックされた認証バッファーを受け取るバイト配列へのポインターです。このパラメーターに NULL を指定すると、必要なバッファー サイズを pcbPackedCredentials パラメーターで受け取ることができます。 | ||||||||||
| pcbPackedCredentials | DWORD* | inout | pPackedCredentials バッファーのサイズ (バイト単位) を指定する DWORD 値へのポインターです。出力時、バッファーのサイズが不足している場合は、pPackedCredentials バッファーに必要なサイズ (バイト単位) を指定します。 |
戻り値の型: BOOL
公式ドキュメント
文字列形式のユーザー名とパスワードを認証バッファーに変換します。(Unicode)
戻り値
関数が成功した場合は TRUE、それ以外の場合は FALSE を返します。
拡張エラー情報を取得するには、 GetLastError 関数を呼び出します。この関数は次のエラー コードを返す場合があります。
| 戻り値 | 説明 |
|---|---|
| pPackedCredentials で指定されたバッファーが小さすぎます。 |
解説(Remarks)
wincred.h ヘッダーは CredPackAuthenticationBuffer をエイリアスとして定義しており、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択します。エンコーディングに依存しないエイリアスの使用と、エンコーディングに依存しないコードではないコードを混在させると、コンパイル エラーや実行時エラーの原因となる不一致が生じる可能性があります。詳細については、「関数プロトタイプの規則」を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// credui.dll (Unicode / -W)
#include <windows.h>
BOOL CredPackAuthenticationBufferW(
CRED_PACK_FLAGS dwFlags,
LPWSTR pszUserName,
LPWSTR pszPassword,
BYTE* pPackedCredentials, // optional
DWORD* pcbPackedCredentials
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("credui.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool CredPackAuthenticationBufferW(
uint dwFlags, // CRED_PACK_FLAGS
[MarshalAs(UnmanagedType.LPWStr)] string pszUserName, // LPWSTR
[MarshalAs(UnmanagedType.LPWStr)] string pszPassword, // LPWSTR
IntPtr pPackedCredentials, // BYTE* optional, out
ref uint pcbPackedCredentials // DWORD* in/out
);<DllImport("credui.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CredPackAuthenticationBufferW(
dwFlags As UInteger, ' CRED_PACK_FLAGS
<MarshalAs(UnmanagedType.LPWStr)> pszUserName As String, ' LPWSTR
<MarshalAs(UnmanagedType.LPWStr)> pszPassword As String, ' LPWSTR
pPackedCredentials As IntPtr, ' BYTE* optional, out
ByRef pcbPackedCredentials As UInteger ' DWORD* in/out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' dwFlags : CRED_PACK_FLAGS
' pszUserName : LPWSTR
' pszPassword : LPWSTR
' pPackedCredentials : BYTE* optional, out
' pcbPackedCredentials : DWORD* in/out
Declare PtrSafe Function CredPackAuthenticationBufferW Lib "credui" ( _
ByVal dwFlags As Long, _
ByVal pszUserName As LongPtr, _
ByVal pszPassword As LongPtr, _
ByVal pPackedCredentials As LongPtr, _
ByRef pcbPackedCredentials As Long) 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
CredPackAuthenticationBufferW = ctypes.windll.credui.CredPackAuthenticationBufferW
CredPackAuthenticationBufferW.restype = wintypes.BOOL
CredPackAuthenticationBufferW.argtypes = [
wintypes.DWORD, # dwFlags : CRED_PACK_FLAGS
wintypes.LPCWSTR, # pszUserName : LPWSTR
wintypes.LPCWSTR, # pszPassword : LPWSTR
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')
CredPackAuthenticationBufferW = Fiddle::Function.new(
lib['CredPackAuthenticationBufferW'],
[
-Fiddle::TYPE_INT, # dwFlags : CRED_PACK_FLAGS
Fiddle::TYPE_VOIDP, # pszUserName : LPWSTR
Fiddle::TYPE_VOIDP, # pszPassword : LPWSTR
Fiddle::TYPE_VOIDP, # pPackedCredentials : BYTE* optional, out
Fiddle::TYPE_VOIDP, # pcbPackedCredentials : DWORD* in/out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "credui")]
extern "system" {
fn CredPackAuthenticationBufferW(
dwFlags: u32, // CRED_PACK_FLAGS
pszUserName: *mut u16, // LPWSTR
pszPassword: *mut u16, // LPWSTR
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.Unicode, SetLastError = true)]
public static extern bool CredPackAuthenticationBufferW(uint dwFlags, [MarshalAs(UnmanagedType.LPWStr)] string pszUserName, [MarshalAs(UnmanagedType.LPWStr)] string pszPassword, IntPtr pPackedCredentials, ref uint pcbPackedCredentials);
"@
$api = Add-Type -MemberDefinition $sig -Name 'credui_CredPackAuthenticationBufferW' -Namespace Win32 -PassThru
# $api::CredPackAuthenticationBufferW(dwFlags, pszUserName, pszPassword, pPackedCredentials, pcbPackedCredentials)#uselib "credui.dll"
#func global CredPackAuthenticationBufferW "CredPackAuthenticationBufferW" wptr, wptr, wptr, wptr, wptr
; CredPackAuthenticationBufferW dwFlags, pszUserName, pszPassword, varptr(pPackedCredentials), varptr(pcbPackedCredentials) ; 戻り値は stat
; dwFlags : CRED_PACK_FLAGS -> "wptr"
; pszUserName : LPWSTR -> "wptr"
; pszPassword : LPWSTR -> "wptr"
; pPackedCredentials : BYTE* optional, out -> "wptr"
; pcbPackedCredentials : DWORD* in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "credui.dll" #cfunc global CredPackAuthenticationBufferW "CredPackAuthenticationBufferW" int, wstr, wstr, var, var ; res = CredPackAuthenticationBufferW(dwFlags, pszUserName, pszPassword, pPackedCredentials, pcbPackedCredentials) ; dwFlags : CRED_PACK_FLAGS -> "int" ; pszUserName : LPWSTR -> "wstr" ; pszPassword : LPWSTR -> "wstr" ; pPackedCredentials : BYTE* optional, out -> "var" ; pcbPackedCredentials : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "credui.dll" #cfunc global CredPackAuthenticationBufferW "CredPackAuthenticationBufferW" int, wstr, wstr, sptr, sptr ; res = CredPackAuthenticationBufferW(dwFlags, pszUserName, pszPassword, varptr(pPackedCredentials), varptr(pcbPackedCredentials)) ; dwFlags : CRED_PACK_FLAGS -> "int" ; pszUserName : LPWSTR -> "wstr" ; pszPassword : LPWSTR -> "wstr" ; pPackedCredentials : BYTE* optional, out -> "sptr" ; pcbPackedCredentials : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; BOOL CredPackAuthenticationBufferW(CRED_PACK_FLAGS dwFlags, LPWSTR pszUserName, LPWSTR pszPassword, BYTE* pPackedCredentials, DWORD* pcbPackedCredentials) #uselib "credui.dll" #cfunc global CredPackAuthenticationBufferW "CredPackAuthenticationBufferW" int, wstr, wstr, var, var ; res = CredPackAuthenticationBufferW(dwFlags, pszUserName, pszPassword, pPackedCredentials, pcbPackedCredentials) ; dwFlags : CRED_PACK_FLAGS -> "int" ; pszUserName : LPWSTR -> "wstr" ; pszPassword : LPWSTR -> "wstr" ; pPackedCredentials : BYTE* optional, out -> "var" ; pcbPackedCredentials : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL CredPackAuthenticationBufferW(CRED_PACK_FLAGS dwFlags, LPWSTR pszUserName, LPWSTR pszPassword, BYTE* pPackedCredentials, DWORD* pcbPackedCredentials) #uselib "credui.dll" #cfunc global CredPackAuthenticationBufferW "CredPackAuthenticationBufferW" int, wstr, wstr, intptr, intptr ; res = CredPackAuthenticationBufferW(dwFlags, pszUserName, pszPassword, varptr(pPackedCredentials), varptr(pcbPackedCredentials)) ; dwFlags : CRED_PACK_FLAGS -> "int" ; pszUserName : LPWSTR -> "wstr" ; pszPassword : LPWSTR -> "wstr" ; 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")
procCredPackAuthenticationBufferW = credui.NewProc("CredPackAuthenticationBufferW")
)
// dwFlags (CRED_PACK_FLAGS), pszUserName (LPWSTR), pszPassword (LPWSTR), pPackedCredentials (BYTE* optional, out), pcbPackedCredentials (DWORD* in/out)
r1, _, err := procCredPackAuthenticationBufferW.Call(
uintptr(dwFlags),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszUserName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPassword))),
uintptr(pPackedCredentials),
uintptr(pcbPackedCredentials),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CredPackAuthenticationBufferW(
dwFlags: DWORD; // CRED_PACK_FLAGS
pszUserName: PWideChar; // LPWSTR
pszPassword: PWideChar; // LPWSTR
pPackedCredentials: Pointer; // BYTE* optional, out
pcbPackedCredentials: Pointer // DWORD* in/out
): BOOL; stdcall;
external 'credui.dll' name 'CredPackAuthenticationBufferW';result := DllCall("credui\CredPackAuthenticationBufferW"
, "UInt", dwFlags ; CRED_PACK_FLAGS
, "WStr", pszUserName ; LPWSTR
, "WStr", pszPassword ; LPWSTR
, "Ptr", pPackedCredentials ; BYTE* optional, out
, "Ptr", pcbPackedCredentials ; DWORD* in/out
, "Int") ; return: BOOL●CredPackAuthenticationBufferW(dwFlags, pszUserName, pszPassword, pPackedCredentials, pcbPackedCredentials) = DLL("credui.dll", "bool CredPackAuthenticationBufferW(dword, char*, char*, void*, void*)")
# 呼び出し: CredPackAuthenticationBufferW(dwFlags, pszUserName, pszPassword, pPackedCredentials, pcbPackedCredentials)
# dwFlags : CRED_PACK_FLAGS -> "dword"
# pszUserName : LPWSTR -> "char*"
# pszPassword : LPWSTR -> "char*"
# pPackedCredentials : BYTE* optional, out -> "void*"
# pcbPackedCredentials : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "credui" fn CredPackAuthenticationBufferW(
dwFlags: u32, // CRED_PACK_FLAGS
pszUserName: [*c]const u16, // LPWSTR
pszPassword: [*c]const u16, // LPWSTR
pPackedCredentials: [*c]u8, // BYTE* optional, out
pcbPackedCredentials: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc CredPackAuthenticationBufferW(
dwFlags: uint32, # CRED_PACK_FLAGS
pszUserName: WideCString, # LPWSTR
pszPassword: WideCString, # LPWSTR
pPackedCredentials: ptr uint8, # BYTE* optional, out
pcbPackedCredentials: ptr uint32 # DWORD* in/out
): int32 {.importc: "CredPackAuthenticationBufferW", stdcall, dynlib: "credui.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "credui");
extern(Windows)
int CredPackAuthenticationBufferW(
uint dwFlags, // CRED_PACK_FLAGS
const(wchar)* pszUserName, // LPWSTR
const(wchar)* pszPassword, // LPWSTR
ubyte* pPackedCredentials, // BYTE* optional, out
uint* pcbPackedCredentials // DWORD* in/out
);ccall((:CredPackAuthenticationBufferW, "credui.dll"), stdcall, Int32,
(UInt32, Cwstring, Cwstring, Ptr{UInt8}, Ptr{UInt32}),
dwFlags, pszUserName, pszPassword, pPackedCredentials, pcbPackedCredentials)
# dwFlags : CRED_PACK_FLAGS -> UInt32
# pszUserName : LPWSTR -> Cwstring
# pszPassword : LPWSTR -> Cwstring
# pPackedCredentials : BYTE* optional, out -> Ptr{UInt8}
# pcbPackedCredentials : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t CredPackAuthenticationBufferW(
uint32_t dwFlags,
const uint16_t* pszUserName,
const uint16_t* pszPassword,
uint8_t* pPackedCredentials,
uint32_t* pcbPackedCredentials);
]]
local credui = ffi.load("credui")
-- credui.CredPackAuthenticationBufferW(dwFlags, pszUserName, pszPassword, pPackedCredentials, pcbPackedCredentials)
-- dwFlags : CRED_PACK_FLAGS
-- pszUserName : LPWSTR
-- pszPassword : LPWSTR
-- pPackedCredentials : BYTE* optional, out
-- pcbPackedCredentials : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('credui.dll');
const CredPackAuthenticationBufferW = lib.func('__stdcall', 'CredPackAuthenticationBufferW', 'int32_t', ['uint32_t', 'str16', 'str16', 'uint8_t *', 'uint32_t *']);
// CredPackAuthenticationBufferW(dwFlags, pszUserName, pszPassword, pPackedCredentials, pcbPackedCredentials)
// dwFlags : CRED_PACK_FLAGS -> 'uint32_t'
// pszUserName : LPWSTR -> 'str16'
// pszPassword : LPWSTR -> 'str16'
// pPackedCredentials : BYTE* optional, out -> 'uint8_t *'
// pcbPackedCredentials : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("credui.dll", {
CredPackAuthenticationBufferW: { parameters: ["u32", "buffer", "buffer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.CredPackAuthenticationBufferW(dwFlags, pszUserName, pszPassword, pPackedCredentials, pcbPackedCredentials)
// dwFlags : CRED_PACK_FLAGS -> "u32"
// pszUserName : LPWSTR -> "buffer"
// pszPassword : LPWSTR -> "buffer"
// pPackedCredentials : BYTE* optional, out -> "pointer"
// pcbPackedCredentials : DWORD* in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CredPackAuthenticationBufferW(
uint32_t dwFlags,
const uint16_t* pszUserName,
const uint16_t* pszPassword,
uint8_t* pPackedCredentials,
uint32_t* pcbPackedCredentials);
C, "credui.dll");
// $ffi->CredPackAuthenticationBufferW(dwFlags, pszUserName, pszPassword, pPackedCredentials, pcbPackedCredentials);
// dwFlags : CRED_PACK_FLAGS
// pszUserName : LPWSTR
// pszPassword : LPWSTR
// pPackedCredentials : BYTE* optional, out
// pcbPackedCredentials : DWORD* in/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 Credui extends StdCallLibrary {
Credui INSTANCE = Native.load("credui", Credui.class, W32APIOptions.UNICODE_OPTIONS);
boolean CredPackAuthenticationBufferW(
int dwFlags, // CRED_PACK_FLAGS
WString pszUserName, // LPWSTR
WString pszPassword, // LPWSTR
byte[] pPackedCredentials, // BYTE* optional, out
IntByReference pcbPackedCredentials // DWORD* in/out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("credui")]
lib Libcredui
fun CredPackAuthenticationBufferW = CredPackAuthenticationBufferW(
dwFlags : UInt32, # CRED_PACK_FLAGS
pszUserName : UInt16*, # LPWSTR
pszPassword : UInt16*, # LPWSTR
pPackedCredentials : UInt8*, # BYTE* optional, out
pcbPackedCredentials : UInt32* # DWORD* in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CredPackAuthenticationBufferWNative = Int32 Function(Uint32, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint8>, Pointer<Uint32>);
typedef CredPackAuthenticationBufferWDart = int Function(int, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint8>, Pointer<Uint32>);
final CredPackAuthenticationBufferW = DynamicLibrary.open('credui.dll')
.lookupFunction<CredPackAuthenticationBufferWNative, CredPackAuthenticationBufferWDart>('CredPackAuthenticationBufferW');
// dwFlags : CRED_PACK_FLAGS -> Uint32
// pszUserName : LPWSTR -> Pointer<Utf16>
// pszPassword : LPWSTR -> Pointer<Utf16>
// pPackedCredentials : BYTE* optional, out -> Pointer<Uint8>
// pcbPackedCredentials : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CredPackAuthenticationBufferW(
dwFlags: DWORD; // CRED_PACK_FLAGS
pszUserName: PWideChar; // LPWSTR
pszPassword: PWideChar; // LPWSTR
pPackedCredentials: Pointer; // BYTE* optional, out
pcbPackedCredentials: Pointer // DWORD* in/out
): BOOL; stdcall;
external 'credui.dll' name 'CredPackAuthenticationBufferW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CredPackAuthenticationBufferW"
c_CredPackAuthenticationBufferW :: Word32 -> CWString -> CWString -> Ptr Word8 -> Ptr Word32 -> IO CInt
-- dwFlags : CRED_PACK_FLAGS -> Word32
-- pszUserName : LPWSTR -> CWString
-- pszPassword : LPWSTR -> CWString
-- pPackedCredentials : BYTE* optional, out -> Ptr Word8
-- pcbPackedCredentials : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let credpackauthenticationbufferw =
foreign "CredPackAuthenticationBufferW"
(uint32_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint8_t) @-> (ptr uint32_t) @-> returning int32_t)
(* dwFlags : CRED_PACK_FLAGS -> uint32_t *)
(* pszUserName : LPWSTR -> (ptr uint16_t) *)
(* pszPassword : LPWSTR -> (ptr uint16_t) *)
(* pPackedCredentials : BYTE* optional, out -> (ptr uint8_t) *)
(* pcbPackedCredentials : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library credui (t "credui.dll"))
(cffi:use-foreign-library credui)
(cffi:defcfun ("CredPackAuthenticationBufferW" cred-pack-authentication-buffer-w :convention :stdcall) :int32
(dw-flags :uint32) ; CRED_PACK_FLAGS
(psz-user-name (:string :encoding :utf-16le)) ; LPWSTR
(psz-password (:string :encoding :utf-16le)) ; LPWSTR
(p-packed-credentials :pointer) ; BYTE* optional, out
(pcb-packed-credentials :pointer)) ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CredPackAuthenticationBufferW = Win32::API::More->new('credui',
'BOOL CredPackAuthenticationBufferW(DWORD dwFlags, LPCWSTR pszUserName, LPCWSTR pszPassword, LPVOID pPackedCredentials, LPVOID pcbPackedCredentials)');
# my $ret = $CredPackAuthenticationBufferW->Call($dwFlags, $pszUserName, $pszPassword, $pPackedCredentials, $pcbPackedCredentials);
# dwFlags : CRED_PACK_FLAGS -> DWORD
# pszUserName : LPWSTR -> LPCWSTR
# pszPassword : LPWSTR -> LPCWSTR
# pPackedCredentials : BYTE* optional, out -> LPVOID
# pcbPackedCredentials : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f CredPackAuthenticationBufferA (ANSI版) — ユーザー名とパスワードを認証バッファにパックする。