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

BuildTrusteeWithNameA

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

シグネチャ

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

void BuildTrusteeWithNameA(
    TRUSTEE_A* pTrustee,
    LPSTR pName   // optional
);

パラメーター

名前方向説明
pTrusteeTRUSTEE_A*inout初期化する TRUSTEE 構造体へのポインターです。BuildTrusteeWithName 関数はメモリを割り当てません。このパラメーターが NULL または無効なポインターの場合、結果は未定義です。
pNameLPSTRinoptional

TRUSTEE 構造体の ptstrName メンバーに設定する trustee の名前を格納した、null 終端文字列へのポインターです。BuildTrusteeWithName 関数は、TRUSTEE 構造体のその他のメンバーを次のように設定します。

Value Meaning
pMultipleTrustee
NULL
MultipleTrusteeOperation
NO_MULTIPLE_TRUSTEE
TrusteeForm
TRUSTEE_IS_NAME
TrusteeType
TRUSTEE_IS_UNKNOWN

戻り値の型: void

公式ドキュメント

TRUSTEE 構造体を初期化します。呼び出し元は trustee 名を指定します。この関数は構造体のその他のメンバーを既定値に設定します。(ANSI)

解説(Remarks)

メモ

aclapi.h ヘッダーは BuildTrusteeWithName をエイリアスとして定義しており、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択します。エンコード中立のエイリアスの使用を、エンコード中立でないコードと混在させると、不一致が生じ、コンパイルエラーや実行時エラーの原因となることがあります。詳細については、「Conventions for Function Prototypes」を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

void BuildTrusteeWithNameA(
    TRUSTEE_A* pTrustee,
    LPSTR pName   // optional
);
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern void BuildTrusteeWithNameA(
    IntPtr pTrustee,   // TRUSTEE_A* in/out
    [MarshalAs(UnmanagedType.LPStr)] string pName   // LPSTR optional
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Sub BuildTrusteeWithNameA(
    pTrustee As IntPtr,   ' TRUSTEE_A* in/out
    <MarshalAs(UnmanagedType.LPStr)> pName As String   ' LPSTR optional
)
End Sub
' pTrustee : TRUSTEE_A* in/out
' pName : LPSTR optional
Declare PtrSafe Sub BuildTrusteeWithNameA Lib "advapi32" ( _
    ByVal pTrustee As LongPtr, _
    ByVal pName As String)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

BuildTrusteeWithNameA = ctypes.windll.advapi32.BuildTrusteeWithNameA
BuildTrusteeWithNameA.restype = None
BuildTrusteeWithNameA.argtypes = [
    ctypes.c_void_p,  # pTrustee : TRUSTEE_A* in/out
    wintypes.LPCSTR,  # pName : LPSTR optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
BuildTrusteeWithNameA = Fiddle::Function.new(
  lib['BuildTrusteeWithNameA'],
  [
    Fiddle::TYPE_VOIDP,  # pTrustee : TRUSTEE_A* in/out
    Fiddle::TYPE_VOIDP,  # pName : LPSTR optional
  ],
  Fiddle::TYPE_VOID)
#[link(name = "advapi32")]
extern "system" {
    fn BuildTrusteeWithNameA(
        pTrustee: *mut TRUSTEE_A,  // TRUSTEE_A* in/out
        pName: *mut u8  // LPSTR optional
    );
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi)]
public static extern void BuildTrusteeWithNameA(IntPtr pTrustee, [MarshalAs(UnmanagedType.LPStr)] string pName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_BuildTrusteeWithNameA' -Namespace Win32 -PassThru
# $api::BuildTrusteeWithNameA(pTrustee, pName)
#uselib "ADVAPI32.dll"
#func global BuildTrusteeWithNameA "BuildTrusteeWithNameA" sptr, sptr
; BuildTrusteeWithNameA varptr(pTrustee), pName
; pTrustee : TRUSTEE_A* in/out -> "sptr"
; pName : LPSTR optional -> "sptr"
出力引数:
#uselib "ADVAPI32.dll"
#func global BuildTrusteeWithNameA "BuildTrusteeWithNameA" var, str
; BuildTrusteeWithNameA pTrustee, pName
; pTrustee : TRUSTEE_A* in/out -> "var"
; pName : LPSTR optional -> "str"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; void BuildTrusteeWithNameA(TRUSTEE_A* pTrustee, LPSTR pName)
#uselib "ADVAPI32.dll"
#func global BuildTrusteeWithNameA "BuildTrusteeWithNameA" var, str
; BuildTrusteeWithNameA pTrustee, pName
; pTrustee : TRUSTEE_A* in/out -> "var"
; pName : LPSTR optional -> "str"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procBuildTrusteeWithNameA = advapi32.NewProc("BuildTrusteeWithNameA")
)

// pTrustee (TRUSTEE_A* in/out), pName (LPSTR optional)
r1, _, err := procBuildTrusteeWithNameA.Call(
	uintptr(pTrustee),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void
procedure BuildTrusteeWithNameA(
  pTrustee: Pointer;   // TRUSTEE_A* in/out
  pName: PAnsiChar   // LPSTR optional
); stdcall;
  external 'ADVAPI32.dll' name 'BuildTrusteeWithNameA';
result := DllCall("ADVAPI32\BuildTrusteeWithNameA"
    , "Ptr", pTrustee   ; TRUSTEE_A* in/out
    , "AStr", pName   ; LPSTR optional
    , "Int")   ; return: void
●BuildTrusteeWithNameA(pTrustee, pName) = DLL("ADVAPI32.dll", "int BuildTrusteeWithNameA(void*, char*)")
# 呼び出し: BuildTrusteeWithNameA(pTrustee, pName)
# pTrustee : TRUSTEE_A* in/out -> "void*"
# pName : LPSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "advapi32" fn BuildTrusteeWithNameA(
    pTrustee: [*c]TRUSTEE_A, // TRUSTEE_A* in/out
    pName: [*c]const u8 // LPSTR optional
) callconv(std.os.windows.WINAPI) void;
proc BuildTrusteeWithNameA(
    pTrustee: ptr TRUSTEE_A,  # TRUSTEE_A* in/out
    pName: cstring  # LPSTR optional
) {.importc: "BuildTrusteeWithNameA", stdcall, dynlib: "ADVAPI32.dll".}
pragma(lib, "advapi32");
extern(Windows)
void BuildTrusteeWithNameA(
    TRUSTEE_A* pTrustee,   // TRUSTEE_A* in/out
    const(char)* pName   // LPSTR optional
);
ccall((:BuildTrusteeWithNameA, "ADVAPI32.dll"), stdcall, Cvoid,
      (Ptr{TRUSTEE_A}, Cstring),
      pTrustee, pName)
# pTrustee : TRUSTEE_A* in/out -> Ptr{TRUSTEE_A}
# pName : LPSTR optional -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
void BuildTrusteeWithNameA(
    void* pTrustee,
    const char* pName);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.BuildTrusteeWithNameA(pTrustee, pName)
-- pTrustee : TRUSTEE_A* in/out
-- pName : LPSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const BuildTrusteeWithNameA = lib.func('__stdcall', 'BuildTrusteeWithNameA', 'void', ['void *', 'str']);
// BuildTrusteeWithNameA(pTrustee, pName)
// pTrustee : TRUSTEE_A* in/out -> 'void *'
// pName : LPSTR optional -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ADVAPI32.dll", {
  BuildTrusteeWithNameA: { parameters: ["pointer", "buffer"], result: "void" },
});
// lib.symbols.BuildTrusteeWithNameA(pTrustee, pName)
// pTrustee : TRUSTEE_A* in/out -> "pointer"
// pName : LPSTR optional -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void BuildTrusteeWithNameA(
    void* pTrustee,
    const char* pName);
C, "ADVAPI32.dll");
// $ffi->BuildTrusteeWithNameA(pTrustee, pName);
// pTrustee : TRUSTEE_A* in/out
// pName : LPSTR optional
// 構造体/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);
    void BuildTrusteeWithNameA(
        Pointer pTrustee,   // TRUSTEE_A* in/out
        String pName   // LPSTR optional
    );
}
@[Link("advapi32")]
lib LibADVAPI32
  fun BuildTrusteeWithNameA = BuildTrusteeWithNameA(
    pTrustee : TRUSTEE_A*,   # TRUSTEE_A* in/out
    pName : UInt8*   # LPSTR optional
  ) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef BuildTrusteeWithNameANative = Void Function(Pointer<Void>, Pointer<Utf8>);
typedef BuildTrusteeWithNameADart = void Function(Pointer<Void>, Pointer<Utf8>);
final BuildTrusteeWithNameA = DynamicLibrary.open('ADVAPI32.dll')
    .lookupFunction<BuildTrusteeWithNameANative, BuildTrusteeWithNameADart>('BuildTrusteeWithNameA');
// pTrustee : TRUSTEE_A* in/out -> Pointer<Void>
// pName : LPSTR optional -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
procedure BuildTrusteeWithNameA(
  pTrustee: Pointer;   // TRUSTEE_A* in/out
  pName: PAnsiChar   // LPSTR optional
); stdcall;
  external 'ADVAPI32.dll' name 'BuildTrusteeWithNameA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "BuildTrusteeWithNameA"
  c_BuildTrusteeWithNameA :: Ptr () -> CString -> IO ()
-- pTrustee : TRUSTEE_A* in/out -> Ptr ()
-- pName : LPSTR optional -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let buildtrusteewithnamea =
  foreign "BuildTrusteeWithNameA"
    ((ptr void) @-> string @-> returning void)
(* pTrustee : TRUSTEE_A* in/out -> (ptr void) *)
(* pName : LPSTR optional -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)

(cffi:defcfun ("BuildTrusteeWithNameA" build-trustee-with-name-a :convention :stdcall) :void
  (p-trustee :pointer)   ; TRUSTEE_A* in/out
  (p-name :string))   ; LPSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $BuildTrusteeWithNameA = Win32::API::More->new('ADVAPI32',
    'void BuildTrusteeWithNameA(LPVOID pTrustee, LPCSTR pName)');
# my $ret = $BuildTrusteeWithNameA->Call($pTrustee, $pName);
# pTrustee : TRUSTEE_A* in/out -> LPVOID
# pName : LPSTR optional -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
公式の関連項目
使用する型