ホーム › System.EventLog › ReportEventA
ReportEventA
関数イベントログにエントリを書き込む(ANSI版)。
シグネチャ
// ADVAPI32.dll (ANSI / -A)
#include <windows.h>
BOOL ReportEventA(
HANDLE hEventLog,
REPORT_EVENT_TYPE wType,
WORD wCategory,
DWORD dwEventID,
PSID lpUserSid, // optional
WORD wNumStrings,
DWORD dwDataSize,
LPCSTR* 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 | LPCSTR* | inoptional |
| lpRawData | void* | inoptional |
戻り値の型: BOOL
各言語での呼び出し定義
// ADVAPI32.dll (ANSI / -A)
#include <windows.h>
BOOL ReportEventA(
HANDLE hEventLog,
REPORT_EVENT_TYPE wType,
WORD wCategory,
DWORD dwEventID,
PSID lpUserSid, // optional
WORD wNumStrings,
DWORD dwDataSize,
LPCSTR* lpStrings, // optional
void* lpRawData // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool ReportEventA(
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, // LPCSTR* optional
IntPtr lpRawData // void* optional
);<DllImport("ADVAPI32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function ReportEventA(
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, ' LPCSTR* 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 : LPCSTR* optional
' lpRawData : void* optional
Declare PtrSafe Function ReportEventA 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
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ReportEventA = ctypes.windll.advapi32.ReportEventA
ReportEventA.restype = wintypes.BOOL
ReportEventA.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 : LPCSTR* 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')
ReportEventA = Fiddle::Function.new(
lib['ReportEventA'],
[
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 : LPCSTR* optional
Fiddle::TYPE_VOIDP, # lpRawData : void* optional
],
Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn ReportEventA(
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 u8, // LPCSTR* 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.Ansi, SetLastError = true)]
public static extern bool ReportEventA(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_ReportEventA' -Namespace Win32 -PassThru
# $api::ReportEventA(hEventLog, wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData)#uselib "ADVAPI32.dll"
#func global ReportEventA "ReportEventA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; ReportEventA hEventLog, wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, varptr(lpStrings), lpRawData ; 戻り値は stat
; hEventLog : HANDLE -> "sptr"
; wType : REPORT_EVENT_TYPE -> "sptr"
; wCategory : WORD -> "sptr"
; dwEventID : DWORD -> "sptr"
; lpUserSid : PSID optional -> "sptr"
; wNumStrings : WORD -> "sptr"
; dwDataSize : DWORD -> "sptr"
; lpStrings : LPCSTR* optional -> "sptr"
; lpRawData : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ADVAPI32.dll" #cfunc global ReportEventA "ReportEventA" sptr, int, int, int, sptr, int, int, var, sptr ; res = ReportEventA(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 : LPCSTR* optional -> "var" ; lpRawData : void* optional -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global ReportEventA "ReportEventA" sptr, int, int, int, sptr, int, int, sptr, sptr ; res = ReportEventA(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 : LPCSTR* optional -> "sptr" ; lpRawData : void* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL ReportEventA(HANDLE hEventLog, REPORT_EVENT_TYPE wType, WORD wCategory, DWORD dwEventID, PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCSTR* lpStrings, void* lpRawData) #uselib "ADVAPI32.dll" #cfunc global ReportEventA "ReportEventA" intptr, int, int, int, intptr, int, int, var, intptr ; res = ReportEventA(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 : LPCSTR* optional -> "var" ; lpRawData : void* optional -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL ReportEventA(HANDLE hEventLog, REPORT_EVENT_TYPE wType, WORD wCategory, DWORD dwEventID, PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCSTR* lpStrings, void* lpRawData) #uselib "ADVAPI32.dll" #cfunc global ReportEventA "ReportEventA" intptr, int, int, int, intptr, int, int, intptr, intptr ; res = ReportEventA(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 : LPCSTR* optional -> "intptr" ; lpRawData : void* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procReportEventA = advapi32.NewProc("ReportEventA")
)
// hEventLog (HANDLE), wType (REPORT_EVENT_TYPE), wCategory (WORD), dwEventID (DWORD), lpUserSid (PSID optional), wNumStrings (WORD), dwDataSize (DWORD), lpStrings (LPCSTR* optional), lpRawData (void* optional)
r1, _, err := procReportEventA.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 ReportEventA(
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: PPAnsiChar; // LPCSTR* optional
lpRawData: Pointer // void* optional
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'ReportEventA';result := DllCall("ADVAPI32\ReportEventA"
, "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 ; LPCSTR* optional
, "Ptr", lpRawData ; void* optional
, "Int") ; return: BOOL●ReportEventA(hEventLog, wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData) = DLL("ADVAPI32.dll", "bool ReportEventA(void*, int, int, dword, void*, int, dword, void*, void*)")
# 呼び出し: ReportEventA(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 : LPCSTR* optional -> "void*"
# lpRawData : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。