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

AddAce

関数
ACLの指定位置に1つ以上のACEを追加する。
DLLADVAPI32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// ADVAPI32.dll
#include <windows.h>

BOOL AddAce(
    ACL* pAcl,
    ACE_REVISION dwAceRevision,
    DWORD dwStartingAceIndex,
    void* pAceList,
    DWORD nAceListLength
);

パラメーター

名前方向
pAclACL*inout
dwAceRevisionACE_REVISIONin
dwStartingAceIndexDWORDin
pAceListvoid*in
nAceListLengthDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

// ADVAPI32.dll
#include <windows.h>

BOOL AddAce(
    ACL* pAcl,
    ACE_REVISION dwAceRevision,
    DWORD dwStartingAceIndex,
    void* pAceList,
    DWORD nAceListLength
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool AddAce(
    IntPtr pAcl,   // ACL* in/out
    uint dwAceRevision,   // ACE_REVISION
    uint dwStartingAceIndex,   // DWORD
    IntPtr pAceList,   // void*
    uint nAceListLength   // DWORD
);
<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function AddAce(
    pAcl As IntPtr,   ' ACL* in/out
    dwAceRevision As UInteger,   ' ACE_REVISION
    dwStartingAceIndex As UInteger,   ' DWORD
    pAceList As IntPtr,   ' void*
    nAceListLength As UInteger   ' DWORD
) As Boolean
End Function
' pAcl : ACL* in/out
' dwAceRevision : ACE_REVISION
' dwStartingAceIndex : DWORD
' pAceList : void*
' nAceListLength : DWORD
Declare PtrSafe Function AddAce Lib "advapi32" ( _
    ByVal pAcl As LongPtr, _
    ByVal dwAceRevision As Long, _
    ByVal dwStartingAceIndex As Long, _
    ByVal pAceList As LongPtr, _
    ByVal nAceListLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

AddAce = ctypes.windll.advapi32.AddAce
AddAce.restype = wintypes.BOOL
AddAce.argtypes = [
    ctypes.c_void_p,  # pAcl : ACL* in/out
    wintypes.DWORD,  # dwAceRevision : ACE_REVISION
    wintypes.DWORD,  # dwStartingAceIndex : DWORD
    ctypes.POINTER(None),  # pAceList : void*
    wintypes.DWORD,  # nAceListLength : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
AddAce = Fiddle::Function.new(
  lib['AddAce'],
  [
    Fiddle::TYPE_VOIDP,  # pAcl : ACL* in/out
    -Fiddle::TYPE_INT,  # dwAceRevision : ACE_REVISION
    -Fiddle::TYPE_INT,  # dwStartingAceIndex : DWORD
    Fiddle::TYPE_VOIDP,  # pAceList : void*
    -Fiddle::TYPE_INT,  # nAceListLength : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn AddAce(
        pAcl: *mut ACL,  // ACL* in/out
        dwAceRevision: u32,  // ACE_REVISION
        dwStartingAceIndex: u32,  // DWORD
        pAceList: *mut (),  // void*
        nAceListLength: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true)]
public static extern bool AddAce(IntPtr pAcl, uint dwAceRevision, uint dwStartingAceIndex, IntPtr pAceList, uint nAceListLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_AddAce' -Namespace Win32 -PassThru
# $api::AddAce(pAcl, dwAceRevision, dwStartingAceIndex, pAceList, nAceListLength)
#uselib "ADVAPI32.dll"
#func global AddAce "AddAce" sptr, sptr, sptr, sptr, sptr
; AddAce varptr(pAcl), dwAceRevision, dwStartingAceIndex, pAceList, nAceListLength   ; 戻り値は stat
; pAcl : ACL* in/out -> "sptr"
; dwAceRevision : ACE_REVISION -> "sptr"
; dwStartingAceIndex : DWORD -> "sptr"
; pAceList : void* -> "sptr"
; nAceListLength : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global AddAce "AddAce" var, int, int, sptr, int
; res = AddAce(pAcl, dwAceRevision, dwStartingAceIndex, pAceList, nAceListLength)
; pAcl : ACL* in/out -> "var"
; dwAceRevision : ACE_REVISION -> "int"
; dwStartingAceIndex : DWORD -> "int"
; pAceList : void* -> "sptr"
; nAceListLength : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL AddAce(ACL* pAcl, ACE_REVISION dwAceRevision, DWORD dwStartingAceIndex, void* pAceList, DWORD nAceListLength)
#uselib "ADVAPI32.dll"
#cfunc global AddAce "AddAce" var, int, int, intptr, int
; res = AddAce(pAcl, dwAceRevision, dwStartingAceIndex, pAceList, nAceListLength)
; pAcl : ACL* in/out -> "var"
; dwAceRevision : ACE_REVISION -> "int"
; dwStartingAceIndex : DWORD -> "int"
; pAceList : void* -> "intptr"
; nAceListLength : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procAddAce = advapi32.NewProc("AddAce")
)

// pAcl (ACL* in/out), dwAceRevision (ACE_REVISION), dwStartingAceIndex (DWORD), pAceList (void*), nAceListLength (DWORD)
r1, _, err := procAddAce.Call(
	uintptr(pAcl),
	uintptr(dwAceRevision),
	uintptr(dwStartingAceIndex),
	uintptr(pAceList),
	uintptr(nAceListLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function AddAce(
  pAcl: Pointer;   // ACL* in/out
  dwAceRevision: DWORD;   // ACE_REVISION
  dwStartingAceIndex: DWORD;   // DWORD
  pAceList: Pointer;   // void*
  nAceListLength: DWORD   // DWORD
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'AddAce';
result := DllCall("ADVAPI32\AddAce"
    , "Ptr", pAcl   ; ACL* in/out
    , "UInt", dwAceRevision   ; ACE_REVISION
    , "UInt", dwStartingAceIndex   ; DWORD
    , "Ptr", pAceList   ; void*
    , "UInt", nAceListLength   ; DWORD
    , "Int")   ; return: BOOL
●AddAce(pAcl, dwAceRevision, dwStartingAceIndex, pAceList, nAceListLength) = DLL("ADVAPI32.dll", "bool AddAce(void*, dword, dword, void*, dword)")
# 呼び出し: AddAce(pAcl, dwAceRevision, dwStartingAceIndex, pAceList, nAceListLength)
# pAcl : ACL* in/out -> "void*"
# dwAceRevision : ACE_REVISION -> "dword"
# dwStartingAceIndex : DWORD -> "dword"
# pAceList : void* -> "void*"
# nAceListLength : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。