ホーム › System.Threading › InitOnceExecuteOnce
InitOnceExecuteOnce
関数指定の初期化関数を一度だけスレッドセーフに実行する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL InitOnceExecuteOnce(
INIT_ONCE* InitOnce,
PINIT_ONCE_FN InitFn,
void* Parameter, // optional
void** Context // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| InitOnce | INIT_ONCE* | inout |
| InitFn | PINIT_ONCE_FN | in |
| Parameter | void* | inoutoptional |
| Context | void** | outoptional |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL InitOnceExecuteOnce(
INIT_ONCE* InitOnce,
PINIT_ONCE_FN InitFn,
void* Parameter, // optional
void** Context // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool InitOnceExecuteOnce(
IntPtr InitOnce, // INIT_ONCE* in/out
IntPtr InitFn, // PINIT_ONCE_FN
IntPtr Parameter, // void* optional, in/out
IntPtr Context // void** optional, out
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function InitOnceExecuteOnce(
InitOnce As IntPtr, ' INIT_ONCE* in/out
InitFn As IntPtr, ' PINIT_ONCE_FN
Parameter As IntPtr, ' void* optional, in/out
Context As IntPtr ' void** optional, out
) As Boolean
End Function' InitOnce : INIT_ONCE* in/out
' InitFn : PINIT_ONCE_FN
' Parameter : void* optional, in/out
' Context : void** optional, out
Declare PtrSafe Function InitOnceExecuteOnce Lib "kernel32" ( _
ByVal InitOnce As LongPtr, _
ByVal InitFn As LongPtr, _
ByVal Parameter As LongPtr, _
ByVal Context As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
InitOnceExecuteOnce = ctypes.windll.kernel32.InitOnceExecuteOnce
InitOnceExecuteOnce.restype = wintypes.BOOL
InitOnceExecuteOnce.argtypes = [
ctypes.c_void_p, # InitOnce : INIT_ONCE* in/out
ctypes.c_void_p, # InitFn : PINIT_ONCE_FN
ctypes.POINTER(None), # Parameter : void* optional, in/out
ctypes.c_void_p, # Context : void** optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
InitOnceExecuteOnce = Fiddle::Function.new(
lib['InitOnceExecuteOnce'],
[
Fiddle::TYPE_VOIDP, # InitOnce : INIT_ONCE* in/out
Fiddle::TYPE_VOIDP, # InitFn : PINIT_ONCE_FN
Fiddle::TYPE_VOIDP, # Parameter : void* optional, in/out
Fiddle::TYPE_VOIDP, # Context : void** optional, out
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn InitOnceExecuteOnce(
InitOnce: *mut INIT_ONCE, // INIT_ONCE* in/out
InitFn: *const core::ffi::c_void, // PINIT_ONCE_FN
Parameter: *mut (), // void* optional, in/out
Context: *mut *mut () // void** optional, out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern bool InitOnceExecuteOnce(IntPtr InitOnce, IntPtr InitFn, IntPtr Parameter, IntPtr Context);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_InitOnceExecuteOnce' -Namespace Win32 -PassThru
# $api::InitOnceExecuteOnce(InitOnce, InitFn, Parameter, Context)#uselib "KERNEL32.dll"
#func global InitOnceExecuteOnce "InitOnceExecuteOnce" sptr, sptr, sptr, sptr
; InitOnceExecuteOnce varptr(InitOnce), InitFn, Parameter, Context ; 戻り値は stat
; InitOnce : INIT_ONCE* in/out -> "sptr"
; InitFn : PINIT_ONCE_FN -> "sptr"
; Parameter : void* optional, in/out -> "sptr"
; Context : void** optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global InitOnceExecuteOnce "InitOnceExecuteOnce" var, sptr, sptr, sptr ; res = InitOnceExecuteOnce(InitOnce, InitFn, Parameter, Context) ; InitOnce : INIT_ONCE* in/out -> "var" ; InitFn : PINIT_ONCE_FN -> "sptr" ; Parameter : void* optional, in/out -> "sptr" ; Context : void** optional, out -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global InitOnceExecuteOnce "InitOnceExecuteOnce" sptr, sptr, sptr, sptr ; res = InitOnceExecuteOnce(varptr(InitOnce), InitFn, Parameter, Context) ; InitOnce : INIT_ONCE* in/out -> "sptr" ; InitFn : PINIT_ONCE_FN -> "sptr" ; Parameter : void* optional, in/out -> "sptr" ; Context : void** optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL InitOnceExecuteOnce(INIT_ONCE* InitOnce, PINIT_ONCE_FN InitFn, void* Parameter, void** Context) #uselib "KERNEL32.dll" #cfunc global InitOnceExecuteOnce "InitOnceExecuteOnce" var, intptr, intptr, intptr ; res = InitOnceExecuteOnce(InitOnce, InitFn, Parameter, Context) ; InitOnce : INIT_ONCE* in/out -> "var" ; InitFn : PINIT_ONCE_FN -> "intptr" ; Parameter : void* optional, in/out -> "intptr" ; Context : void** optional, out -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL InitOnceExecuteOnce(INIT_ONCE* InitOnce, PINIT_ONCE_FN InitFn, void* Parameter, void** Context) #uselib "KERNEL32.dll" #cfunc global InitOnceExecuteOnce "InitOnceExecuteOnce" intptr, intptr, intptr, intptr ; res = InitOnceExecuteOnce(varptr(InitOnce), InitFn, Parameter, Context) ; InitOnce : INIT_ONCE* in/out -> "intptr" ; InitFn : PINIT_ONCE_FN -> "intptr" ; Parameter : void* optional, in/out -> "intptr" ; Context : void** optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procInitOnceExecuteOnce = kernel32.NewProc("InitOnceExecuteOnce")
)
// InitOnce (INIT_ONCE* in/out), InitFn (PINIT_ONCE_FN), Parameter (void* optional, in/out), Context (void** optional, out)
r1, _, err := procInitOnceExecuteOnce.Call(
uintptr(InitOnce),
uintptr(InitFn),
uintptr(Parameter),
uintptr(Context),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction InitOnceExecuteOnce(
InitOnce: Pointer; // INIT_ONCE* in/out
InitFn: Pointer; // PINIT_ONCE_FN
Parameter: Pointer; // void* optional, in/out
Context: Pointer // void** optional, out
): BOOL; stdcall;
external 'KERNEL32.dll' name 'InitOnceExecuteOnce';result := DllCall("KERNEL32\InitOnceExecuteOnce"
, "Ptr", InitOnce ; INIT_ONCE* in/out
, "Ptr", InitFn ; PINIT_ONCE_FN
, "Ptr", Parameter ; void* optional, in/out
, "Ptr", Context ; void** optional, out
, "Int") ; return: BOOL●InitOnceExecuteOnce(InitOnce, InitFn, Parameter, Context) = DLL("KERNEL32.dll", "bool InitOnceExecuteOnce(void*, void*, void*, void*)")
# 呼び出し: InitOnceExecuteOnce(InitOnce, InitFn, Parameter, Context)
# InitOnce : INIT_ONCE* in/out -> "void*"
# InitFn : PINIT_ONCE_FN -> "void*"
# Parameter : void* optional, in/out -> "void*"
# Context : void** optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。