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

AllocateLocallyUniqueId

関数
ローカルで一意なLUIDを割り当てる。
DLLADVAPI32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL AllocateLocallyUniqueId(
    LUID* Luid
);

パラメーター

名前方向
LuidLUID*out

戻り値の型: BOOL

各言語での呼び出し定義

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

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

AllocateLocallyUniqueId = ctypes.windll.advapi32.AllocateLocallyUniqueId
AllocateLocallyUniqueId.restype = wintypes.BOOL
AllocateLocallyUniqueId.argtypes = [
    ctypes.c_void_p,  # Luid : LUID* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
AllocateLocallyUniqueId = Fiddle::Function.new(
  lib['AllocateLocallyUniqueId'],
  [
    Fiddle::TYPE_VOIDP,  # Luid : LUID* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn AllocateLocallyUniqueId(
        Luid: *mut LUID  // LUID* out
    ) -> 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 AllocateLocallyUniqueId(IntPtr Luid);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_AllocateLocallyUniqueId' -Namespace Win32 -PassThru
# $api::AllocateLocallyUniqueId(Luid)
#uselib "ADVAPI32.dll"
#func global AllocateLocallyUniqueId "AllocateLocallyUniqueId" sptr
; AllocateLocallyUniqueId varptr(Luid)   ; 戻り値は stat
; Luid : LUID* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global AllocateLocallyUniqueId "AllocateLocallyUniqueId" var
; res = AllocateLocallyUniqueId(Luid)
; Luid : LUID* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL AllocateLocallyUniqueId(LUID* Luid)
#uselib "ADVAPI32.dll"
#cfunc global AllocateLocallyUniqueId "AllocateLocallyUniqueId" var
; res = AllocateLocallyUniqueId(Luid)
; Luid : LUID* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procAllocateLocallyUniqueId = advapi32.NewProc("AllocateLocallyUniqueId")
)

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