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