ホーム › Devices.DeviceAndDriverInstallation › CM_Register_Notification
CM_Register_Notification
関数デバイスやインターフェイスの変更通知を登録する。
シグネチャ
// CFGMGR32.dll
#include <windows.h>
CONFIGRET CM_Register_Notification(
CM_NOTIFY_FILTER* pFilter,
void* pContext, // optional
PCM_NOTIFY_CALLBACK pCallback,
HCMNOTIFICATION* pNotifyContext
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pFilter | CM_NOTIFY_FILTER* | in | 通知対象を指定するフィルター構造体(CM_NOTIFY_FILTER)へのポインタ。インターフェイス/ハンドル/インスタンス単位を指定する。 |
| pContext | void* | inoptional | コールバックに渡されるユーザー定義のコンテキストポインタ。不要ならNULL可。 |
| pCallback | PCM_NOTIFY_CALLBACK | in | 通知発生時に呼び出されるコールバック関数(PCM_NOTIFY_CALLBACK)。 |
| pNotifyContext | HCMNOTIFICATION* | out | 登録した通知のハンドル(HCMNOTIFICATION)を受け取る出力先。解除時に使用する。 |
戻り値の型: CONFIGRET
各言語での呼び出し定義
// CFGMGR32.dll
#include <windows.h>
CONFIGRET CM_Register_Notification(
CM_NOTIFY_FILTER* pFilter,
void* pContext, // optional
PCM_NOTIFY_CALLBACK pCallback,
HCMNOTIFICATION* pNotifyContext
);[DllImport("CFGMGR32.dll", ExactSpelling = true)]
static extern uint CM_Register_Notification(
IntPtr pFilter, // CM_NOTIFY_FILTER*
IntPtr pContext, // void* optional
IntPtr pCallback, // PCM_NOTIFY_CALLBACK
IntPtr pNotifyContext // HCMNOTIFICATION* out
);<DllImport("CFGMGR32.dll", ExactSpelling:=True)>
Public Shared Function CM_Register_Notification(
pFilter As IntPtr, ' CM_NOTIFY_FILTER*
pContext As IntPtr, ' void* optional
pCallback As IntPtr, ' PCM_NOTIFY_CALLBACK
pNotifyContext As IntPtr ' HCMNOTIFICATION* out
) As UInteger
End Function' pFilter : CM_NOTIFY_FILTER*
' pContext : void* optional
' pCallback : PCM_NOTIFY_CALLBACK
' pNotifyContext : HCMNOTIFICATION* out
Declare PtrSafe Function CM_Register_Notification Lib "cfgmgr32" ( _
ByVal pFilter As LongPtr, _
ByVal pContext As LongPtr, _
ByVal pCallback As LongPtr, _
ByVal pNotifyContext As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CM_Register_Notification = ctypes.windll.cfgmgr32.CM_Register_Notification
CM_Register_Notification.restype = wintypes.DWORD
CM_Register_Notification.argtypes = [
ctypes.c_void_p, # pFilter : CM_NOTIFY_FILTER*
ctypes.POINTER(None), # pContext : void* optional
ctypes.c_void_p, # pCallback : PCM_NOTIFY_CALLBACK
ctypes.c_void_p, # pNotifyContext : HCMNOTIFICATION* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('CFGMGR32.dll')
CM_Register_Notification = Fiddle::Function.new(
lib['CM_Register_Notification'],
[
Fiddle::TYPE_VOIDP, # pFilter : CM_NOTIFY_FILTER*
Fiddle::TYPE_VOIDP, # pContext : void* optional
Fiddle::TYPE_VOIDP, # pCallback : PCM_NOTIFY_CALLBACK
Fiddle::TYPE_VOIDP, # pNotifyContext : HCMNOTIFICATION* out
],
-Fiddle::TYPE_INT)#[link(name = "cfgmgr32")]
extern "system" {
fn CM_Register_Notification(
pFilter: *mut CM_NOTIFY_FILTER, // CM_NOTIFY_FILTER*
pContext: *mut (), // void* optional
pCallback: *const core::ffi::c_void, // PCM_NOTIFY_CALLBACK
pNotifyContext: *mut *mut core::ffi::c_void // HCMNOTIFICATION* out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("CFGMGR32.dll")]
public static extern uint CM_Register_Notification(IntPtr pFilter, IntPtr pContext, IntPtr pCallback, IntPtr pNotifyContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CFGMGR32_CM_Register_Notification' -Namespace Win32 -PassThru
# $api::CM_Register_Notification(pFilter, pContext, pCallback, pNotifyContext)#uselib "CFGMGR32.dll"
#func global CM_Register_Notification "CM_Register_Notification" sptr, sptr, sptr, sptr
; CM_Register_Notification varptr(pFilter), pContext, pCallback, pNotifyContext ; 戻り値は stat
; pFilter : CM_NOTIFY_FILTER* -> "sptr"
; pContext : void* optional -> "sptr"
; pCallback : PCM_NOTIFY_CALLBACK -> "sptr"
; pNotifyContext : HCMNOTIFICATION* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "CFGMGR32.dll" #cfunc global CM_Register_Notification "CM_Register_Notification" var, sptr, sptr, sptr ; res = CM_Register_Notification(pFilter, pContext, pCallback, pNotifyContext) ; pFilter : CM_NOTIFY_FILTER* -> "var" ; pContext : void* optional -> "sptr" ; pCallback : PCM_NOTIFY_CALLBACK -> "sptr" ; pNotifyContext : HCMNOTIFICATION* out -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "CFGMGR32.dll" #cfunc global CM_Register_Notification "CM_Register_Notification" sptr, sptr, sptr, sptr ; res = CM_Register_Notification(varptr(pFilter), pContext, pCallback, pNotifyContext) ; pFilter : CM_NOTIFY_FILTER* -> "sptr" ; pContext : void* optional -> "sptr" ; pCallback : PCM_NOTIFY_CALLBACK -> "sptr" ; pNotifyContext : HCMNOTIFICATION* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; CONFIGRET CM_Register_Notification(CM_NOTIFY_FILTER* pFilter, void* pContext, PCM_NOTIFY_CALLBACK pCallback, HCMNOTIFICATION* pNotifyContext) #uselib "CFGMGR32.dll" #cfunc global CM_Register_Notification "CM_Register_Notification" var, intptr, intptr, intptr ; res = CM_Register_Notification(pFilter, pContext, pCallback, pNotifyContext) ; pFilter : CM_NOTIFY_FILTER* -> "var" ; pContext : void* optional -> "intptr" ; pCallback : PCM_NOTIFY_CALLBACK -> "intptr" ; pNotifyContext : HCMNOTIFICATION* out -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; CONFIGRET CM_Register_Notification(CM_NOTIFY_FILTER* pFilter, void* pContext, PCM_NOTIFY_CALLBACK pCallback, HCMNOTIFICATION* pNotifyContext) #uselib "CFGMGR32.dll" #cfunc global CM_Register_Notification "CM_Register_Notification" intptr, intptr, intptr, intptr ; res = CM_Register_Notification(varptr(pFilter), pContext, pCallback, pNotifyContext) ; pFilter : CM_NOTIFY_FILTER* -> "intptr" ; pContext : void* optional -> "intptr" ; pCallback : PCM_NOTIFY_CALLBACK -> "intptr" ; pNotifyContext : HCMNOTIFICATION* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
cfgmgr32 = windows.NewLazySystemDLL("CFGMGR32.dll")
procCM_Register_Notification = cfgmgr32.NewProc("CM_Register_Notification")
)
// pFilter (CM_NOTIFY_FILTER*), pContext (void* optional), pCallback (PCM_NOTIFY_CALLBACK), pNotifyContext (HCMNOTIFICATION* out)
r1, _, err := procCM_Register_Notification.Call(
uintptr(pFilter),
uintptr(pContext),
uintptr(pCallback),
uintptr(pNotifyContext),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // CONFIGRETfunction CM_Register_Notification(
pFilter: Pointer; // CM_NOTIFY_FILTER*
pContext: Pointer; // void* optional
pCallback: Pointer; // PCM_NOTIFY_CALLBACK
pNotifyContext: Pointer // HCMNOTIFICATION* out
): DWORD; stdcall;
external 'CFGMGR32.dll' name 'CM_Register_Notification';result := DllCall("CFGMGR32\CM_Register_Notification"
, "Ptr", pFilter ; CM_NOTIFY_FILTER*
, "Ptr", pContext ; void* optional
, "Ptr", pCallback ; PCM_NOTIFY_CALLBACK
, "Ptr", pNotifyContext ; HCMNOTIFICATION* out
, "UInt") ; return: CONFIGRET●CM_Register_Notification(pFilter, pContext, pCallback, pNotifyContext) = DLL("CFGMGR32.dll", "dword CM_Register_Notification(void*, void*, void*, void*)")
# 呼び出し: CM_Register_Notification(pFilter, pContext, pCallback, pNotifyContext)
# pFilter : CM_NOTIFY_FILTER* -> "void*"
# pContext : void* optional -> "void*"
# pCallback : PCM_NOTIFY_CALLBACK -> "void*"
# pNotifyContext : HCMNOTIFICATION* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "cfgmgr32" fn CM_Register_Notification(
pFilter: [*c]CM_NOTIFY_FILTER, // CM_NOTIFY_FILTER*
pContext: ?*anyopaque, // void* optional
pCallback: ?*anyopaque, // PCM_NOTIFY_CALLBACK
pNotifyContext: ?*anyopaque // HCMNOTIFICATION* out
) callconv(std.os.windows.WINAPI) u32;proc CM_Register_Notification(
pFilter: ptr CM_NOTIFY_FILTER, # CM_NOTIFY_FILTER*
pContext: pointer, # void* optional
pCallback: pointer, # PCM_NOTIFY_CALLBACK
pNotifyContext: pointer # HCMNOTIFICATION* out
): uint32 {.importc: "CM_Register_Notification", stdcall, dynlib: "CFGMGR32.dll".}pragma(lib, "cfgmgr32");
extern(Windows)
uint CM_Register_Notification(
CM_NOTIFY_FILTER* pFilter, // CM_NOTIFY_FILTER*
void* pContext, // void* optional
void* pCallback, // PCM_NOTIFY_CALLBACK
void* pNotifyContext // HCMNOTIFICATION* out
);ccall((:CM_Register_Notification, "CFGMGR32.dll"), stdcall, UInt32,
(Ptr{CM_NOTIFY_FILTER}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
pFilter, pContext, pCallback, pNotifyContext)
# pFilter : CM_NOTIFY_FILTER* -> Ptr{CM_NOTIFY_FILTER}
# pContext : void* optional -> Ptr{Cvoid}
# pCallback : PCM_NOTIFY_CALLBACK -> Ptr{Cvoid}
# pNotifyContext : HCMNOTIFICATION* out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t CM_Register_Notification(
void* pFilter,
void* pContext,
void* pCallback,
void* pNotifyContext);
]]
local cfgmgr32 = ffi.load("cfgmgr32")
-- cfgmgr32.CM_Register_Notification(pFilter, pContext, pCallback, pNotifyContext)
-- pFilter : CM_NOTIFY_FILTER*
-- pContext : void* optional
-- pCallback : PCM_NOTIFY_CALLBACK
-- pNotifyContext : HCMNOTIFICATION* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('CFGMGR32.dll');
const CM_Register_Notification = lib.func('__stdcall', 'CM_Register_Notification', 'uint32_t', ['void *', 'void *', 'void *', 'void *']);
// CM_Register_Notification(pFilter, pContext, pCallback, pNotifyContext)
// pFilter : CM_NOTIFY_FILTER* -> 'void *'
// pContext : void* optional -> 'void *'
// pCallback : PCM_NOTIFY_CALLBACK -> 'void *'
// pNotifyContext : HCMNOTIFICATION* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。const lib = Deno.dlopen("CFGMGR32.dll", {
CM_Register_Notification: { parameters: ["pointer", "pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.CM_Register_Notification(pFilter, pContext, pCallback, pNotifyContext)
// pFilter : CM_NOTIFY_FILTER* -> "pointer"
// pContext : void* optional -> "pointer"
// pCallback : PCM_NOTIFY_CALLBACK -> "pointer"
// pNotifyContext : HCMNOTIFICATION* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t CM_Register_Notification(
void* pFilter,
void* pContext,
void* pCallback,
void* pNotifyContext);
C, "CFGMGR32.dll");
// $ffi->CM_Register_Notification(pFilter, pContext, pCallback, pNotifyContext);
// pFilter : CM_NOTIFY_FILTER*
// pContext : void* optional
// pCallback : PCM_NOTIFY_CALLBACK
// pNotifyContext : HCMNOTIFICATION* 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 Cfgmgr32 extends StdCallLibrary {
Cfgmgr32 INSTANCE = Native.load("cfgmgr32", Cfgmgr32.class);
int CM_Register_Notification(
Pointer pFilter, // CM_NOTIFY_FILTER*
Pointer pContext, // void* optional
Callback pCallback, // PCM_NOTIFY_CALLBACK
Pointer pNotifyContext // HCMNOTIFICATION* out
);
}@[Link("cfgmgr32")]
lib LibCFGMGR32
fun CM_Register_Notification = CM_Register_Notification(
pFilter : CM_NOTIFY_FILTER*, # CM_NOTIFY_FILTER*
pContext : Void*, # void* optional
pCallback : Void*, # PCM_NOTIFY_CALLBACK
pNotifyContext : Void* # HCMNOTIFICATION* out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CM_Register_NotificationNative = Uint32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef CM_Register_NotificationDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final CM_Register_Notification = DynamicLibrary.open('CFGMGR32.dll')
.lookupFunction<CM_Register_NotificationNative, CM_Register_NotificationDart>('CM_Register_Notification');
// pFilter : CM_NOTIFY_FILTER* -> Pointer<Void>
// pContext : void* optional -> Pointer<Void>
// pCallback : PCM_NOTIFY_CALLBACK -> Pointer<Void>
// pNotifyContext : HCMNOTIFICATION* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CM_Register_Notification(
pFilter: Pointer; // CM_NOTIFY_FILTER*
pContext: Pointer; // void* optional
pCallback: Pointer; // PCM_NOTIFY_CALLBACK
pNotifyContext: Pointer // HCMNOTIFICATION* out
): DWORD; stdcall;
external 'CFGMGR32.dll' name 'CM_Register_Notification';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CM_Register_Notification"
c_CM_Register_Notification :: Ptr () -> Ptr () -> Ptr () -> Ptr () -> IO Word32
-- pFilter : CM_NOTIFY_FILTER* -> Ptr ()
-- pContext : void* optional -> Ptr ()
-- pCallback : PCM_NOTIFY_CALLBACK -> Ptr ()
-- pNotifyContext : HCMNOTIFICATION* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let cm_register_notification =
foreign "CM_Register_Notification"
((ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning uint32_t)
(* pFilter : CM_NOTIFY_FILTER* -> (ptr void) *)
(* pContext : void* optional -> (ptr void) *)
(* pCallback : PCM_NOTIFY_CALLBACK -> (ptr void) *)
(* pNotifyContext : HCMNOTIFICATION* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library cfgmgr32 (t "CFGMGR32.dll"))
(cffi:use-foreign-library cfgmgr32)
(cffi:defcfun ("CM_Register_Notification" cm-register-notification :convention :stdcall) :uint32
(p-filter :pointer) ; CM_NOTIFY_FILTER*
(p-context :pointer) ; void* optional
(p-callback :pointer) ; PCM_NOTIFY_CALLBACK
(p-notify-context :pointer)) ; HCMNOTIFICATION* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CM_Register_Notification = Win32::API::More->new('CFGMGR32',
'DWORD CM_Register_Notification(LPVOID pFilter, LPVOID pContext, LPVOID pCallback, HANDLE pNotifyContext)');
# my $ret = $CM_Register_Notification->Call($pFilter, $pContext, $pCallback, $pNotifyContext);
# pFilter : CM_NOTIFY_FILTER* -> LPVOID
# pContext : void* optional -> LPVOID
# pCallback : PCM_NOTIFY_CALLBACK -> LPVOID
# pNotifyContext : HCMNOTIFICATION* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。