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

ClearEventLogW

関数
イベントログを消去する(Unicode版)。
DLLADVAPI32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL ClearEventLogW(
    HANDLE hEventLog,
    LPCWSTR lpBackupFileName   // optional
);

パラメーター

名前方向
hEventLogHANDLEin
lpBackupFileNameLPCWSTRinoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL ClearEventLogW(
    HANDLE hEventLog,
    LPCWSTR lpBackupFileName   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool ClearEventLogW(
    IntPtr hEventLog,   // HANDLE
    [MarshalAs(UnmanagedType.LPWStr)] string lpBackupFileName   // LPCWSTR optional
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function ClearEventLogW(
    hEventLog As IntPtr,   ' HANDLE
    <MarshalAs(UnmanagedType.LPWStr)> lpBackupFileName As String   ' LPCWSTR optional
) As Boolean
End Function
' hEventLog : HANDLE
' lpBackupFileName : LPCWSTR optional
Declare PtrSafe Function ClearEventLogW Lib "advapi32" ( _
    ByVal hEventLog As LongPtr, _
    ByVal lpBackupFileName 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

ClearEventLogW = ctypes.windll.advapi32.ClearEventLogW
ClearEventLogW.restype = wintypes.BOOL
ClearEventLogW.argtypes = [
    wintypes.HANDLE,  # hEventLog : HANDLE
    wintypes.LPCWSTR,  # lpBackupFileName : LPCWSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
ClearEventLogW = Fiddle::Function.new(
  lib['ClearEventLogW'],
  [
    Fiddle::TYPE_VOIDP,  # hEventLog : HANDLE
    Fiddle::TYPE_VOIDP,  # lpBackupFileName : LPCWSTR optional
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "advapi32")]
extern "system" {
    fn ClearEventLogW(
        hEventLog: *mut core::ffi::c_void,  // HANDLE
        lpBackupFileName: *const u16  // LPCWSTR 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 ClearEventLogW(IntPtr hEventLog, [MarshalAs(UnmanagedType.LPWStr)] string lpBackupFileName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_ClearEventLogW' -Namespace Win32 -PassThru
# $api::ClearEventLogW(hEventLog, lpBackupFileName)
#uselib "ADVAPI32.dll"
#func global ClearEventLogW "ClearEventLogW" wptr, wptr
; ClearEventLogW hEventLog, lpBackupFileName   ; 戻り値は stat
; hEventLog : HANDLE -> "wptr"
; lpBackupFileName : LPCWSTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ADVAPI32.dll"
#cfunc global ClearEventLogW "ClearEventLogW" sptr, wstr
; res = ClearEventLogW(hEventLog, lpBackupFileName)
; hEventLog : HANDLE -> "sptr"
; lpBackupFileName : LPCWSTR optional -> "wstr"
; BOOL ClearEventLogW(HANDLE hEventLog, LPCWSTR lpBackupFileName)
#uselib "ADVAPI32.dll"
#cfunc global ClearEventLogW "ClearEventLogW" intptr, wstr
; res = ClearEventLogW(hEventLog, lpBackupFileName)
; hEventLog : HANDLE -> "intptr"
; lpBackupFileName : LPCWSTR optional -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procClearEventLogW = advapi32.NewProc("ClearEventLogW")
)

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