Win32 API 日本語リファレンス
ホームSystem.Threading › CreateEventW

CreateEventW

関数
名前付きまたは無名のイベントを作成する(Unicode版)。
DLLKERNEL32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

HANDLE CreateEventW(
    SECURITY_ATTRIBUTES* lpEventAttributes,   // optional
    BOOL bManualReset,
    BOOL bInitialState,
    LPCWSTR lpName   // optional
);

パラメーター

名前方向
lpEventAttributesSECURITY_ATTRIBUTES*inoptional
bManualResetBOOLin
bInitialStateBOOLin
lpNameLPCWSTRinoptional

戻り値の型: HANDLE

各言語での呼び出し定義

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

HANDLE CreateEventW(
    SECURITY_ATTRIBUTES* lpEventAttributes,   // optional
    BOOL bManualReset,
    BOOL bInitialState,
    LPCWSTR lpName   // optional
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr CreateEventW(
    IntPtr lpEventAttributes,   // SECURITY_ATTRIBUTES* optional
    bool bManualReset,   // BOOL
    bool bInitialState,   // BOOL
    [MarshalAs(UnmanagedType.LPWStr)] string lpName   // LPCWSTR optional
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CreateEventW(
    lpEventAttributes As IntPtr,   ' SECURITY_ATTRIBUTES* optional
    bManualReset As Boolean,   ' BOOL
    bInitialState As Boolean,   ' BOOL
    <MarshalAs(UnmanagedType.LPWStr)> lpName As String   ' LPCWSTR optional
) As IntPtr
End Function
' lpEventAttributes : SECURITY_ATTRIBUTES* optional
' bManualReset : BOOL
' bInitialState : BOOL
' lpName : LPCWSTR optional
Declare PtrSafe Function CreateEventW Lib "kernel32" ( _
    ByVal lpEventAttributes As LongPtr, _
    ByVal bManualReset As Long, _
    ByVal bInitialState As Long, _
    ByVal lpName As LongPtr) As LongPtr
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateEventW = ctypes.windll.kernel32.CreateEventW
CreateEventW.restype = ctypes.c_void_p
CreateEventW.argtypes = [
    ctypes.c_void_p,  # lpEventAttributes : SECURITY_ATTRIBUTES* optional
    wintypes.BOOL,  # bManualReset : BOOL
    wintypes.BOOL,  # bInitialState : BOOL
    wintypes.LPCWSTR,  # lpName : LPCWSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
CreateEventW = Fiddle::Function.new(
  lib['CreateEventW'],
  [
    Fiddle::TYPE_VOIDP,  # lpEventAttributes : SECURITY_ATTRIBUTES* optional
    Fiddle::TYPE_INT,  # bManualReset : BOOL
    Fiddle::TYPE_INT,  # bInitialState : BOOL
    Fiddle::TYPE_VOIDP,  # lpName : LPCWSTR optional
  ],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "kernel32")]
extern "system" {
    fn CreateEventW(
        lpEventAttributes: *mut SECURITY_ATTRIBUTES,  // SECURITY_ATTRIBUTES* optional
        bManualReset: i32,  // BOOL
        bInitialState: i32,  // BOOL
        lpName: *const u16  // LPCWSTR optional
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr CreateEventW(IntPtr lpEventAttributes, bool bManualReset, bool bInitialState, [MarshalAs(UnmanagedType.LPWStr)] string lpName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_CreateEventW' -Namespace Win32 -PassThru
# $api::CreateEventW(lpEventAttributes, bManualReset, bInitialState, lpName)
#uselib "KERNEL32.dll"
#func global CreateEventW "CreateEventW" wptr, wptr, wptr, wptr
; CreateEventW varptr(lpEventAttributes), bManualReset, bInitialState, lpName   ; 戻り値は stat
; lpEventAttributes : SECURITY_ATTRIBUTES* optional -> "wptr"
; bManualReset : BOOL -> "wptr"
; bInitialState : BOOL -> "wptr"
; lpName : LPCWSTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global CreateEventW "CreateEventW" var, int, int, wstr
; res = CreateEventW(lpEventAttributes, bManualReset, bInitialState, lpName)
; lpEventAttributes : SECURITY_ATTRIBUTES* optional -> "var"
; bManualReset : BOOL -> "int"
; bInitialState : BOOL -> "int"
; lpName : LPCWSTR optional -> "wstr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HANDLE CreateEventW(SECURITY_ATTRIBUTES* lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCWSTR lpName)
#uselib "KERNEL32.dll"
#cfunc global CreateEventW "CreateEventW" var, int, int, wstr
; res = CreateEventW(lpEventAttributes, bManualReset, bInitialState, lpName)
; lpEventAttributes : SECURITY_ATTRIBUTES* optional -> "var"
; bManualReset : BOOL -> "int"
; bInitialState : BOOL -> "int"
; lpName : LPCWSTR optional -> "wstr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procCreateEventW = kernel32.NewProc("CreateEventW")
)

// lpEventAttributes (SECURITY_ATTRIBUTES* optional), bManualReset (BOOL), bInitialState (BOOL), lpName (LPCWSTR optional)
r1, _, err := procCreateEventW.Call(
	uintptr(lpEventAttributes),
	uintptr(bManualReset),
	uintptr(bInitialState),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HANDLE
function CreateEventW(
  lpEventAttributes: Pointer;   // SECURITY_ATTRIBUTES* optional
  bManualReset: BOOL;   // BOOL
  bInitialState: BOOL;   // BOOL
  lpName: PWideChar   // LPCWSTR optional
): THandle; stdcall;
  external 'KERNEL32.dll' name 'CreateEventW';
result := DllCall("KERNEL32\CreateEventW"
    , "Ptr", lpEventAttributes   ; SECURITY_ATTRIBUTES* optional
    , "Int", bManualReset   ; BOOL
    , "Int", bInitialState   ; BOOL
    , "WStr", lpName   ; LPCWSTR optional
    , "Ptr")   ; return: HANDLE
●CreateEventW(lpEventAttributes, bManualReset, bInitialState, lpName) = DLL("KERNEL32.dll", "void* CreateEventW(void*, bool, bool, char*)")
# 呼び出し: CreateEventW(lpEventAttributes, bManualReset, bInitialState, lpName)
# lpEventAttributes : SECURITY_ATTRIBUTES* optional -> "void*"
# bManualReset : BOOL -> "bool"
# bInitialState : BOOL -> "bool"
# lpName : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。