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

NetAlertRaiseEx

関数
サービス名を指定してネットワークアラートを通知する。
DLLNETAPI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

DWORD NetAlertRaiseEx(
    LPCWSTR AlertType,
    void* VariableInfo,
    DWORD VariableInfoSize,
    LPCWSTR ServiceName
);

パラメーター

名前方向
AlertTypeLPCWSTRin
VariableInfovoid*in
VariableInfoSizeDWORDin
ServiceNameLPCWSTRin

戻り値の型: DWORD

各言語での呼び出し定義

// 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   // DWORD
function 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)。