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

BuildTrusteeWithNameW

関数
アカウント名を指定してTRUSTEE構造体を初期化する。
DLLADVAPI32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

void BuildTrusteeWithNameW(
    TRUSTEE_W* pTrustee,
    LPWSTR pName   // optional
);

パラメーター

名前方向
pTrusteeTRUSTEE_W*inout
pNameLPWSTRinoptional

戻り値の型: void

各言語での呼び出し定義

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

void BuildTrusteeWithNameW(
    TRUSTEE_W* pTrustee,
    LPWSTR pName   // optional
);
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern void BuildTrusteeWithNameW(
    IntPtr pTrustee,   // TRUSTEE_W* in/out
    [MarshalAs(UnmanagedType.LPWStr)] string pName   // LPWSTR optional
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Sub BuildTrusteeWithNameW(
    pTrustee As IntPtr,   ' TRUSTEE_W* in/out
    <MarshalAs(UnmanagedType.LPWStr)> pName As String   ' LPWSTR optional
)
End Sub
' pTrustee : TRUSTEE_W* in/out
' pName : LPWSTR optional
Declare PtrSafe Sub BuildTrusteeWithNameW Lib "advapi32" ( _
    ByVal pTrustee As LongPtr, _
    ByVal pName As LongPtr)
' 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

BuildTrusteeWithNameW = ctypes.windll.advapi32.BuildTrusteeWithNameW
BuildTrusteeWithNameW.restype = None
BuildTrusteeWithNameW.argtypes = [
    ctypes.c_void_p,  # pTrustee : TRUSTEE_W* in/out
    wintypes.LPCWSTR,  # pName : LPWSTR optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
BuildTrusteeWithNameW = Fiddle::Function.new(
  lib['BuildTrusteeWithNameW'],
  [
    Fiddle::TYPE_VOIDP,  # pTrustee : TRUSTEE_W* in/out
    Fiddle::TYPE_VOIDP,  # pName : LPWSTR optional
  ],
  Fiddle::TYPE_VOID)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "advapi32")]
extern "system" {
    fn BuildTrusteeWithNameW(
        pTrustee: *mut TRUSTEE_W,  // TRUSTEE_W* in/out
        pName: *mut u16  // LPWSTR optional
    );
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode)]
public static extern void BuildTrusteeWithNameW(IntPtr pTrustee, [MarshalAs(UnmanagedType.LPWStr)] string pName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_BuildTrusteeWithNameW' -Namespace Win32 -PassThru
# $api::BuildTrusteeWithNameW(pTrustee, pName)
#uselib "ADVAPI32.dll"
#func global BuildTrusteeWithNameW "BuildTrusteeWithNameW" wptr, wptr
; BuildTrusteeWithNameW varptr(pTrustee), pName
; pTrustee : TRUSTEE_W* in/out -> "wptr"
; pName : LPWSTR optional -> "wptr"
出力引数:
#uselib "ADVAPI32.dll"
#func global BuildTrusteeWithNameW "BuildTrusteeWithNameW" var, wstr
; BuildTrusteeWithNameW pTrustee, pName
; pTrustee : TRUSTEE_W* in/out -> "var"
; pName : LPWSTR optional -> "wstr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; void BuildTrusteeWithNameW(TRUSTEE_W* pTrustee, LPWSTR pName)
#uselib "ADVAPI32.dll"
#func global BuildTrusteeWithNameW "BuildTrusteeWithNameW" var, wstr
; BuildTrusteeWithNameW pTrustee, pName
; pTrustee : TRUSTEE_W* in/out -> "var"
; pName : LPWSTR optional -> "wstr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procBuildTrusteeWithNameW = advapi32.NewProc("BuildTrusteeWithNameW")
)

// pTrustee (TRUSTEE_W* in/out), pName (LPWSTR optional)
r1, _, err := procBuildTrusteeWithNameW.Call(
	uintptr(pTrustee),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void
procedure BuildTrusteeWithNameW(
  pTrustee: Pointer;   // TRUSTEE_W* in/out
  pName: PWideChar   // LPWSTR optional
); stdcall;
  external 'ADVAPI32.dll' name 'BuildTrusteeWithNameW';
result := DllCall("ADVAPI32\BuildTrusteeWithNameW"
    , "Ptr", pTrustee   ; TRUSTEE_W* in/out
    , "WStr", pName   ; LPWSTR optional
    , "Int")   ; return: void
●BuildTrusteeWithNameW(pTrustee, pName) = DLL("ADVAPI32.dll", "int BuildTrusteeWithNameW(void*, char*)")
# 呼び出し: BuildTrusteeWithNameW(pTrustee, pName)
# pTrustee : TRUSTEE_W* in/out -> "void*"
# pName : LPWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。