Win32 API 日本語リファレンス
ホームDevices.DeviceAndDriverInstallation › CM_Register_Notification

CM_Register_Notification

関数
デバイスやインターフェイスの変更通知を登録する。
DLLCFGMGR32.dll呼出規約winapi対応OSwindows8.0

シグネチャ

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

CONFIGRET CM_Register_Notification(
    CM_NOTIFY_FILTER* pFilter,
    void* pContext,   // optional
    PCM_NOTIFY_CALLBACK pCallback,
    HCMNOTIFICATION* pNotifyContext
);

パラメーター

名前方向
pFilterCM_NOTIFY_FILTER*in
pContextvoid*inoptional
pCallbackPCM_NOTIFY_CALLBACKin
pNotifyContextHCMNOTIFICATION*out

戻り値の型: 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 方式にも切替可。
出力引数:
; 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 方式にも切替可。
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   // CONFIGRET
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';
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)。