ホーム › NetworkManagement.NetManagement › LogEventW
LogEventW
関数指定種別のイベントをイベントログに記録する(Unicode版)。
シグネチャ
// rtutils.dll (Unicode / -W)
#include <windows.h>
void LogEventW(
DWORD wEventType,
DWORD dwMessageId,
DWORD cNumberOfSubStrings,
LPWSTR* plpwsSubStrings
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| wEventType | DWORD | in | イベントの種類(エラー/警告/情報等)を示す値を指定する。 |
| dwMessageId | DWORD | in | ログに記録するメッセージID(リソースID)を指定する。 |
| cNumberOfSubStrings | DWORD | in | plpwsSubStrings配列内の置換文字列の数を指定する。 |
| plpwsSubStrings | LPWSTR* | in | メッセージ内のプレースホルダを埋める文字列配列(Unicode)。 |
戻り値の型: void
各言語での呼び出し定義
// rtutils.dll (Unicode / -W)
#include <windows.h>
void LogEventW(
DWORD wEventType,
DWORD dwMessageId,
DWORD cNumberOfSubStrings,
LPWSTR* plpwsSubStrings
);[DllImport("rtutils.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern void LogEventW(
uint wEventType, // DWORD
uint dwMessageId, // DWORD
uint cNumberOfSubStrings, // DWORD
IntPtr plpwsSubStrings // LPWSTR*
);<DllImport("rtutils.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Sub LogEventW(
wEventType As UInteger, ' DWORD
dwMessageId As UInteger, ' DWORD
cNumberOfSubStrings As UInteger, ' DWORD
plpwsSubStrings As IntPtr ' LPWSTR*
)
End Sub' wEventType : DWORD
' dwMessageId : DWORD
' cNumberOfSubStrings : DWORD
' plpwsSubStrings : LPWSTR*
Declare PtrSafe Sub LogEventW Lib "rtutils" ( _
ByVal wEventType As Long, _
ByVal dwMessageId As Long, _
ByVal cNumberOfSubStrings As Long, _
ByVal plpwsSubStrings 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
LogEventW = ctypes.windll.rtutils.LogEventW
LogEventW.restype = None
LogEventW.argtypes = [
wintypes.DWORD, # wEventType : DWORD
wintypes.DWORD, # dwMessageId : DWORD
wintypes.DWORD, # cNumberOfSubStrings : DWORD
ctypes.c_void_p, # plpwsSubStrings : LPWSTR*
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('rtutils.dll')
LogEventW = Fiddle::Function.new(
lib['LogEventW'],
[
-Fiddle::TYPE_INT, # wEventType : DWORD
-Fiddle::TYPE_INT, # dwMessageId : DWORD
-Fiddle::TYPE_INT, # cNumberOfSubStrings : DWORD
Fiddle::TYPE_VOIDP, # plpwsSubStrings : LPWSTR*
],
Fiddle::TYPE_VOID)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "rtutils")]
extern "system" {
fn LogEventW(
wEventType: u32, // DWORD
dwMessageId: u32, // DWORD
cNumberOfSubStrings: u32, // DWORD
plpwsSubStrings: *mut *mut u16 // LPWSTR*
);
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("rtutils.dll", CharSet = CharSet.Unicode)]
public static extern void LogEventW(uint wEventType, uint dwMessageId, uint cNumberOfSubStrings, IntPtr plpwsSubStrings);
"@
$api = Add-Type -MemberDefinition $sig -Name 'rtutils_LogEventW' -Namespace Win32 -PassThru
# $api::LogEventW(wEventType, dwMessageId, cNumberOfSubStrings, plpwsSubStrings)#uselib "rtutils.dll"
#func global LogEventW "LogEventW" wptr, wptr, wptr, wptr
; LogEventW wEventType, dwMessageId, cNumberOfSubStrings, varptr(plpwsSubStrings)
; wEventType : DWORD -> "wptr"
; dwMessageId : DWORD -> "wptr"
; cNumberOfSubStrings : DWORD -> "wptr"
; plpwsSubStrings : LPWSTR* -> "wptr"出力引数:
#uselib "rtutils.dll" #func global LogEventW "LogEventW" int, int, int, var ; LogEventW wEventType, dwMessageId, cNumberOfSubStrings, plpwsSubStrings ; wEventType : DWORD -> "int" ; dwMessageId : DWORD -> "int" ; cNumberOfSubStrings : DWORD -> "int" ; plpwsSubStrings : LPWSTR* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "rtutils.dll" #func global LogEventW "LogEventW" int, int, int, sptr ; LogEventW wEventType, dwMessageId, cNumberOfSubStrings, varptr(plpwsSubStrings) ; wEventType : DWORD -> "int" ; dwMessageId : DWORD -> "int" ; cNumberOfSubStrings : DWORD -> "int" ; plpwsSubStrings : LPWSTR* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; void LogEventW(DWORD wEventType, DWORD dwMessageId, DWORD cNumberOfSubStrings, LPWSTR* plpwsSubStrings) #uselib "rtutils.dll" #func global LogEventW "LogEventW" int, int, int, var ; LogEventW wEventType, dwMessageId, cNumberOfSubStrings, plpwsSubStrings ; wEventType : DWORD -> "int" ; dwMessageId : DWORD -> "int" ; cNumberOfSubStrings : DWORD -> "int" ; plpwsSubStrings : LPWSTR* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; void LogEventW(DWORD wEventType, DWORD dwMessageId, DWORD cNumberOfSubStrings, LPWSTR* plpwsSubStrings) #uselib "rtutils.dll" #func global LogEventW "LogEventW" int, int, int, intptr ; LogEventW wEventType, dwMessageId, cNumberOfSubStrings, varptr(plpwsSubStrings) ; wEventType : DWORD -> "int" ; dwMessageId : DWORD -> "int" ; cNumberOfSubStrings : DWORD -> "int" ; plpwsSubStrings : LPWSTR* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
rtutils = windows.NewLazySystemDLL("rtutils.dll")
procLogEventW = rtutils.NewProc("LogEventW")
)
// wEventType (DWORD), dwMessageId (DWORD), cNumberOfSubStrings (DWORD), plpwsSubStrings (LPWSTR*)
r1, _, err := procLogEventW.Call(
uintptr(wEventType),
uintptr(dwMessageId),
uintptr(cNumberOfSubStrings),
uintptr(plpwsSubStrings),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // voidprocedure LogEventW(
wEventType: DWORD; // DWORD
dwMessageId: DWORD; // DWORD
cNumberOfSubStrings: DWORD; // DWORD
plpwsSubStrings: PPWideChar // LPWSTR*
); stdcall;
external 'rtutils.dll' name 'LogEventW';result := DllCall("rtutils\LogEventW"
, "UInt", wEventType ; DWORD
, "UInt", dwMessageId ; DWORD
, "UInt", cNumberOfSubStrings ; DWORD
, "Ptr", plpwsSubStrings ; LPWSTR*
, "Int") ; return: void●LogEventW(wEventType, dwMessageId, cNumberOfSubStrings, plpwsSubStrings) = DLL("rtutils.dll", "int LogEventW(dword, dword, dword, void*)")
# 呼び出し: LogEventW(wEventType, dwMessageId, cNumberOfSubStrings, plpwsSubStrings)
# wEventType : DWORD -> "dword"
# dwMessageId : DWORD -> "dword"
# cNumberOfSubStrings : DWORD -> "dword"
# plpwsSubStrings : LPWSTR* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "rtutils" fn LogEventW(
wEventType: u32, // DWORD
dwMessageId: u32, // DWORD
cNumberOfSubStrings: u32, // DWORD
plpwsSubStrings: [*c][*c]u16 // LPWSTR*
) callconv(std.os.windows.WINAPI) void;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc LogEventW(
wEventType: uint32, # DWORD
dwMessageId: uint32, # DWORD
cNumberOfSubStrings: uint32, # DWORD
plpwsSubStrings: ptr WideCString # LPWSTR*
) {.importc: "LogEventW", stdcall, dynlib: "rtutils.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "rtutils");
extern(Windows)
void LogEventW(
uint wEventType, // DWORD
uint dwMessageId, // DWORD
uint cNumberOfSubStrings, // DWORD
wchar** plpwsSubStrings // LPWSTR*
);ccall((:LogEventW, "rtutils.dll"), stdcall, Cvoid,
(UInt32, UInt32, UInt32, Ptr{Ptr{UInt16}}),
wEventType, dwMessageId, cNumberOfSubStrings, plpwsSubStrings)
# wEventType : DWORD -> UInt32
# dwMessageId : DWORD -> UInt32
# cNumberOfSubStrings : DWORD -> UInt32
# plpwsSubStrings : LPWSTR* -> Ptr{Ptr{UInt16}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
void LogEventW(
uint32_t wEventType,
uint32_t dwMessageId,
uint32_t cNumberOfSubStrings,
uint16_t** plpwsSubStrings);
]]
local rtutils = ffi.load("rtutils")
-- rtutils.LogEventW(wEventType, dwMessageId, cNumberOfSubStrings, plpwsSubStrings)
-- wEventType : DWORD
-- dwMessageId : DWORD
-- cNumberOfSubStrings : DWORD
-- plpwsSubStrings : LPWSTR*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('rtutils.dll');
const LogEventW = lib.func('__stdcall', 'LogEventW', 'void', ['uint32_t', 'uint32_t', 'uint32_t', 'void *']);
// LogEventW(wEventType, dwMessageId, cNumberOfSubStrings, plpwsSubStrings)
// wEventType : DWORD -> 'uint32_t'
// dwMessageId : DWORD -> 'uint32_t'
// cNumberOfSubStrings : DWORD -> 'uint32_t'
// plpwsSubStrings : LPWSTR* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("rtutils.dll", {
LogEventW: { parameters: ["u32", "u32", "u32", "pointer"], result: "void" },
});
// lib.symbols.LogEventW(wEventType, dwMessageId, cNumberOfSubStrings, plpwsSubStrings)
// wEventType : DWORD -> "u32"
// dwMessageId : DWORD -> "u32"
// cNumberOfSubStrings : DWORD -> "u32"
// plpwsSubStrings : LPWSTR* -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void LogEventW(
uint32_t wEventType,
uint32_t dwMessageId,
uint32_t cNumberOfSubStrings,
uint16_t** plpwsSubStrings);
C, "rtutils.dll");
// $ffi->LogEventW(wEventType, dwMessageId, cNumberOfSubStrings, plpwsSubStrings);
// wEventType : DWORD
// dwMessageId : DWORD
// cNumberOfSubStrings : DWORD
// plpwsSubStrings : LPWSTR*
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Rtutils extends StdCallLibrary {
Rtutils INSTANCE = Native.load("rtutils", Rtutils.class, W32APIOptions.UNICODE_OPTIONS);
void LogEventW(
int wEventType, // DWORD
int dwMessageId, // DWORD
int cNumberOfSubStrings, // DWORD
PointerByReference plpwsSubStrings // LPWSTR*
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("rtutils")]
lib Librtutils
fun LogEventW = LogEventW(
wEventType : UInt32, # DWORD
dwMessageId : UInt32, # DWORD
cNumberOfSubStrings : UInt32, # DWORD
plpwsSubStrings : UInt16** # LPWSTR*
) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef LogEventWNative = Void Function(Uint32, Uint32, Uint32, Pointer<Pointer<Utf16>>);
typedef LogEventWDart = void Function(int, int, int, Pointer<Pointer<Utf16>>);
final LogEventW = DynamicLibrary.open('rtutils.dll')
.lookupFunction<LogEventWNative, LogEventWDart>('LogEventW');
// wEventType : DWORD -> Uint32
// dwMessageId : DWORD -> Uint32
// cNumberOfSubStrings : DWORD -> Uint32
// plpwsSubStrings : LPWSTR* -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
procedure LogEventW(
wEventType: DWORD; // DWORD
dwMessageId: DWORD; // DWORD
cNumberOfSubStrings: DWORD; // DWORD
plpwsSubStrings: PPWideChar // LPWSTR*
); stdcall;
external 'rtutils.dll' name 'LogEventW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "LogEventW"
c_LogEventW :: Word32 -> Word32 -> Word32 -> Ptr CWString -> IO ()
-- wEventType : DWORD -> Word32
-- dwMessageId : DWORD -> Word32
-- cNumberOfSubStrings : DWORD -> Word32
-- plpwsSubStrings : LPWSTR* -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let logeventw =
foreign "LogEventW"
(uint32_t @-> uint32_t @-> uint32_t @-> (ptr (ptr uint16_t)) @-> returning void)
(* wEventType : DWORD -> uint32_t *)
(* dwMessageId : DWORD -> uint32_t *)
(* cNumberOfSubStrings : DWORD -> uint32_t *)
(* plpwsSubStrings : LPWSTR* -> (ptr (ptr uint16_t)) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library rtutils (t "rtutils.dll"))
(cffi:use-foreign-library rtutils)
(cffi:defcfun ("LogEventW" log-event-w :convention :stdcall) :void
(w-event-type :uint32) ; DWORD
(dw-message-id :uint32) ; DWORD
(c-number-of-sub-strings :uint32) ; DWORD
(plpws-sub-strings :pointer)) ; LPWSTR*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $LogEventW = Win32::API::More->new('rtutils',
'void LogEventW(DWORD wEventType, DWORD dwMessageId, DWORD cNumberOfSubStrings, LPVOID plpwsSubStrings)');
# my $ret = $LogEventW->Call($wEventType, $dwMessageId, $cNumberOfSubStrings, $plpwsSubStrings);
# wEventType : DWORD -> DWORD
# dwMessageId : DWORD -> DWORD
# cNumberOfSubStrings : DWORD -> DWORD
# plpwsSubStrings : LPWSTR* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f LogEventA (ANSI版) — 指定種別のイベントをイベントログに記録する(ANSI版)。