ホーム › System.GroupPolicy › RegisterGPNotification
RegisterGPNotification
関数グループポリシー変更通知を登録する。
シグネチャ
// USERENV.dll
#include <windows.h>
BOOL RegisterGPNotification(
HANDLE hEvent,
BOOL bMachine
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hEvent | HANDLE | in | ポリシー適用時にシグナル状態になるイベントオブジェクトのハンドル。 |
| bMachine | BOOL | in | TRUEでコンピューターポリシー、FALSEでユーザーポリシーの通知を登録する。 |
戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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 // BOOLfunction 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)。const std = @import("std");
extern "userenv" fn RegisterGPNotification(
hEvent: ?*anyopaque, // HANDLE
bMachine: i32 // BOOL
) callconv(std.os.windows.WINAPI) i32;proc RegisterGPNotification(
hEvent: pointer, # HANDLE
bMachine: int32 # BOOL
): int32 {.importc: "RegisterGPNotification", stdcall, dynlib: "USERENV.dll".}pragma(lib, "userenv");
extern(Windows)
int RegisterGPNotification(
void* hEvent, // HANDLE
int bMachine // BOOL
);ccall((:RegisterGPNotification, "USERENV.dll"), stdcall, Int32,
(Ptr{Cvoid}, Int32),
hEvent, bMachine)
# hEvent : HANDLE -> Ptr{Cvoid}
# bMachine : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t RegisterGPNotification(
void* hEvent,
int32_t bMachine);
]]
local userenv = ffi.load("userenv")
-- userenv.RegisterGPNotification(hEvent, bMachine)
-- hEvent : HANDLE
-- bMachine : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USERENV.dll');
const RegisterGPNotification = lib.func('__stdcall', 'RegisterGPNotification', 'int32_t', ['void *', 'int32_t']);
// RegisterGPNotification(hEvent, bMachine)
// hEvent : HANDLE -> 'void *'
// bMachine : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USERENV.dll", {
RegisterGPNotification: { parameters: ["pointer", "i32"], result: "i32" },
});
// lib.symbols.RegisterGPNotification(hEvent, bMachine)
// hEvent : HANDLE -> "pointer"
// bMachine : BOOL -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t RegisterGPNotification(
void* hEvent,
int32_t bMachine);
C, "USERENV.dll");
// $ffi->RegisterGPNotification(hEvent, bMachine);
// hEvent : HANDLE
// bMachine : BOOL
// 構造体/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 Userenv extends StdCallLibrary {
Userenv INSTANCE = Native.load("userenv", Userenv.class);
boolean RegisterGPNotification(
Pointer hEvent, // HANDLE
boolean bMachine // BOOL
);
}@[Link("userenv")]
lib LibUSERENV
fun RegisterGPNotification = RegisterGPNotification(
hEvent : Void*, # HANDLE
bMachine : Int32 # BOOL
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef RegisterGPNotificationNative = Int32 Function(Pointer<Void>, Int32);
typedef RegisterGPNotificationDart = int Function(Pointer<Void>, int);
final RegisterGPNotification = DynamicLibrary.open('USERENV.dll')
.lookupFunction<RegisterGPNotificationNative, RegisterGPNotificationDart>('RegisterGPNotification');
// hEvent : HANDLE -> Pointer<Void>
// bMachine : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function RegisterGPNotification(
hEvent: THandle; // HANDLE
bMachine: BOOL // BOOL
): BOOL; stdcall;
external 'USERENV.dll' name 'RegisterGPNotification';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "RegisterGPNotification"
c_RegisterGPNotification :: Ptr () -> CInt -> IO CInt
-- hEvent : HANDLE -> Ptr ()
-- bMachine : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let registergpnotification =
foreign "RegisterGPNotification"
((ptr void) @-> int32_t @-> returning int32_t)
(* hEvent : HANDLE -> (ptr void) *)
(* bMachine : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library userenv (t "USERENV.dll"))
(cffi:use-foreign-library userenv)
(cffi:defcfun ("RegisterGPNotification" register-gpnotification :convention :stdcall) :int32
(h-event :pointer) ; HANDLE
(b-machine :int32)) ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $RegisterGPNotification = Win32::API::More->new('USERENV',
'BOOL RegisterGPNotification(HANDLE hEvent, BOOL bMachine)');
# my $ret = $RegisterGPNotification->Call($hEvent, $bMachine);
# hEvent : HANDLE -> HANDLE
# bMachine : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。