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

EqualSid

関数
2つのSIDが等しいかどうかを判定する。
DLLADVAPI32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL EqualSid(
    PSID pSid1,
    PSID pSid2
);

パラメーター

名前方向
pSid1PSIDin
pSid2PSIDin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL EqualSid(
    PSID pSid1,
    PSID pSid2
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool EqualSid(
    IntPtr pSid1,   // PSID
    IntPtr pSid2   // PSID
);
<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function EqualSid(
    pSid1 As IntPtr,   ' PSID
    pSid2 As IntPtr   ' PSID
) As Boolean
End Function
' pSid1 : PSID
' pSid2 : PSID
Declare PtrSafe Function EqualSid Lib "advapi32" ( _
    ByVal pSid1 As LongPtr, _
    ByVal pSid2 As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

EqualSid = ctypes.windll.advapi32.EqualSid
EqualSid.restype = wintypes.BOOL
EqualSid.argtypes = [
    wintypes.HANDLE,  # pSid1 : PSID
    wintypes.HANDLE,  # pSid2 : PSID
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
EqualSid = Fiddle::Function.new(
  lib['EqualSid'],
  [
    Fiddle::TYPE_VOIDP,  # pSid1 : PSID
    Fiddle::TYPE_VOIDP,  # pSid2 : PSID
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn EqualSid(
        pSid1: *mut core::ffi::c_void,  // PSID
        pSid2: *mut core::ffi::c_void  // PSID
    ) -> 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 EqualSid(IntPtr pSid1, IntPtr pSid2);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_EqualSid' -Namespace Win32 -PassThru
# $api::EqualSid(pSid1, pSid2)
#uselib "ADVAPI32.dll"
#func global EqualSid "EqualSid" sptr, sptr
; EqualSid pSid1, pSid2   ; 戻り値は stat
; pSid1 : PSID -> "sptr"
; pSid2 : PSID -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ADVAPI32.dll"
#cfunc global EqualSid "EqualSid" sptr, sptr
; res = EqualSid(pSid1, pSid2)
; pSid1 : PSID -> "sptr"
; pSid2 : PSID -> "sptr"
; BOOL EqualSid(PSID pSid1, PSID pSid2)
#uselib "ADVAPI32.dll"
#cfunc global EqualSid "EqualSid" intptr, intptr
; res = EqualSid(pSid1, pSid2)
; pSid1 : PSID -> "intptr"
; pSid2 : PSID -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procEqualSid = advapi32.NewProc("EqualSid")
)

// pSid1 (PSID), pSid2 (PSID)
r1, _, err := procEqualSid.Call(
	uintptr(pSid1),
	uintptr(pSid2),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function EqualSid(
  pSid1: THandle;   // PSID
  pSid2: THandle   // PSID
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'EqualSid';
result := DllCall("ADVAPI32\EqualSid"
    , "Ptr", pSid1   ; PSID
    , "Ptr", pSid2   ; PSID
    , "Int")   ; return: BOOL
●EqualSid(pSid1, pSid2) = DLL("ADVAPI32.dll", "bool EqualSid(void*, void*)")
# 呼び出し: EqualSid(pSid1, pSid2)
# pSid1 : PSID -> "void*"
# pSid2 : PSID -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。