RegisterEventSourceW
関数シグネチャ
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
HANDLE RegisterEventSourceW(
LPCWSTR lpUNCServerName, // optional
LPCWSTR lpSourceName
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpUNCServerName | LPCWSTR | inoptional | この操作を実行するリモートサーバーの UNC (Universal Naming Convention) 名。このパラメーターが NULL の場合は、ローカルコンピューターが使用されます。 |
| lpSourceName | LPCWSTR | in | ハンドルを取得する イベントソースの名前。ソース名は、Eventlog レジストリキー配下にあるログのサブキーである必要があります。 なお、Security ログはシステム専用です。 Note この文字列には、< や > などの XML エスケープシーケンスを除き、XML 属性で使用できない文字を含めることはできません。
|
戻り値の型: HANDLE
公式ドキュメント
指定したイベントログに登録済みのハンドルを取得します。(Unicode)
戻り値
関数が成功した場合、戻り値はイベントログへのハンドルです。
関数が失敗した場合、戻り値は NULL です。拡張エラー情報を取得するには、 GetLastError を呼び出します。
lpSourceName に Security イベントログを指定した場合、関数は ERROR_ACCESS_DENIED を返します。
解説(Remarks)
ソース名が見つからない場合、イベントログサービスは Application ログを使用します。イベントは報告されますが、イベント識別子に関連する説明を参照するためのメッセージファイルおよびカテゴリメッセージファイルが存在しないため、説明は含まれません。
イベントログへのハンドルを閉じるには、 DeregisterEventSource 関数を使用します。
例
例については、 Reporting an Event を参照してください。
winbase.h ヘッダーは RegisterEventSource をエイリアスとして定義しており、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択します。エンコーディング非依存のエイリアスを、エンコーディング非依存でないコードと混在して使用すると、不一致が生じてコンパイルエラーまたは実行時エラーの原因となる場合があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
HANDLE RegisterEventSourceW(
LPCWSTR lpUNCServerName, // optional
LPCWSTR lpSourceName
);[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr RegisterEventSourceW(
[MarshalAs(UnmanagedType.LPWStr)] string lpUNCServerName, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string lpSourceName // LPCWSTR
);<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function RegisterEventSourceW(
<MarshalAs(UnmanagedType.LPWStr)> lpUNCServerName As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> lpSourceName As String ' LPCWSTR
) As IntPtr
End Function' lpUNCServerName : LPCWSTR optional
' lpSourceName : LPCWSTR
Declare PtrSafe Function RegisterEventSourceW Lib "advapi32" ( _
ByVal lpUNCServerName As LongPtr, _
ByVal lpSourceName As LongPtr) 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
RegisterEventSourceW = ctypes.windll.advapi32.RegisterEventSourceW
RegisterEventSourceW.restype = ctypes.c_void_p
RegisterEventSourceW.argtypes = [
wintypes.LPCWSTR, # lpUNCServerName : LPCWSTR optional
wintypes.LPCWSTR, # lpSourceName : LPCWSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
RegisterEventSourceW = Fiddle::Function.new(
lib['RegisterEventSourceW'],
[
Fiddle::TYPE_VOIDP, # lpUNCServerName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # lpSourceName : LPCWSTR
],
Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "advapi32")]
extern "system" {
fn RegisterEventSourceW(
lpUNCServerName: *const u16, // LPCWSTR optional
lpSourceName: *const u16 // LPCWSTR
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr RegisterEventSourceW([MarshalAs(UnmanagedType.LPWStr)] string lpUNCServerName, [MarshalAs(UnmanagedType.LPWStr)] string lpSourceName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_RegisterEventSourceW' -Namespace Win32 -PassThru
# $api::RegisterEventSourceW(lpUNCServerName, lpSourceName)#uselib "ADVAPI32.dll"
#func global RegisterEventSourceW "RegisterEventSourceW" wptr, wptr
; RegisterEventSourceW lpUNCServerName, lpSourceName ; 戻り値は stat
; lpUNCServerName : LPCWSTR optional -> "wptr"
; lpSourceName : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ADVAPI32.dll"
#cfunc global RegisterEventSourceW "RegisterEventSourceW" wstr, wstr
; res = RegisterEventSourceW(lpUNCServerName, lpSourceName)
; lpUNCServerName : LPCWSTR optional -> "wstr"
; lpSourceName : LPCWSTR -> "wstr"; HANDLE RegisterEventSourceW(LPCWSTR lpUNCServerName, LPCWSTR lpSourceName)
#uselib "ADVAPI32.dll"
#cfunc global RegisterEventSourceW "RegisterEventSourceW" wstr, wstr
; res = RegisterEventSourceW(lpUNCServerName, lpSourceName)
; lpUNCServerName : LPCWSTR optional -> "wstr"
; lpSourceName : LPCWSTR -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procRegisterEventSourceW = advapi32.NewProc("RegisterEventSourceW")
)
// lpUNCServerName (LPCWSTR optional), lpSourceName (LPCWSTR)
r1, _, err := procRegisterEventSourceW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpUNCServerName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpSourceName))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HANDLEfunction RegisterEventSourceW(
lpUNCServerName: PWideChar; // LPCWSTR optional
lpSourceName: PWideChar // LPCWSTR
): THandle; stdcall;
external 'ADVAPI32.dll' name 'RegisterEventSourceW';result := DllCall("ADVAPI32\RegisterEventSourceW"
, "WStr", lpUNCServerName ; LPCWSTR optional
, "WStr", lpSourceName ; LPCWSTR
, "Ptr") ; return: HANDLE●RegisterEventSourceW(lpUNCServerName, lpSourceName) = DLL("ADVAPI32.dll", "void* RegisterEventSourceW(char*, char*)")
# 呼び出し: RegisterEventSourceW(lpUNCServerName, lpSourceName)
# lpUNCServerName : LPCWSTR optional -> "char*"
# lpSourceName : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "advapi32" fn RegisterEventSourceW(
lpUNCServerName: [*c]const u16, // LPCWSTR optional
lpSourceName: [*c]const u16 // LPCWSTR
) callconv(std.os.windows.WINAPI) ?*anyopaque;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc RegisterEventSourceW(
lpUNCServerName: WideCString, # LPCWSTR optional
lpSourceName: WideCString # LPCWSTR
): pointer {.importc: "RegisterEventSourceW", stdcall, dynlib: "ADVAPI32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "advapi32");
extern(Windows)
void* RegisterEventSourceW(
const(wchar)* lpUNCServerName, // LPCWSTR optional
const(wchar)* lpSourceName // LPCWSTR
);ccall((:RegisterEventSourceW, "ADVAPI32.dll"), stdcall, Ptr{Cvoid},
(Cwstring, Cwstring),
lpUNCServerName, lpSourceName)
# lpUNCServerName : LPCWSTR optional -> Cwstring
# lpSourceName : LPCWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
void* RegisterEventSourceW(
const uint16_t* lpUNCServerName,
const uint16_t* lpSourceName);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.RegisterEventSourceW(lpUNCServerName, lpSourceName)
-- lpUNCServerName : LPCWSTR optional
-- lpSourceName : LPCWSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const RegisterEventSourceW = lib.func('__stdcall', 'RegisterEventSourceW', 'void *', ['str16', 'str16']);
// RegisterEventSourceW(lpUNCServerName, lpSourceName)
// lpUNCServerName : LPCWSTR optional -> 'str16'
// lpSourceName : LPCWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
RegisterEventSourceW: { parameters: ["buffer", "buffer"], result: "pointer" },
});
// lib.symbols.RegisterEventSourceW(lpUNCServerName, lpSourceName)
// lpUNCServerName : LPCWSTR optional -> "buffer"
// lpSourceName : LPCWSTR -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* RegisterEventSourceW(
const uint16_t* lpUNCServerName,
const uint16_t* lpSourceName);
C, "ADVAPI32.dll");
// $ffi->RegisterEventSourceW(lpUNCServerName, lpSourceName);
// lpUNCServerName : LPCWSTR optional
// lpSourceName : LPCWSTR
// 構造体/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 Advapi32 extends StdCallLibrary {
Advapi32 INSTANCE = Native.load("advapi32", Advapi32.class, W32APIOptions.UNICODE_OPTIONS);
Pointer RegisterEventSourceW(
WString lpUNCServerName, // LPCWSTR optional
WString lpSourceName // LPCWSTR
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("advapi32")]
lib LibADVAPI32
fun RegisterEventSourceW = RegisterEventSourceW(
lpUNCServerName : UInt16*, # LPCWSTR optional
lpSourceName : UInt16* # LPCWSTR
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef RegisterEventSourceWNative = Pointer<Void> Function(Pointer<Utf16>, Pointer<Utf16>);
typedef RegisterEventSourceWDart = Pointer<Void> Function(Pointer<Utf16>, Pointer<Utf16>);
final RegisterEventSourceW = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<RegisterEventSourceWNative, RegisterEventSourceWDart>('RegisterEventSourceW');
// lpUNCServerName : LPCWSTR optional -> Pointer<Utf16>
// lpSourceName : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function RegisterEventSourceW(
lpUNCServerName: PWideChar; // LPCWSTR optional
lpSourceName: PWideChar // LPCWSTR
): THandle; stdcall;
external 'ADVAPI32.dll' name 'RegisterEventSourceW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "RegisterEventSourceW"
c_RegisterEventSourceW :: CWString -> CWString -> IO (Ptr ())
-- lpUNCServerName : LPCWSTR optional -> CWString
-- lpSourceName : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let registereventsourcew =
foreign "RegisterEventSourceW"
((ptr uint16_t) @-> (ptr uint16_t) @-> returning (ptr void))
(* lpUNCServerName : LPCWSTR optional -> (ptr uint16_t) *)
(* lpSourceName : LPCWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)
(cffi:defcfun ("RegisterEventSourceW" register-event-source-w :convention :stdcall) :pointer
(lp-uncserver-name (:string :encoding :utf-16le)) ; LPCWSTR optional
(lp-source-name (:string :encoding :utf-16le))) ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $RegisterEventSourceW = Win32::API::More->new('ADVAPI32',
'HANDLE RegisterEventSourceW(LPCWSTR lpUNCServerName, LPCWSTR lpSourceName)');
# my $ret = $RegisterEventSourceW->Call($lpUNCServerName, $lpSourceName);
# lpUNCServerName : LPCWSTR optional -> LPCWSTR
# lpSourceName : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f RegisterEventSourceA (ANSI版) — イベントソースを登録しハンドルを取得する(ANSI版)。
- f DeregisterEventSource — イベントソースのハンドルを登録解除して閉じる。
- f ReportEventW — イベントログにエントリを書き込む(Unicode版)。