ホーム › System.EventLog › ReportEventW
ReportEventW
関数イベントログにエントリを書き込む(Unicode版)。
シグネチャ
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
BOOL ReportEventW(
HANDLE hEventLog,
REPORT_EVENT_TYPE wType,
WORD wCategory,
DWORD dwEventID,
PSID lpUserSid, // optional
WORD wNumStrings,
DWORD dwDataSize,
LPCWSTR* lpStrings, // optional
void* lpRawData // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hEventLog | HANDLE | in |
| wType | REPORT_EVENT_TYPE | in |
| wCategory | WORD | in |
| dwEventID | DWORD | in |
| lpUserSid | PSID | inoptional |
| wNumStrings | WORD | in |
| dwDataSize | DWORD | in |
| lpStrings | LPCWSTR* | inoptional |
| lpRawData | void* | inoptional |
戻り値の型: BOOL
各言語での呼び出し定義
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
BOOL ReportEventW(
HANDLE hEventLog,
REPORT_EVENT_TYPE wType,
WORD wCategory,
DWORD dwEventID,
PSID lpUserSid, // optional
WORD wNumStrings,
DWORD dwDataSize,
LPCWSTR* lpStrings, // optional
void* lpRawData // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool ReportEventW(
IntPtr hEventLog, // HANDLE
ushort wType, // REPORT_EVENT_TYPE
ushort wCategory, // WORD
uint dwEventID, // DWORD
IntPtr lpUserSid, // PSID optional
ushort wNumStrings, // WORD
uint dwDataSize, // DWORD
IntPtr lpStrings, // LPCWSTR* optional
IntPtr lpRawData // void* optional
);<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function ReportEventW(
hEventLog As IntPtr, ' HANDLE
wType As UShort, ' REPORT_EVENT_TYPE
wCategory As UShort, ' WORD
dwEventID As UInteger, ' DWORD
lpUserSid As IntPtr, ' PSID optional
wNumStrings As UShort, ' WORD
dwDataSize As UInteger, ' DWORD
lpStrings As IntPtr, ' LPCWSTR* optional
lpRawData As IntPtr ' void* optional
) As Boolean
End Function' hEventLog : HANDLE
' wType : REPORT_EVENT_TYPE
' wCategory : WORD
' dwEventID : DWORD
' lpUserSid : PSID optional
' wNumStrings : WORD
' dwDataSize : DWORD
' lpStrings : LPCWSTR* optional
' lpRawData : void* optional
Declare PtrSafe Function ReportEventW Lib "advapi32" ( _
ByVal hEventLog As LongPtr, _
ByVal wType As Integer, _
ByVal wCategory As Integer, _
ByVal dwEventID As Long, _
ByVal lpUserSid As LongPtr, _
ByVal wNumStrings As Integer, _
ByVal dwDataSize As Long, _
ByVal lpStrings As LongPtr, _
ByVal lpRawData As LongPtr) As Long
' 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
ReportEventW = ctypes.windll.advapi32.ReportEventW
ReportEventW.restype = wintypes.BOOL
ReportEventW.argtypes = [
wintypes.HANDLE, # hEventLog : HANDLE
ctypes.c_ushort, # wType : REPORT_EVENT_TYPE
ctypes.c_ushort, # wCategory : WORD
wintypes.DWORD, # dwEventID : DWORD
wintypes.HANDLE, # lpUserSid : PSID optional
ctypes.c_ushort, # wNumStrings : WORD
wintypes.DWORD, # dwDataSize : DWORD
ctypes.c_void_p, # lpStrings : LPCWSTR* optional
ctypes.POINTER(None), # lpRawData : void* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
ReportEventW = Fiddle::Function.new(
lib['ReportEventW'],
[
Fiddle::TYPE_VOIDP, # hEventLog : HANDLE
-Fiddle::TYPE_SHORT, # wType : REPORT_EVENT_TYPE
-Fiddle::TYPE_SHORT, # wCategory : WORD
-Fiddle::TYPE_INT, # dwEventID : DWORD
Fiddle::TYPE_VOIDP, # lpUserSid : PSID optional
-Fiddle::TYPE_SHORT, # wNumStrings : WORD
-Fiddle::TYPE_INT, # dwDataSize : DWORD
Fiddle::TYPE_VOIDP, # lpStrings : LPCWSTR* optional
Fiddle::TYPE_VOIDP, # lpRawData : void* optional
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "advapi32")]
extern "system" {
fn ReportEventW(
hEventLog: *mut core::ffi::c_void, // HANDLE
wType: u16, // REPORT_EVENT_TYPE
wCategory: u16, // WORD
dwEventID: u32, // DWORD
lpUserSid: *mut core::ffi::c_void, // PSID optional
wNumStrings: u16, // WORD
dwDataSize: u32, // DWORD
lpStrings: *const *const u16, // LPCWSTR* optional
lpRawData: *mut () // void* optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool ReportEventW(IntPtr hEventLog, ushort wType, ushort wCategory, uint dwEventID, IntPtr lpUserSid, ushort wNumStrings, uint dwDataSize, IntPtr lpStrings, IntPtr lpRawData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_ReportEventW' -Namespace Win32 -PassThru
# $api::ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData)#uselib "ADVAPI32.dll"
#func global ReportEventW "ReportEventW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; ReportEventW hEventLog, wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, varptr(lpStrings), lpRawData ; 戻り値は stat
; hEventLog : HANDLE -> "wptr"
; wType : REPORT_EVENT_TYPE -> "wptr"
; wCategory : WORD -> "wptr"
; dwEventID : DWORD -> "wptr"
; lpUserSid : PSID optional -> "wptr"
; wNumStrings : WORD -> "wptr"
; dwDataSize : DWORD -> "wptr"
; lpStrings : LPCWSTR* optional -> "wptr"
; lpRawData : void* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ADVAPI32.dll" #cfunc global ReportEventW "ReportEventW" sptr, int, int, int, sptr, int, int, var, sptr ; res = ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData) ; hEventLog : HANDLE -> "sptr" ; wType : REPORT_EVENT_TYPE -> "int" ; wCategory : WORD -> "int" ; dwEventID : DWORD -> "int" ; lpUserSid : PSID optional -> "sptr" ; wNumStrings : WORD -> "int" ; dwDataSize : DWORD -> "int" ; lpStrings : LPCWSTR* optional -> "var" ; lpRawData : void* optional -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global ReportEventW "ReportEventW" sptr, int, int, int, sptr, int, int, sptr, sptr ; res = ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, varptr(lpStrings), lpRawData) ; hEventLog : HANDLE -> "sptr" ; wType : REPORT_EVENT_TYPE -> "int" ; wCategory : WORD -> "int" ; dwEventID : DWORD -> "int" ; lpUserSid : PSID optional -> "sptr" ; wNumStrings : WORD -> "int" ; dwDataSize : DWORD -> "int" ; lpStrings : LPCWSTR* optional -> "sptr" ; lpRawData : void* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL ReportEventW(HANDLE hEventLog, REPORT_EVENT_TYPE wType, WORD wCategory, DWORD dwEventID, PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCWSTR* lpStrings, void* lpRawData) #uselib "ADVAPI32.dll" #cfunc global ReportEventW "ReportEventW" intptr, int, int, int, intptr, int, int, var, intptr ; res = ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData) ; hEventLog : HANDLE -> "intptr" ; wType : REPORT_EVENT_TYPE -> "int" ; wCategory : WORD -> "int" ; dwEventID : DWORD -> "int" ; lpUserSid : PSID optional -> "intptr" ; wNumStrings : WORD -> "int" ; dwDataSize : DWORD -> "int" ; lpStrings : LPCWSTR* optional -> "var" ; lpRawData : void* optional -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL ReportEventW(HANDLE hEventLog, REPORT_EVENT_TYPE wType, WORD wCategory, DWORD dwEventID, PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCWSTR* lpStrings, void* lpRawData) #uselib "ADVAPI32.dll" #cfunc global ReportEventW "ReportEventW" intptr, int, int, int, intptr, int, int, intptr, intptr ; res = ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, varptr(lpStrings), lpRawData) ; hEventLog : HANDLE -> "intptr" ; wType : REPORT_EVENT_TYPE -> "int" ; wCategory : WORD -> "int" ; dwEventID : DWORD -> "int" ; lpUserSid : PSID optional -> "intptr" ; wNumStrings : WORD -> "int" ; dwDataSize : DWORD -> "int" ; lpStrings : LPCWSTR* optional -> "intptr" ; lpRawData : void* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procReportEventW = advapi32.NewProc("ReportEventW")
)
// hEventLog (HANDLE), wType (REPORT_EVENT_TYPE), wCategory (WORD), dwEventID (DWORD), lpUserSid (PSID optional), wNumStrings (WORD), dwDataSize (DWORD), lpStrings (LPCWSTR* optional), lpRawData (void* optional)
r1, _, err := procReportEventW.Call(
uintptr(hEventLog),
uintptr(wType),
uintptr(wCategory),
uintptr(dwEventID),
uintptr(lpUserSid),
uintptr(wNumStrings),
uintptr(dwDataSize),
uintptr(lpStrings),
uintptr(lpRawData),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction ReportEventW(
hEventLog: THandle; // HANDLE
wType: Word; // REPORT_EVENT_TYPE
wCategory: Word; // WORD
dwEventID: DWORD; // DWORD
lpUserSid: THandle; // PSID optional
wNumStrings: Word; // WORD
dwDataSize: DWORD; // DWORD
lpStrings: PPWideChar; // LPCWSTR* optional
lpRawData: Pointer // void* optional
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'ReportEventW';result := DllCall("ADVAPI32\ReportEventW"
, "Ptr", hEventLog ; HANDLE
, "UShort", wType ; REPORT_EVENT_TYPE
, "UShort", wCategory ; WORD
, "UInt", dwEventID ; DWORD
, "Ptr", lpUserSid ; PSID optional
, "UShort", wNumStrings ; WORD
, "UInt", dwDataSize ; DWORD
, "Ptr", lpStrings ; LPCWSTR* optional
, "Ptr", lpRawData ; void* optional
, "Int") ; return: BOOL●ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData) = DLL("ADVAPI32.dll", "bool ReportEventW(void*, int, int, dword, void*, int, dword, void*, void*)")
# 呼び出し: ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData)
# hEventLog : HANDLE -> "void*"
# wType : REPORT_EVENT_TYPE -> "int"
# wCategory : WORD -> "int"
# dwEventID : DWORD -> "dword"
# lpUserSid : PSID optional -> "void*"
# wNumStrings : WORD -> "int"
# dwDataSize : DWORD -> "dword"
# lpStrings : LPCWSTR* optional -> "void*"
# lpRawData : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。