ホーム › System.EventLog › RegisterEventSourceW
RegisterEventSourceW
関数イベントソースを登録しハンドルを取得する(Unicode版)。
シグネチャ
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
HANDLE RegisterEventSourceW(
LPCWSTR lpUNCServerName, // optional
LPCWSTR lpSourceName
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpUNCServerName | LPCWSTR | inoptional |
| lpSourceName | LPCWSTR | in |
戻り値の型: HANDLE
各言語での呼び出し定義
// 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 版の利用を推奨。