NetAlertRaiseEx
関数シグネチャ
// NETAPI32.dll
#include <windows.h>
DWORD NetAlertRaiseEx(
LPCWSTR AlertType,
void* VariableInfo,
DWORD VariableInfoSize,
LPCWSTR ServiceName
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| AlertType | LPCWSTR | in | 発生させるアラートクラス(アラートの種類)を指定する定数文字列へのポインターです。このパラメーターには、次の定義済みの値のいずれか、またはネットワークアプリケーション用のユーザー定義のアラートクラスを指定できます。(アラートのイベント名には任意のテキスト文字列を使用できます。)
| ||||||||||||
| VariableInfo | void* | in | 割り込みメッセージを待ち受けているクライアントに送信するデータへのポインターです。データは、1 つの ADMIN_OTHER_INFO、 ERRLOG_OTHER_INFO、 PRINT_OTHER_INFO、または USER_OTHER_INFO 構造体と、それに続く必要な可変長情報で構成する必要があります。詳細については、次の「解説」セクションのコードサンプルを参照してください。 呼び出し側のアプリケーションは、すべての構造体および可変データのメモリを割り当て、解放する必要があります。詳細については、 Network Management Function Buffers を参照してください。 | ||||||||||||
| VariableInfoSize | DWORD | in | VariableInfo パラメーターが指すバッファー内の可変情報のバイト数です。 | ||||||||||||
| ServiceName | LPCWSTR | in | 割り込みメッセージを発生させるサービスの名前を指定する定数文字列へのポインターです。 |
戻り値の型: DWORD
公式ドキュメント
NetAlertRaiseEx 関数は、特定のイベントが発生したときに、登録されているすべてのクライアントに通知します。NetAlertRaiseEx は STD_ALERT 構造体を指定する必要がないため、この拡張関数を呼び出すことでアラートメッセージの送信を簡略化できます。
戻り値
関数が成功した場合、戻り値は NERR_Success です。
関数が失敗した場合、戻り値はシステムエラーコードであり、次のエラーコードのいずれかになることがあります。考えられるすべてのエラーコードの一覧については、 System Error Codes を参照してください。
| 戻り値 | 説明 |
|---|---|
| パラメーターが正しくありません。このエラーは、AlertEventName パラメーターが NULL または空の文字列である場合、ServiceName パラメーターが NULL または空の文字列である場合、VariableInfo パラメーターが NULL である場合、または VariableInfoSize パラメーターが 512 から STD_ALERT 構造体のサイズを引いた値より大きい場合に返されます。 | |
| 要求はサポートされていません。Windows Vista 以降では Alerter サービスがサポートされていないため、このエラーが返されます。 |
解説(Remarks)
NetAlertRaiseEx 関数を正常に実行するために、特別なグループメンバーシップは必要ありません。
NetAlertRaiseEx 関数を呼び出すとき、クライアントコンピューターで alerter サービスが実行されている必要があります。実行されていない場合、関数は ERROR_FILE_NOT_FOUND で失敗します。
例
次のコードサンプルは、NetAlertRaiseEx 関数を呼び出して、次の種類の割り込みメッセージ(アラート)を発生させる方法を示しています。
- ADMIN_OTHER_INFO 構造体を指定した管理アラート
- PRINT_OTHER_INFO 構造体を指定した印刷アラート
- USER_OTHER_INFO 構造体を指定したユーザーアラート
呼び出し側のアプリケーションは、アラートメッセージバッファー内のすべての構造体および可変長データのメモリを割り当て、解放する必要があることに注意してください。
ユーザーアラートでユーザー定義の構造体および有効な文字列を渡すには、イベントメッセージファイルを作成し、それをアプリケーションにリンクする必要があります。また、レジストリの EventLog セクションにある EventMessageFile サブキーにアプリケーションを登録する必要があります。アプリケーションを登録しない場合、ユーザーアラートには、USER_OTHER_INFO 構造体に続く可変長文字列で渡した情報が含まれます。EventMessageFile の詳細については、Event Logging を参照してください。
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "netapi32.lib")
#include <windows.h>
#include <lm.h>
#include <stdio.h>
#include <time.h>
//
// Define default strings.
//
#define PROGRAM_NAME TEXT("NETALRT")
#define szComputerName TEXT("\\\\TESTCOMPUTER")
#define szUserName TEXT("TEST")
#define szQueueName TEXT("PQUEUE")
#define szDestName TEXT("MYPRINTER")
#define szStatus TEXT("OK")
//
// Define structure sizes.
//
#define VAREDSIZE 312 // maximum size of the variable length message
char buff[VAREDSIZE];
//
int main()
{
time_t now;
PADMIN_OTHER_INFO pAdminInfo; // ADMIN_OTHER_INFO structure
PPRINT_OTHER_INFO pPrintInfo; // PRINT_OTHER_INFO structure
PUSER_OTHER_INFO pUserInfo; // USER_OTHER_INFO structure
TCHAR *p;
DWORD dwResult;
time( &now ); // Retrieve the current time to print it later.
//
// Sending an administrative alert
//
// Assign values to the members of the ADMIN_OTHER_INFO structure.
//
pAdminInfo = (PADMIN_OTHER_INFO) buff;
ZeroMemory(pAdminInfo, VAREDSIZE);
//
// Error 2377, NERR_LogOverflow, indicates
// a log file is full.
//
pAdminInfo->alrtad_errcode = 2377;
pAdminInfo->alrtad_numstrings = 1;
//
// Retrieve a pointer to the variable data portion at the
// end of the buffer by calling the ALERT_VAR_DATA macro.
//
p = (LPTSTR) ALERT_VAR_DATA(pAdminInfo);
//
// Fill in the variable-length, concatenated strings
// that follow the ADMIN_OTHER_INFO structure. These strings
// will be written to the message log.
//
wcscpy_s(p,VAREDSIZE/2, TEXT("'C:\\MYLOG.TXT'"));
//
// Call the NetAlertRaiseEx function to raise the
// administrative alert.
//
dwResult = NetAlertRaiseEx(ALERT_ADMIN_EVENT, pAdminInfo, 255 , TEXT("MYSERVICE"));
//
// Display the results of the function call.
//
if (dwResult != NERR_Success)
{
wprintf(L"NetAlertRaiseEx failed: %d\n", dwResult);
return -1;
}
else
wprintf(L"Administrative alert raised successfully.\n");
//
// Sending a print alert
//
// Assign values to the members of the PRINT_OTHER_INFO structure.
//
pPrintInfo = (PPRINT_OTHER_INFO) buff;
ZeroMemory(pPrintInfo, VAREDSIZE);
pPrintInfo->alrtpr_jobid = 5457;
pPrintInfo->alrtpr_status = 0;
pPrintInfo->alrtpr_submitted = (DWORD) now;
pPrintInfo->alrtpr_size = 1000;
//
// Retrieve a pointer to the variable data portion at the
// end of the buffer by calling the ALERT_VAR_DATA macro.
//
p = (LPTSTR) ALERT_VAR_DATA(pPrintInfo);
//
// Fill in the variable-length, concatenated strings
// that follow the PRINT_OTHER_INFO structure.
//
wcscpy_s(p, VAREDSIZE/2, szComputerName); // computername
p += lstrlen(p) + 1;
wcscpy_s(p, (VAREDSIZE/2)-wcslen(szComputerName)-1, szUserName); // user name
p += lstrlen(p) + 1;
wcscpy_s(p, (VAREDSIZE/2)-wcslen(szComputerName)-wcslen(szUserName)-2,
szQueueName); // printer queuename
p += lstrlen(p) + 1;
wcscpy_s(p, (VAREDSIZE/2)-wcslen(szComputerName)-wcslen(szUserName)-wcslen(szQueueName)-3,
szDestName); // destination or printer name (optional)
p += lstrlen(p) + 1;
wcscpy_s(p, (VAREDSIZE/2)-wcslen(szComputerName)-wcslen(szUserName)-wcslen(szQueueName)
- wcslen(szDestName)-4, szStatus); // status of the print job (optional)
//
// Call the NetAlertRaiseEx function to raise the
// print alert.
//
dwResult = NetAlertRaiseEx(ALERT_PRINT_EVENT, pPrintInfo, VAREDSIZE, TEXT("MYSERVICE"));
//
// Display the results of the function call.
//
if (dwResult != NERR_Success)
{
wprintf(L"NetAlertRaiseEx failed: %d\n", dwResult);
return -1;
}
else
wprintf(L"Print alert raised successfully.\n");
//
// Sending a user alert
//
// Assign values to the members of the USER_OTHER_INFO structure.
//
pUserInfo = (PUSER_OTHER_INFO) buff;
ZeroMemory(pUserInfo, VAREDSIZE);
pUserInfo->alrtus_errcode = 0xffff;
pUserInfo->alrtus_numstrings = 1;
//
// Retrieve a pointer to the variable data portion at the
// end of the buffer by calling the ALERT_VAR_DATA macro.
//
p = (LPTSTR) ALERT_VAR_DATA(pUserInfo);
//
// Fill in the variable-length, concatenated strings
// that follow the USER_OTHER_INFO structure.
//
wcscpy_s(p,(VAREDSIZE/2), TEXT("C:\\USERLOG.TXT"));
p += lstrlen(p) + 1;
wcscpy_s(p, (VAREDSIZE/2) - wcslen(TEXT("C:\\USERLOG.TXT"))-1, szUserName);
//
// Call the NetAlertRaiseEx function to raise the
// user alert.
//
dwResult = NetAlertRaiseEx(ALERT_USER_EVENT, pUserInfo, VAREDSIZE, TEXT("MYSERVICE"));
//
// Display the results of the function call.
//
if (dwResult != NERR_Success)
{
wprintf(L"NetAlertRaiseEx failed: %d\n", dwResult);
return -1;
}
else
wprintf(L"User alert raised successfully.\n");
return(dwResult);
}
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// NETAPI32.dll
#include <windows.h>
DWORD NetAlertRaiseEx(
LPCWSTR AlertType,
void* VariableInfo,
DWORD VariableInfoSize,
LPCWSTR ServiceName
);[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern uint NetAlertRaiseEx(
[MarshalAs(UnmanagedType.LPWStr)] string AlertType, // LPCWSTR
IntPtr VariableInfo, // void*
uint VariableInfoSize, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] string ServiceName // LPCWSTR
);<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function NetAlertRaiseEx(
<MarshalAs(UnmanagedType.LPWStr)> AlertType As String, ' LPCWSTR
VariableInfo As IntPtr, ' void*
VariableInfoSize As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> ServiceName As String ' LPCWSTR
) As UInteger
End Function' AlertType : LPCWSTR
' VariableInfo : void*
' VariableInfoSize : DWORD
' ServiceName : LPCWSTR
Declare PtrSafe Function NetAlertRaiseEx Lib "netapi32" ( _
ByVal AlertType As LongPtr, _
ByVal VariableInfo As LongPtr, _
ByVal VariableInfoSize As Long, _
ByVal ServiceName As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
NetAlertRaiseEx = ctypes.windll.netapi32.NetAlertRaiseEx
NetAlertRaiseEx.restype = wintypes.DWORD
NetAlertRaiseEx.argtypes = [
wintypes.LPCWSTR, # AlertType : LPCWSTR
ctypes.POINTER(None), # VariableInfo : void*
wintypes.DWORD, # VariableInfoSize : DWORD
wintypes.LPCWSTR, # ServiceName : LPCWSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('NETAPI32.dll')
NetAlertRaiseEx = Fiddle::Function.new(
lib['NetAlertRaiseEx'],
[
Fiddle::TYPE_VOIDP, # AlertType : LPCWSTR
Fiddle::TYPE_VOIDP, # VariableInfo : void*
-Fiddle::TYPE_INT, # VariableInfoSize : DWORD
Fiddle::TYPE_VOIDP, # ServiceName : LPCWSTR
],
-Fiddle::TYPE_INT)#[link(name = "netapi32")]
extern "system" {
fn NetAlertRaiseEx(
AlertType: *const u16, // LPCWSTR
VariableInfo: *mut (), // void*
VariableInfoSize: u32, // DWORD
ServiceName: *const u16 // LPCWSTR
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("NETAPI32.dll")]
public static extern uint NetAlertRaiseEx([MarshalAs(UnmanagedType.LPWStr)] string AlertType, IntPtr VariableInfo, uint VariableInfoSize, [MarshalAs(UnmanagedType.LPWStr)] string ServiceName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NETAPI32_NetAlertRaiseEx' -Namespace Win32 -PassThru
# $api::NetAlertRaiseEx(AlertType, VariableInfo, VariableInfoSize, ServiceName)#uselib "NETAPI32.dll"
#func global NetAlertRaiseEx "NetAlertRaiseEx" sptr, sptr, sptr, sptr
; NetAlertRaiseEx AlertType, VariableInfo, VariableInfoSize, ServiceName ; 戻り値は stat
; AlertType : LPCWSTR -> "sptr"
; VariableInfo : void* -> "sptr"
; VariableInfoSize : DWORD -> "sptr"
; ServiceName : LPCWSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "NETAPI32.dll"
#cfunc global NetAlertRaiseEx "NetAlertRaiseEx" wstr, sptr, int, wstr
; res = NetAlertRaiseEx(AlertType, VariableInfo, VariableInfoSize, ServiceName)
; AlertType : LPCWSTR -> "wstr"
; VariableInfo : void* -> "sptr"
; VariableInfoSize : DWORD -> "int"
; ServiceName : LPCWSTR -> "wstr"; DWORD NetAlertRaiseEx(LPCWSTR AlertType, void* VariableInfo, DWORD VariableInfoSize, LPCWSTR ServiceName)
#uselib "NETAPI32.dll"
#cfunc global NetAlertRaiseEx "NetAlertRaiseEx" wstr, intptr, int, wstr
; res = NetAlertRaiseEx(AlertType, VariableInfo, VariableInfoSize, ServiceName)
; AlertType : LPCWSTR -> "wstr"
; VariableInfo : void* -> "intptr"
; VariableInfoSize : DWORD -> "int"
; ServiceName : LPCWSTR -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
procNetAlertRaiseEx = netapi32.NewProc("NetAlertRaiseEx")
)
// AlertType (LPCWSTR), VariableInfo (void*), VariableInfoSize (DWORD), ServiceName (LPCWSTR)
r1, _, err := procNetAlertRaiseEx.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(AlertType))),
uintptr(VariableInfo),
uintptr(VariableInfoSize),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ServiceName))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction NetAlertRaiseEx(
AlertType: PWideChar; // LPCWSTR
VariableInfo: Pointer; // void*
VariableInfoSize: DWORD; // DWORD
ServiceName: PWideChar // LPCWSTR
): DWORD; stdcall;
external 'NETAPI32.dll' name 'NetAlertRaiseEx';result := DllCall("NETAPI32\NetAlertRaiseEx"
, "WStr", AlertType ; LPCWSTR
, "Ptr", VariableInfo ; void*
, "UInt", VariableInfoSize ; DWORD
, "WStr", ServiceName ; LPCWSTR
, "UInt") ; return: DWORD●NetAlertRaiseEx(AlertType, VariableInfo, VariableInfoSize, ServiceName) = DLL("NETAPI32.dll", "dword NetAlertRaiseEx(char*, void*, dword, char*)")
# 呼び出し: NetAlertRaiseEx(AlertType, VariableInfo, VariableInfoSize, ServiceName)
# AlertType : LPCWSTR -> "char*"
# VariableInfo : void* -> "void*"
# VariableInfoSize : DWORD -> "dword"
# ServiceName : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "netapi32" fn NetAlertRaiseEx(
AlertType: [*c]const u16, // LPCWSTR
VariableInfo: ?*anyopaque, // void*
VariableInfoSize: u32, // DWORD
ServiceName: [*c]const u16 // LPCWSTR
) callconv(std.os.windows.WINAPI) u32;proc NetAlertRaiseEx(
AlertType: WideCString, # LPCWSTR
VariableInfo: pointer, # void*
VariableInfoSize: uint32, # DWORD
ServiceName: WideCString # LPCWSTR
): uint32 {.importc: "NetAlertRaiseEx", stdcall, dynlib: "NETAPI32.dll".}pragma(lib, "netapi32");
extern(Windows)
uint NetAlertRaiseEx(
const(wchar)* AlertType, // LPCWSTR
void* VariableInfo, // void*
uint VariableInfoSize, // DWORD
const(wchar)* ServiceName // LPCWSTR
);ccall((:NetAlertRaiseEx, "NETAPI32.dll"), stdcall, UInt32,
(Cwstring, Ptr{Cvoid}, UInt32, Cwstring),
AlertType, VariableInfo, VariableInfoSize, ServiceName)
# AlertType : LPCWSTR -> Cwstring
# VariableInfo : void* -> Ptr{Cvoid}
# VariableInfoSize : DWORD -> UInt32
# ServiceName : LPCWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t NetAlertRaiseEx(
const uint16_t* AlertType,
void* VariableInfo,
uint32_t VariableInfoSize,
const uint16_t* ServiceName);
]]
local netapi32 = ffi.load("netapi32")
-- netapi32.NetAlertRaiseEx(AlertType, VariableInfo, VariableInfoSize, ServiceName)
-- AlertType : LPCWSTR
-- VariableInfo : void*
-- VariableInfoSize : DWORD
-- ServiceName : LPCWSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('NETAPI32.dll');
const NetAlertRaiseEx = lib.func('__stdcall', 'NetAlertRaiseEx', 'uint32_t', ['str16', 'void *', 'uint32_t', 'str16']);
// NetAlertRaiseEx(AlertType, VariableInfo, VariableInfoSize, ServiceName)
// AlertType : LPCWSTR -> 'str16'
// VariableInfo : void* -> 'void *'
// VariableInfoSize : DWORD -> 'uint32_t'
// ServiceName : LPCWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("NETAPI32.dll", {
NetAlertRaiseEx: { parameters: ["buffer", "pointer", "u32", "buffer"], result: "u32" },
});
// lib.symbols.NetAlertRaiseEx(AlertType, VariableInfo, VariableInfoSize, ServiceName)
// AlertType : LPCWSTR -> "buffer"
// VariableInfo : void* -> "pointer"
// VariableInfoSize : DWORD -> "u32"
// ServiceName : LPCWSTR -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t NetAlertRaiseEx(
const uint16_t* AlertType,
void* VariableInfo,
uint32_t VariableInfoSize,
const uint16_t* ServiceName);
C, "NETAPI32.dll");
// $ffi->NetAlertRaiseEx(AlertType, VariableInfo, VariableInfoSize, ServiceName);
// AlertType : LPCWSTR
// VariableInfo : void*
// VariableInfoSize : DWORD
// ServiceName : 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 Netapi32 extends StdCallLibrary {
Netapi32 INSTANCE = Native.load("netapi32", Netapi32.class);
int NetAlertRaiseEx(
WString AlertType, // LPCWSTR
Pointer VariableInfo, // void*
int VariableInfoSize, // DWORD
WString ServiceName // LPCWSTR
);
}@[Link("netapi32")]
lib LibNETAPI32
fun NetAlertRaiseEx = NetAlertRaiseEx(
AlertType : UInt16*, # LPCWSTR
VariableInfo : Void*, # void*
VariableInfoSize : UInt32, # DWORD
ServiceName : UInt16* # LPCWSTR
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef NetAlertRaiseExNative = Uint32 Function(Pointer<Utf16>, Pointer<Void>, Uint32, Pointer<Utf16>);
typedef NetAlertRaiseExDart = int Function(Pointer<Utf16>, Pointer<Void>, int, Pointer<Utf16>);
final NetAlertRaiseEx = DynamicLibrary.open('NETAPI32.dll')
.lookupFunction<NetAlertRaiseExNative, NetAlertRaiseExDart>('NetAlertRaiseEx');
// AlertType : LPCWSTR -> Pointer<Utf16>
// VariableInfo : void* -> Pointer<Void>
// VariableInfoSize : DWORD -> Uint32
// ServiceName : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function NetAlertRaiseEx(
AlertType: PWideChar; // LPCWSTR
VariableInfo: Pointer; // void*
VariableInfoSize: DWORD; // DWORD
ServiceName: PWideChar // LPCWSTR
): DWORD; stdcall;
external 'NETAPI32.dll' name 'NetAlertRaiseEx';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "NetAlertRaiseEx"
c_NetAlertRaiseEx :: CWString -> Ptr () -> Word32 -> CWString -> IO Word32
-- AlertType : LPCWSTR -> CWString
-- VariableInfo : void* -> Ptr ()
-- VariableInfoSize : DWORD -> Word32
-- ServiceName : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let netalertraiseex =
foreign "NetAlertRaiseEx"
((ptr uint16_t) @-> (ptr void) @-> uint32_t @-> (ptr uint16_t) @-> returning uint32_t)
(* AlertType : LPCWSTR -> (ptr uint16_t) *)
(* VariableInfo : void* -> (ptr void) *)
(* VariableInfoSize : DWORD -> uint32_t *)
(* ServiceName : LPCWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library netapi32 (t "NETAPI32.dll"))
(cffi:use-foreign-library netapi32)
(cffi:defcfun ("NetAlertRaiseEx" net-alert-raise-ex :convention :stdcall) :uint32
(alert-type (:string :encoding :utf-16le)) ; LPCWSTR
(variable-info :pointer) ; void*
(variable-info-size :uint32) ; DWORD
(service-name (:string :encoding :utf-16le))) ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $NetAlertRaiseEx = Win32::API::More->new('NETAPI32',
'DWORD NetAlertRaiseEx(LPCWSTR AlertType, LPVOID VariableInfo, DWORD VariableInfoSize, LPCWSTR ServiceName)');
# my $ret = $NetAlertRaiseEx->Call($AlertType, $VariableInfo, $VariableInfoSize, $ServiceName);
# AlertType : LPCWSTR -> LPCWSTR
# VariableInfo : void* -> LPVOID
# VariableInfoSize : DWORD -> DWORD
# ServiceName : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f NetAlertRaise — 登録されたクライアントにネットワークアラートを通知する。