Win32 API 日本語リファレンス
ホームSystem.GroupPolicy › RegisterGPNotification

RegisterGPNotification

関数
グループポリシー変更通知を登録する。
DLLUSERENV.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

BOOL RegisterGPNotification(
    HANDLE hEvent,
    BOOL bMachine
);

パラメーター

名前方向
hEventHANDLEin
bMachineBOOLin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL RegisterGPNotification(
    HANDLE hEvent,
    BOOL bMachine
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USERENV.dll", SetLastError = true, ExactSpelling = true)]
static extern bool RegisterGPNotification(
    IntPtr hEvent,   // HANDLE
    bool bMachine   // BOOL
);
<DllImport("USERENV.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function RegisterGPNotification(
    hEvent As IntPtr,   ' HANDLE
    bMachine As Boolean   ' BOOL
) As Boolean
End Function
' hEvent : HANDLE
' bMachine : BOOL
Declare PtrSafe Function RegisterGPNotification Lib "userenv" ( _
    ByVal hEvent As LongPtr, _
    ByVal bMachine As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RegisterGPNotification = ctypes.windll.userenv.RegisterGPNotification
RegisterGPNotification.restype = wintypes.BOOL
RegisterGPNotification.argtypes = [
    wintypes.HANDLE,  # hEvent : HANDLE
    wintypes.BOOL,  # bMachine : BOOL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USERENV.dll')
RegisterGPNotification = Fiddle::Function.new(
  lib['RegisterGPNotification'],
  [
    Fiddle::TYPE_VOIDP,  # hEvent : HANDLE
    Fiddle::TYPE_INT,  # bMachine : BOOL
  ],
  Fiddle::TYPE_INT)
#[link(name = "userenv")]
extern "system" {
    fn RegisterGPNotification(
        hEvent: *mut core::ffi::c_void,  // HANDLE
        bMachine: i32  // BOOL
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USERENV.dll", SetLastError = true)]
public static extern bool RegisterGPNotification(IntPtr hEvent, bool bMachine);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USERENV_RegisterGPNotification' -Namespace Win32 -PassThru
# $api::RegisterGPNotification(hEvent, bMachine)
#uselib "USERENV.dll"
#func global RegisterGPNotification "RegisterGPNotification" sptr, sptr
; RegisterGPNotification hEvent, bMachine   ; 戻り値は stat
; hEvent : HANDLE -> "sptr"
; bMachine : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USERENV.dll"
#cfunc global RegisterGPNotification "RegisterGPNotification" sptr, int
; res = RegisterGPNotification(hEvent, bMachine)
; hEvent : HANDLE -> "sptr"
; bMachine : BOOL -> "int"
; BOOL RegisterGPNotification(HANDLE hEvent, BOOL bMachine)
#uselib "USERENV.dll"
#cfunc global RegisterGPNotification "RegisterGPNotification" intptr, int
; res = RegisterGPNotification(hEvent, bMachine)
; hEvent : HANDLE -> "intptr"
; bMachine : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	userenv = windows.NewLazySystemDLL("USERENV.dll")
	procRegisterGPNotification = userenv.NewProc("RegisterGPNotification")
)

// hEvent (HANDLE), bMachine (BOOL)
r1, _, err := procRegisterGPNotification.Call(
	uintptr(hEvent),
	uintptr(bMachine),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function RegisterGPNotification(
  hEvent: THandle;   // HANDLE
  bMachine: BOOL   // BOOL
): BOOL; stdcall;
  external 'USERENV.dll' name 'RegisterGPNotification';
result := DllCall("USERENV\RegisterGPNotification"
    , "Ptr", hEvent   ; HANDLE
    , "Int", bMachine   ; BOOL
    , "Int")   ; return: BOOL
●RegisterGPNotification(hEvent, bMachine) = DLL("USERENV.dll", "bool RegisterGPNotification(void*, bool)")
# 呼び出し: RegisterGPNotification(hEvent, bMachine)
# hEvent : HANDLE -> "void*"
# bMachine : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。