Win32 API 日本語リファレンス
ホームNetworkManagement.NetManagement › NetAuditRead

NetAuditRead

関数
サーバーの監査ログから記録されたエントリを読み取る。
DLLNETAPI32.dll呼出規約winapi

シグネチャ

// NETAPI32.dll
#include <windows.h>

DWORD NetAuditRead(
    LPCWSTR server,
    LPCWSTR service,
    HLOG* auditloghandle,
    DWORD offset,
    DWORD* reserved1,
    DWORD reserved2,
    DWORD offsetflag,
    BYTE** bufptr,
    DWORD prefmaxlen,
    DWORD* bytesread,
    DWORD* totalavailable
);

パラメーター

名前方向説明
serverLPCWSTRin対象サーバーのUNC名。NULLでローカルコンピューターを対象とする。
serviceLPCWSTRin予約済み。NULLを指定する必要がある。
auditloghandleHLOG*inout監査ログハンドル。予約用でNULLを指す変数を渡す。
offsetDWORDin読み込み開始位置のオフセット。offsetflagと併用する。
reserved1DWORD*inout予約済み。NULLを指定する必要がある。
reserved2DWORDin予約済み。0を指定する必要がある。
offsetflagDWORDinオフセットの基準を示すフラグ。先頭/末尾/指定位置を選ぶ。
bufptrBYTE**inout読み込んだ監査レコードのバッファを受け取るポインター。使用後NetApiBufferFreeで解放する。
prefmaxlenDWORDin返却データの推奨最大バイト数を指定する。
bytesreadDWORD*inout実際に読み込まれたバイト数を受け取る出力ポインター。
totalavailableDWORD*inout利用可能な総バイト数を受け取る出力ポインター。

戻り値の型: DWORD

各言語での呼び出し定義

// NETAPI32.dll
#include <windows.h>

DWORD NetAuditRead(
    LPCWSTR server,
    LPCWSTR service,
    HLOG* auditloghandle,
    DWORD offset,
    DWORD* reserved1,
    DWORD reserved2,
    DWORD offsetflag,
    BYTE** bufptr,
    DWORD prefmaxlen,
    DWORD* bytesread,
    DWORD* totalavailable
);
[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern uint NetAuditRead(
    [MarshalAs(UnmanagedType.LPWStr)] string server,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string service,   // LPCWSTR
    IntPtr auditloghandle,   // HLOG* in/out
    uint offset,   // DWORD
    ref uint reserved1,   // DWORD* in/out
    uint reserved2,   // DWORD
    uint offsetflag,   // DWORD
    IntPtr bufptr,   // BYTE** in/out
    uint prefmaxlen,   // DWORD
    ref uint bytesread,   // DWORD* in/out
    ref uint totalavailable   // DWORD* in/out
);
<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function NetAuditRead(
    <MarshalAs(UnmanagedType.LPWStr)> server As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> service As String,   ' LPCWSTR
    auditloghandle As IntPtr,   ' HLOG* in/out
    offset As UInteger,   ' DWORD
    ByRef reserved1 As UInteger,   ' DWORD* in/out
    reserved2 As UInteger,   ' DWORD
    offsetflag As UInteger,   ' DWORD
    bufptr As IntPtr,   ' BYTE** in/out
    prefmaxlen As UInteger,   ' DWORD
    ByRef bytesread As UInteger,   ' DWORD* in/out
    ByRef totalavailable As UInteger   ' DWORD* in/out
) As UInteger
End Function
' server : LPCWSTR
' service : LPCWSTR
' auditloghandle : HLOG* in/out
' offset : DWORD
' reserved1 : DWORD* in/out
' reserved2 : DWORD
' offsetflag : DWORD
' bufptr : BYTE** in/out
' prefmaxlen : DWORD
' bytesread : DWORD* in/out
' totalavailable : DWORD* in/out
Declare PtrSafe Function NetAuditRead Lib "netapi32" ( _
    ByVal server As LongPtr, _
    ByVal service As LongPtr, _
    ByVal auditloghandle As LongPtr, _
    ByVal offset As Long, _
    ByRef reserved1 As Long, _
    ByVal reserved2 As Long, _
    ByVal offsetflag As Long, _
    ByVal bufptr As LongPtr, _
    ByVal prefmaxlen As Long, _
    ByRef bytesread As Long, _
    ByRef totalavailable As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

NetAuditRead = ctypes.windll.netapi32.NetAuditRead
NetAuditRead.restype = wintypes.DWORD
NetAuditRead.argtypes = [
    wintypes.LPCWSTR,  # server : LPCWSTR
    wintypes.LPCWSTR,  # service : LPCWSTR
    ctypes.c_void_p,  # auditloghandle : HLOG* in/out
    wintypes.DWORD,  # offset : DWORD
    ctypes.POINTER(wintypes.DWORD),  # reserved1 : DWORD* in/out
    wintypes.DWORD,  # reserved2 : DWORD
    wintypes.DWORD,  # offsetflag : DWORD
    ctypes.c_void_p,  # bufptr : BYTE** in/out
    wintypes.DWORD,  # prefmaxlen : DWORD
    ctypes.POINTER(wintypes.DWORD),  # bytesread : DWORD* in/out
    ctypes.POINTER(wintypes.DWORD),  # totalavailable : DWORD* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('NETAPI32.dll')
NetAuditRead = Fiddle::Function.new(
  lib['NetAuditRead'],
  [
    Fiddle::TYPE_VOIDP,  # server : LPCWSTR
    Fiddle::TYPE_VOIDP,  # service : LPCWSTR
    Fiddle::TYPE_VOIDP,  # auditloghandle : HLOG* in/out
    -Fiddle::TYPE_INT,  # offset : DWORD
    Fiddle::TYPE_VOIDP,  # reserved1 : DWORD* in/out
    -Fiddle::TYPE_INT,  # reserved2 : DWORD
    -Fiddle::TYPE_INT,  # offsetflag : DWORD
    Fiddle::TYPE_VOIDP,  # bufptr : BYTE** in/out
    -Fiddle::TYPE_INT,  # prefmaxlen : DWORD
    Fiddle::TYPE_VOIDP,  # bytesread : DWORD* in/out
    Fiddle::TYPE_VOIDP,  # totalavailable : DWORD* in/out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "netapi32")]
extern "system" {
    fn NetAuditRead(
        server: *const u16,  // LPCWSTR
        service: *const u16,  // LPCWSTR
        auditloghandle: *mut HLOG,  // HLOG* in/out
        offset: u32,  // DWORD
        reserved1: *mut u32,  // DWORD* in/out
        reserved2: u32,  // DWORD
        offsetflag: u32,  // DWORD
        bufptr: *mut *mut u8,  // BYTE** in/out
        prefmaxlen: u32,  // DWORD
        bytesread: *mut u32,  // DWORD* in/out
        totalavailable: *mut u32  // DWORD* in/out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("NETAPI32.dll")]
public static extern uint NetAuditRead([MarshalAs(UnmanagedType.LPWStr)] string server, [MarshalAs(UnmanagedType.LPWStr)] string service, IntPtr auditloghandle, uint offset, ref uint reserved1, uint reserved2, uint offsetflag, IntPtr bufptr, uint prefmaxlen, ref uint bytesread, ref uint totalavailable);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NETAPI32_NetAuditRead' -Namespace Win32 -PassThru
# $api::NetAuditRead(server, service, auditloghandle, offset, reserved1, reserved2, offsetflag, bufptr, prefmaxlen, bytesread, totalavailable)
#uselib "NETAPI32.dll"
#func global NetAuditRead "NetAuditRead" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; NetAuditRead server, service, varptr(auditloghandle), offset, varptr(reserved1), reserved2, offsetflag, varptr(bufptr), prefmaxlen, varptr(bytesread), varptr(totalavailable)   ; 戻り値は stat
; server : LPCWSTR -> "sptr"
; service : LPCWSTR -> "sptr"
; auditloghandle : HLOG* in/out -> "sptr"
; offset : DWORD -> "sptr"
; reserved1 : DWORD* in/out -> "sptr"
; reserved2 : DWORD -> "sptr"
; offsetflag : DWORD -> "sptr"
; bufptr : BYTE** in/out -> "sptr"
; prefmaxlen : DWORD -> "sptr"
; bytesread : DWORD* in/out -> "sptr"
; totalavailable : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "NETAPI32.dll"
#cfunc global NetAuditRead "NetAuditRead" wstr, wstr, var, int, var, int, int, var, int, var, var
; res = NetAuditRead(server, service, auditloghandle, offset, reserved1, reserved2, offsetflag, bufptr, prefmaxlen, bytesread, totalavailable)
; server : LPCWSTR -> "wstr"
; service : LPCWSTR -> "wstr"
; auditloghandle : HLOG* in/out -> "var"
; offset : DWORD -> "int"
; reserved1 : DWORD* in/out -> "var"
; reserved2 : DWORD -> "int"
; offsetflag : DWORD -> "int"
; bufptr : BYTE** in/out -> "var"
; prefmaxlen : DWORD -> "int"
; bytesread : DWORD* in/out -> "var"
; totalavailable : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD NetAuditRead(LPCWSTR server, LPCWSTR service, HLOG* auditloghandle, DWORD offset, DWORD* reserved1, DWORD reserved2, DWORD offsetflag, BYTE** bufptr, DWORD prefmaxlen, DWORD* bytesread, DWORD* totalavailable)
#uselib "NETAPI32.dll"
#cfunc global NetAuditRead "NetAuditRead" wstr, wstr, var, int, var, int, int, var, int, var, var
; res = NetAuditRead(server, service, auditloghandle, offset, reserved1, reserved2, offsetflag, bufptr, prefmaxlen, bytesread, totalavailable)
; server : LPCWSTR -> "wstr"
; service : LPCWSTR -> "wstr"
; auditloghandle : HLOG* in/out -> "var"
; offset : DWORD -> "int"
; reserved1 : DWORD* in/out -> "var"
; reserved2 : DWORD -> "int"
; offsetflag : DWORD -> "int"
; bufptr : BYTE** in/out -> "var"
; prefmaxlen : DWORD -> "int"
; bytesread : DWORD* in/out -> "var"
; totalavailable : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
	procNetAuditRead = netapi32.NewProc("NetAuditRead")
)

// server (LPCWSTR), service (LPCWSTR), auditloghandle (HLOG* in/out), offset (DWORD), reserved1 (DWORD* in/out), reserved2 (DWORD), offsetflag (DWORD), bufptr (BYTE** in/out), prefmaxlen (DWORD), bytesread (DWORD* in/out), totalavailable (DWORD* in/out)
r1, _, err := procNetAuditRead.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(server))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(service))),
	uintptr(auditloghandle),
	uintptr(offset),
	uintptr(reserved1),
	uintptr(reserved2),
	uintptr(offsetflag),
	uintptr(bufptr),
	uintptr(prefmaxlen),
	uintptr(bytesread),
	uintptr(totalavailable),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function NetAuditRead(
  server: PWideChar;   // LPCWSTR
  service: PWideChar;   // LPCWSTR
  auditloghandle: Pointer;   // HLOG* in/out
  offset: DWORD;   // DWORD
  reserved1: Pointer;   // DWORD* in/out
  reserved2: DWORD;   // DWORD
  offsetflag: DWORD;   // DWORD
  bufptr: Pointer;   // BYTE** in/out
  prefmaxlen: DWORD;   // DWORD
  bytesread: Pointer;   // DWORD* in/out
  totalavailable: Pointer   // DWORD* in/out
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'NetAuditRead';
result := DllCall("NETAPI32\NetAuditRead"
    , "WStr", server   ; LPCWSTR
    , "WStr", service   ; LPCWSTR
    , "Ptr", auditloghandle   ; HLOG* in/out
    , "UInt", offset   ; DWORD
    , "Ptr", reserved1   ; DWORD* in/out
    , "UInt", reserved2   ; DWORD
    , "UInt", offsetflag   ; DWORD
    , "Ptr", bufptr   ; BYTE** in/out
    , "UInt", prefmaxlen   ; DWORD
    , "Ptr", bytesread   ; DWORD* in/out
    , "Ptr", totalavailable   ; DWORD* in/out
    , "UInt")   ; return: DWORD
●NetAuditRead(server, service, auditloghandle, offset, reserved1, reserved2, offsetflag, bufptr, prefmaxlen, bytesread, totalavailable) = DLL("NETAPI32.dll", "dword NetAuditRead(char*, char*, void*, dword, void*, dword, dword, void*, dword, void*, void*)")
# 呼び出し: NetAuditRead(server, service, auditloghandle, offset, reserved1, reserved2, offsetflag, bufptr, prefmaxlen, bytesread, totalavailable)
# server : LPCWSTR -> "char*"
# service : LPCWSTR -> "char*"
# auditloghandle : HLOG* in/out -> "void*"
# offset : DWORD -> "dword"
# reserved1 : DWORD* in/out -> "void*"
# reserved2 : DWORD -> "dword"
# offsetflag : DWORD -> "dword"
# bufptr : BYTE** in/out -> "void*"
# prefmaxlen : DWORD -> "dword"
# bytesread : DWORD* in/out -> "void*"
# totalavailable : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "netapi32" fn NetAuditRead(
    server: [*c]const u16, // LPCWSTR
    service: [*c]const u16, // LPCWSTR
    auditloghandle: [*c]HLOG, // HLOG* in/out
    offset: u32, // DWORD
    reserved1: [*c]u32, // DWORD* in/out
    reserved2: u32, // DWORD
    offsetflag: u32, // DWORD
    bufptr: [*c][*c]u8, // BYTE** in/out
    prefmaxlen: u32, // DWORD
    bytesread: [*c]u32, // DWORD* in/out
    totalavailable: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) u32;
proc NetAuditRead(
    server: WideCString,  # LPCWSTR
    service: WideCString,  # LPCWSTR
    auditloghandle: ptr HLOG,  # HLOG* in/out
    offset: uint32,  # DWORD
    reserved1: ptr uint32,  # DWORD* in/out
    reserved2: uint32,  # DWORD
    offsetflag: uint32,  # DWORD
    bufptr: ptr uint8,  # BYTE** in/out
    prefmaxlen: uint32,  # DWORD
    bytesread: ptr uint32,  # DWORD* in/out
    totalavailable: ptr uint32  # DWORD* in/out
): uint32 {.importc: "NetAuditRead", stdcall, dynlib: "NETAPI32.dll".}
pragma(lib, "netapi32");
extern(Windows)
uint NetAuditRead(
    const(wchar)* server,   // LPCWSTR
    const(wchar)* service,   // LPCWSTR
    HLOG* auditloghandle,   // HLOG* in/out
    uint offset,   // DWORD
    uint* reserved1,   // DWORD* in/out
    uint reserved2,   // DWORD
    uint offsetflag,   // DWORD
    ubyte** bufptr,   // BYTE** in/out
    uint prefmaxlen,   // DWORD
    uint* bytesread,   // DWORD* in/out
    uint* totalavailable   // DWORD* in/out
);
ccall((:NetAuditRead, "NETAPI32.dll"), stdcall, UInt32,
      (Cwstring, Cwstring, Ptr{HLOG}, UInt32, Ptr{UInt32}, UInt32, UInt32, Ptr{UInt8}, UInt32, Ptr{UInt32}, Ptr{UInt32}),
      server, service, auditloghandle, offset, reserved1, reserved2, offsetflag, bufptr, prefmaxlen, bytesread, totalavailable)
# server : LPCWSTR -> Cwstring
# service : LPCWSTR -> Cwstring
# auditloghandle : HLOG* in/out -> Ptr{HLOG}
# offset : DWORD -> UInt32
# reserved1 : DWORD* in/out -> Ptr{UInt32}
# reserved2 : DWORD -> UInt32
# offsetflag : DWORD -> UInt32
# bufptr : BYTE** in/out -> Ptr{UInt8}
# prefmaxlen : DWORD -> UInt32
# bytesread : DWORD* in/out -> Ptr{UInt32}
# totalavailable : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t NetAuditRead(
    const uint16_t* server,
    const uint16_t* service,
    void* auditloghandle,
    uint32_t offset,
    uint32_t* reserved1,
    uint32_t reserved2,
    uint32_t offsetflag,
    uint8_t** bufptr,
    uint32_t prefmaxlen,
    uint32_t* bytesread,
    uint32_t* totalavailable);
]]
local netapi32 = ffi.load("netapi32")
-- netapi32.NetAuditRead(server, service, auditloghandle, offset, reserved1, reserved2, offsetflag, bufptr, prefmaxlen, bytesread, totalavailable)
-- server : LPCWSTR
-- service : LPCWSTR
-- auditloghandle : HLOG* in/out
-- offset : DWORD
-- reserved1 : DWORD* in/out
-- reserved2 : DWORD
-- offsetflag : DWORD
-- bufptr : BYTE** in/out
-- prefmaxlen : DWORD
-- bytesread : DWORD* in/out
-- totalavailable : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('NETAPI32.dll');
const NetAuditRead = lib.func('__stdcall', 'NetAuditRead', 'uint32_t', ['str16', 'str16', 'void *', 'uint32_t', 'uint32_t *', 'uint32_t', 'uint32_t', 'uint8_t *', 'uint32_t', 'uint32_t *', 'uint32_t *']);
// NetAuditRead(server, service, auditloghandle, offset, reserved1, reserved2, offsetflag, bufptr, prefmaxlen, bytesread, totalavailable)
// server : LPCWSTR -> 'str16'
// service : LPCWSTR -> 'str16'
// auditloghandle : HLOG* in/out -> 'void *'
// offset : DWORD -> 'uint32_t'
// reserved1 : DWORD* in/out -> 'uint32_t *'
// reserved2 : DWORD -> 'uint32_t'
// offsetflag : DWORD -> 'uint32_t'
// bufptr : BYTE** in/out -> 'uint8_t *'
// prefmaxlen : DWORD -> 'uint32_t'
// bytesread : DWORD* in/out -> 'uint32_t *'
// totalavailable : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("NETAPI32.dll", {
  NetAuditRead: { parameters: ["buffer", "buffer", "pointer", "u32", "pointer", "u32", "u32", "pointer", "u32", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.NetAuditRead(server, service, auditloghandle, offset, reserved1, reserved2, offsetflag, bufptr, prefmaxlen, bytesread, totalavailable)
// server : LPCWSTR -> "buffer"
// service : LPCWSTR -> "buffer"
// auditloghandle : HLOG* in/out -> "pointer"
// offset : DWORD -> "u32"
// reserved1 : DWORD* in/out -> "pointer"
// reserved2 : DWORD -> "u32"
// offsetflag : DWORD -> "u32"
// bufptr : BYTE** in/out -> "pointer"
// prefmaxlen : DWORD -> "u32"
// bytesread : DWORD* in/out -> "pointer"
// totalavailable : DWORD* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t NetAuditRead(
    const uint16_t* server,
    const uint16_t* service,
    void* auditloghandle,
    uint32_t offset,
    uint32_t* reserved1,
    uint32_t reserved2,
    uint32_t offsetflag,
    uint8_t** bufptr,
    uint32_t prefmaxlen,
    uint32_t* bytesread,
    uint32_t* totalavailable);
C, "NETAPI32.dll");
// $ffi->NetAuditRead(server, service, auditloghandle, offset, reserved1, reserved2, offsetflag, bufptr, prefmaxlen, bytesread, totalavailable);
// server : LPCWSTR
// service : LPCWSTR
// auditloghandle : HLOG* in/out
// offset : DWORD
// reserved1 : DWORD* in/out
// reserved2 : DWORD
// offsetflag : DWORD
// bufptr : BYTE** in/out
// prefmaxlen : DWORD
// bytesread : DWORD* in/out
// totalavailable : DWORD* in/out
// 構造体/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 Netapi32 extends StdCallLibrary {
    Netapi32 INSTANCE = Native.load("netapi32", Netapi32.class);
    int NetAuditRead(
        WString server,   // LPCWSTR
        WString service,   // LPCWSTR
        Pointer auditloghandle,   // HLOG* in/out
        int offset,   // DWORD
        IntByReference reserved1,   // DWORD* in/out
        int reserved2,   // DWORD
        int offsetflag,   // DWORD
        Pointer bufptr,   // BYTE** in/out
        int prefmaxlen,   // DWORD
        IntByReference bytesread,   // DWORD* in/out
        IntByReference totalavailable   // DWORD* in/out
    );
}
@[Link("netapi32")]
lib LibNETAPI32
  fun NetAuditRead = NetAuditRead(
    server : UInt16*,   # LPCWSTR
    service : UInt16*,   # LPCWSTR
    auditloghandle : HLOG*,   # HLOG* in/out
    offset : UInt32,   # DWORD
    reserved1 : UInt32*,   # DWORD* in/out
    reserved2 : UInt32,   # DWORD
    offsetflag : UInt32,   # DWORD
    bufptr : UInt8**,   # BYTE** in/out
    prefmaxlen : UInt32,   # DWORD
    bytesread : UInt32*,   # DWORD* in/out
    totalavailable : UInt32*   # DWORD* in/out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef NetAuditReadNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, Uint32, Pointer<Uint32>, Uint32, Uint32, Pointer<Uint8>, Uint32, Pointer<Uint32>, Pointer<Uint32>);
typedef NetAuditReadDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, int, Pointer<Uint32>, int, int, Pointer<Uint8>, int, Pointer<Uint32>, Pointer<Uint32>);
final NetAuditRead = DynamicLibrary.open('NETAPI32.dll')
    .lookupFunction<NetAuditReadNative, NetAuditReadDart>('NetAuditRead');
// server : LPCWSTR -> Pointer<Utf16>
// service : LPCWSTR -> Pointer<Utf16>
// auditloghandle : HLOG* in/out -> Pointer<Void>
// offset : DWORD -> Uint32
// reserved1 : DWORD* in/out -> Pointer<Uint32>
// reserved2 : DWORD -> Uint32
// offsetflag : DWORD -> Uint32
// bufptr : BYTE** in/out -> Pointer<Uint8>
// prefmaxlen : DWORD -> Uint32
// bytesread : DWORD* in/out -> Pointer<Uint32>
// totalavailable : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function NetAuditRead(
  server: PWideChar;   // LPCWSTR
  service: PWideChar;   // LPCWSTR
  auditloghandle: Pointer;   // HLOG* in/out
  offset: DWORD;   // DWORD
  reserved1: Pointer;   // DWORD* in/out
  reserved2: DWORD;   // DWORD
  offsetflag: DWORD;   // DWORD
  bufptr: Pointer;   // BYTE** in/out
  prefmaxlen: DWORD;   // DWORD
  bytesread: Pointer;   // DWORD* in/out
  totalavailable: Pointer   // DWORD* in/out
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'NetAuditRead';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "NetAuditRead"
  c_NetAuditRead :: CWString -> CWString -> Ptr () -> Word32 -> Ptr Word32 -> Word32 -> Word32 -> Ptr Word8 -> Word32 -> Ptr Word32 -> Ptr Word32 -> IO Word32
-- server : LPCWSTR -> CWString
-- service : LPCWSTR -> CWString
-- auditloghandle : HLOG* in/out -> Ptr ()
-- offset : DWORD -> Word32
-- reserved1 : DWORD* in/out -> Ptr Word32
-- reserved2 : DWORD -> Word32
-- offsetflag : DWORD -> Word32
-- bufptr : BYTE** in/out -> Ptr Word8
-- prefmaxlen : DWORD -> Word32
-- bytesread : DWORD* in/out -> Ptr Word32
-- totalavailable : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let netauditread =
  foreign "NetAuditRead"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr void) @-> uint32_t @-> (ptr uint32_t) @-> uint32_t @-> uint32_t @-> (ptr uint8_t) @-> uint32_t @-> (ptr uint32_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* server : LPCWSTR -> (ptr uint16_t) *)
(* service : LPCWSTR -> (ptr uint16_t) *)
(* auditloghandle : HLOG* in/out -> (ptr void) *)
(* offset : DWORD -> uint32_t *)
(* reserved1 : DWORD* in/out -> (ptr uint32_t) *)
(* reserved2 : DWORD -> uint32_t *)
(* offsetflag : DWORD -> uint32_t *)
(* bufptr : BYTE** in/out -> (ptr uint8_t) *)
(* prefmaxlen : DWORD -> uint32_t *)
(* bytesread : DWORD* in/out -> (ptr uint32_t) *)
(* totalavailable : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library netapi32 (t "NETAPI32.dll"))
(cffi:use-foreign-library netapi32)

(cffi:defcfun ("NetAuditRead" net-audit-read :convention :stdcall) :uint32
  (server (:string :encoding :utf-16le))   ; LPCWSTR
  (service (:string :encoding :utf-16le))   ; LPCWSTR
  (auditloghandle :pointer)   ; HLOG* in/out
  (offset :uint32)   ; DWORD
  (reserved1 :pointer)   ; DWORD* in/out
  (reserved2 :uint32)   ; DWORD
  (offsetflag :uint32)   ; DWORD
  (bufptr :pointer)   ; BYTE** in/out
  (prefmaxlen :uint32)   ; DWORD
  (bytesread :pointer)   ; DWORD* in/out
  (totalavailable :pointer))   ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $NetAuditRead = Win32::API::More->new('NETAPI32',
    'DWORD NetAuditRead(LPCWSTR server, LPCWSTR service, LPVOID auditloghandle, DWORD offset, LPVOID reserved1, DWORD reserved2, DWORD offsetflag, LPVOID bufptr, DWORD prefmaxlen, LPVOID bytesread, LPVOID totalavailable)');
# my $ret = $NetAuditRead->Call($server, $service, $auditloghandle, $offset, $reserved1, $reserved2, $offsetflag, $bufptr, $prefmaxlen, $bytesread, $totalavailable);
# server : LPCWSTR -> LPCWSTR
# service : LPCWSTR -> LPCWSTR
# auditloghandle : HLOG* in/out -> LPVOID
# offset : DWORD -> DWORD
# reserved1 : DWORD* in/out -> LPVOID
# reserved2 : DWORD -> DWORD
# offsetflag : DWORD -> DWORD
# bufptr : BYTE** in/out -> LPVOID
# prefmaxlen : DWORD -> DWORD
# bytesread : DWORD* in/out -> LPVOID
# totalavailable : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型