ホーム › Devices.DeviceAndDriverInstallation › CM_Open_DevNode_Key
CM_Open_DevNode_Key
関数デバイスノードのレジストリキーを開く。
シグネチャ
// CFGMGR32.dll
#include <windows.h>
CONFIGRET CM_Open_DevNode_Key(
DWORD dnDevNode,
DWORD samDesired,
DWORD ulHardwareProfile,
DWORD Disposition,
HKEY* phkDevice,
DWORD ulFlags
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| dnDevNode | DWORD | in | レジストリキーを開く対象デバイスノードのデバイスインスタンスハンドル。 |
| samDesired | DWORD | in | 開くレジストリキーに要求するアクセス権(REGSAM値)。 |
| ulHardwareProfile | DWORD | in | 対象ハードウェアプロファイル番号。0で現在のプロファイル。 |
| Disposition | DWORD | in | キーの作成/オープン方法を指定する値(RegDisposition_Open等)。 |
| phkDevice | HKEY* | out | オープンしたデバイスレジストリキーのハンドルを受け取る出力先。 |
| ulFlags | DWORD | in | 対象キーの種類を示すフラグ(CM_REGISTRY_HARDWARE/SOFTWARE等)。 |
戻り値の型: CONFIGRET
各言語での呼び出し定義
// CFGMGR32.dll
#include <windows.h>
CONFIGRET CM_Open_DevNode_Key(
DWORD dnDevNode,
DWORD samDesired,
DWORD ulHardwareProfile,
DWORD Disposition,
HKEY* phkDevice,
DWORD ulFlags
);[DllImport("CFGMGR32.dll", ExactSpelling = true)]
static extern uint CM_Open_DevNode_Key(
uint dnDevNode, // DWORD
uint samDesired, // DWORD
uint ulHardwareProfile, // DWORD
uint Disposition, // DWORD
IntPtr phkDevice, // HKEY* out
uint ulFlags // DWORD
);<DllImport("CFGMGR32.dll", ExactSpelling:=True)>
Public Shared Function CM_Open_DevNode_Key(
dnDevNode As UInteger, ' DWORD
samDesired As UInteger, ' DWORD
ulHardwareProfile As UInteger, ' DWORD
Disposition As UInteger, ' DWORD
phkDevice As IntPtr, ' HKEY* out
ulFlags As UInteger ' DWORD
) As UInteger
End Function' dnDevNode : DWORD
' samDesired : DWORD
' ulHardwareProfile : DWORD
' Disposition : DWORD
' phkDevice : HKEY* out
' ulFlags : DWORD
Declare PtrSafe Function CM_Open_DevNode_Key Lib "cfgmgr32" ( _
ByVal dnDevNode As Long, _
ByVal samDesired As Long, _
ByVal ulHardwareProfile As Long, _
ByVal Disposition As Long, _
ByVal phkDevice As LongPtr, _
ByVal ulFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CM_Open_DevNode_Key = ctypes.windll.cfgmgr32.CM_Open_DevNode_Key
CM_Open_DevNode_Key.restype = wintypes.DWORD
CM_Open_DevNode_Key.argtypes = [
wintypes.DWORD, # dnDevNode : DWORD
wintypes.DWORD, # samDesired : DWORD
wintypes.DWORD, # ulHardwareProfile : DWORD
wintypes.DWORD, # Disposition : DWORD
ctypes.c_void_p, # phkDevice : HKEY* out
wintypes.DWORD, # ulFlags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('CFGMGR32.dll')
CM_Open_DevNode_Key = Fiddle::Function.new(
lib['CM_Open_DevNode_Key'],
[
-Fiddle::TYPE_INT, # dnDevNode : DWORD
-Fiddle::TYPE_INT, # samDesired : DWORD
-Fiddle::TYPE_INT, # ulHardwareProfile : DWORD
-Fiddle::TYPE_INT, # Disposition : DWORD
Fiddle::TYPE_VOIDP, # phkDevice : HKEY* out
-Fiddle::TYPE_INT, # ulFlags : DWORD
],
-Fiddle::TYPE_INT)#[link(name = "cfgmgr32")]
extern "system" {
fn CM_Open_DevNode_Key(
dnDevNode: u32, // DWORD
samDesired: u32, // DWORD
ulHardwareProfile: u32, // DWORD
Disposition: u32, // DWORD
phkDevice: *mut *mut core::ffi::c_void, // HKEY* out
ulFlags: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("CFGMGR32.dll")]
public static extern uint CM_Open_DevNode_Key(uint dnDevNode, uint samDesired, uint ulHardwareProfile, uint Disposition, IntPtr phkDevice, uint ulFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CFGMGR32_CM_Open_DevNode_Key' -Namespace Win32 -PassThru
# $api::CM_Open_DevNode_Key(dnDevNode, samDesired, ulHardwareProfile, Disposition, phkDevice, ulFlags)#uselib "CFGMGR32.dll"
#func global CM_Open_DevNode_Key "CM_Open_DevNode_Key" sptr, sptr, sptr, sptr, sptr, sptr
; CM_Open_DevNode_Key dnDevNode, samDesired, ulHardwareProfile, Disposition, phkDevice, ulFlags ; 戻り値は stat
; dnDevNode : DWORD -> "sptr"
; samDesired : DWORD -> "sptr"
; ulHardwareProfile : DWORD -> "sptr"
; Disposition : DWORD -> "sptr"
; phkDevice : HKEY* out -> "sptr"
; ulFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "CFGMGR32.dll"
#cfunc global CM_Open_DevNode_Key "CM_Open_DevNode_Key" int, int, int, int, sptr, int
; res = CM_Open_DevNode_Key(dnDevNode, samDesired, ulHardwareProfile, Disposition, phkDevice, ulFlags)
; dnDevNode : DWORD -> "int"
; samDesired : DWORD -> "int"
; ulHardwareProfile : DWORD -> "int"
; Disposition : DWORD -> "int"
; phkDevice : HKEY* out -> "sptr"
; ulFlags : DWORD -> "int"; CONFIGRET CM_Open_DevNode_Key(DWORD dnDevNode, DWORD samDesired, DWORD ulHardwareProfile, DWORD Disposition, HKEY* phkDevice, DWORD ulFlags)
#uselib "CFGMGR32.dll"
#cfunc global CM_Open_DevNode_Key "CM_Open_DevNode_Key" int, int, int, int, intptr, int
; res = CM_Open_DevNode_Key(dnDevNode, samDesired, ulHardwareProfile, Disposition, phkDevice, ulFlags)
; dnDevNode : DWORD -> "int"
; samDesired : DWORD -> "int"
; ulHardwareProfile : DWORD -> "int"
; Disposition : DWORD -> "int"
; phkDevice : HKEY* out -> "intptr"
; ulFlags : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
cfgmgr32 = windows.NewLazySystemDLL("CFGMGR32.dll")
procCM_Open_DevNode_Key = cfgmgr32.NewProc("CM_Open_DevNode_Key")
)
// dnDevNode (DWORD), samDesired (DWORD), ulHardwareProfile (DWORD), Disposition (DWORD), phkDevice (HKEY* out), ulFlags (DWORD)
r1, _, err := procCM_Open_DevNode_Key.Call(
uintptr(dnDevNode),
uintptr(samDesired),
uintptr(ulHardwareProfile),
uintptr(Disposition),
uintptr(phkDevice),
uintptr(ulFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // CONFIGRETfunction CM_Open_DevNode_Key(
dnDevNode: DWORD; // DWORD
samDesired: DWORD; // DWORD
ulHardwareProfile: DWORD; // DWORD
Disposition: DWORD; // DWORD
phkDevice: Pointer; // HKEY* out
ulFlags: DWORD // DWORD
): DWORD; stdcall;
external 'CFGMGR32.dll' name 'CM_Open_DevNode_Key';result := DllCall("CFGMGR32\CM_Open_DevNode_Key"
, "UInt", dnDevNode ; DWORD
, "UInt", samDesired ; DWORD
, "UInt", ulHardwareProfile ; DWORD
, "UInt", Disposition ; DWORD
, "Ptr", phkDevice ; HKEY* out
, "UInt", ulFlags ; DWORD
, "UInt") ; return: CONFIGRET●CM_Open_DevNode_Key(dnDevNode, samDesired, ulHardwareProfile, Disposition, phkDevice, ulFlags) = DLL("CFGMGR32.dll", "dword CM_Open_DevNode_Key(dword, dword, dword, dword, void*, dword)")
# 呼び出し: CM_Open_DevNode_Key(dnDevNode, samDesired, ulHardwareProfile, Disposition, phkDevice, ulFlags)
# dnDevNode : DWORD -> "dword"
# samDesired : DWORD -> "dword"
# ulHardwareProfile : DWORD -> "dword"
# Disposition : DWORD -> "dword"
# phkDevice : HKEY* out -> "void*"
# ulFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "cfgmgr32" fn CM_Open_DevNode_Key(
dnDevNode: u32, // DWORD
samDesired: u32, // DWORD
ulHardwareProfile: u32, // DWORD
Disposition: u32, // DWORD
phkDevice: ?*anyopaque, // HKEY* out
ulFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;proc CM_Open_DevNode_Key(
dnDevNode: uint32, # DWORD
samDesired: uint32, # DWORD
ulHardwareProfile: uint32, # DWORD
Disposition: uint32, # DWORD
phkDevice: pointer, # HKEY* out
ulFlags: uint32 # DWORD
): uint32 {.importc: "CM_Open_DevNode_Key", stdcall, dynlib: "CFGMGR32.dll".}pragma(lib, "cfgmgr32");
extern(Windows)
uint CM_Open_DevNode_Key(
uint dnDevNode, // DWORD
uint samDesired, // DWORD
uint ulHardwareProfile, // DWORD
uint Disposition, // DWORD
void* phkDevice, // HKEY* out
uint ulFlags // DWORD
);ccall((:CM_Open_DevNode_Key, "CFGMGR32.dll"), stdcall, UInt32,
(UInt32, UInt32, UInt32, UInt32, Ptr{Cvoid}, UInt32),
dnDevNode, samDesired, ulHardwareProfile, Disposition, phkDevice, ulFlags)
# dnDevNode : DWORD -> UInt32
# samDesired : DWORD -> UInt32
# ulHardwareProfile : DWORD -> UInt32
# Disposition : DWORD -> UInt32
# phkDevice : HKEY* out -> Ptr{Cvoid}
# ulFlags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t CM_Open_DevNode_Key(
uint32_t dnDevNode,
uint32_t samDesired,
uint32_t ulHardwareProfile,
uint32_t Disposition,
void* phkDevice,
uint32_t ulFlags);
]]
local cfgmgr32 = ffi.load("cfgmgr32")
-- cfgmgr32.CM_Open_DevNode_Key(dnDevNode, samDesired, ulHardwareProfile, Disposition, phkDevice, ulFlags)
-- dnDevNode : DWORD
-- samDesired : DWORD
-- ulHardwareProfile : DWORD
-- Disposition : DWORD
-- phkDevice : HKEY* out
-- ulFlags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('CFGMGR32.dll');
const CM_Open_DevNode_Key = lib.func('__stdcall', 'CM_Open_DevNode_Key', 'uint32_t', ['uint32_t', 'uint32_t', 'uint32_t', 'uint32_t', 'void *', 'uint32_t']);
// CM_Open_DevNode_Key(dnDevNode, samDesired, ulHardwareProfile, Disposition, phkDevice, ulFlags)
// dnDevNode : DWORD -> 'uint32_t'
// samDesired : DWORD -> 'uint32_t'
// ulHardwareProfile : DWORD -> 'uint32_t'
// Disposition : DWORD -> 'uint32_t'
// phkDevice : HKEY* out -> 'void *'
// ulFlags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("CFGMGR32.dll", {
CM_Open_DevNode_Key: { parameters: ["u32", "u32", "u32", "u32", "pointer", "u32"], result: "u32" },
});
// lib.symbols.CM_Open_DevNode_Key(dnDevNode, samDesired, ulHardwareProfile, Disposition, phkDevice, ulFlags)
// dnDevNode : DWORD -> "u32"
// samDesired : DWORD -> "u32"
// ulHardwareProfile : DWORD -> "u32"
// Disposition : DWORD -> "u32"
// phkDevice : HKEY* out -> "pointer"
// ulFlags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t CM_Open_DevNode_Key(
uint32_t dnDevNode,
uint32_t samDesired,
uint32_t ulHardwareProfile,
uint32_t Disposition,
void* phkDevice,
uint32_t ulFlags);
C, "CFGMGR32.dll");
// $ffi->CM_Open_DevNode_Key(dnDevNode, samDesired, ulHardwareProfile, Disposition, phkDevice, ulFlags);
// dnDevNode : DWORD
// samDesired : DWORD
// ulHardwareProfile : DWORD
// Disposition : DWORD
// phkDevice : HKEY* out
// ulFlags : DWORD
// 構造体/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_Open_DevNode_Key(
int dnDevNode, // DWORD
int samDesired, // DWORD
int ulHardwareProfile, // DWORD
int Disposition, // DWORD
Pointer phkDevice, // HKEY* out
int ulFlags // DWORD
);
}@[Link("cfgmgr32")]
lib LibCFGMGR32
fun CM_Open_DevNode_Key = CM_Open_DevNode_Key(
dnDevNode : UInt32, # DWORD
samDesired : UInt32, # DWORD
ulHardwareProfile : UInt32, # DWORD
Disposition : UInt32, # DWORD
phkDevice : Void*, # HKEY* out
ulFlags : UInt32 # DWORD
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CM_Open_DevNode_KeyNative = Uint32 Function(Uint32, Uint32, Uint32, Uint32, Pointer<Void>, Uint32);
typedef CM_Open_DevNode_KeyDart = int Function(int, int, int, int, Pointer<Void>, int);
final CM_Open_DevNode_Key = DynamicLibrary.open('CFGMGR32.dll')
.lookupFunction<CM_Open_DevNode_KeyNative, CM_Open_DevNode_KeyDart>('CM_Open_DevNode_Key');
// dnDevNode : DWORD -> Uint32
// samDesired : DWORD -> Uint32
// ulHardwareProfile : DWORD -> Uint32
// Disposition : DWORD -> Uint32
// phkDevice : HKEY* out -> Pointer<Void>
// ulFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CM_Open_DevNode_Key(
dnDevNode: DWORD; // DWORD
samDesired: DWORD; // DWORD
ulHardwareProfile: DWORD; // DWORD
Disposition: DWORD; // DWORD
phkDevice: Pointer; // HKEY* out
ulFlags: DWORD // DWORD
): DWORD; stdcall;
external 'CFGMGR32.dll' name 'CM_Open_DevNode_Key';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CM_Open_DevNode_Key"
c_CM_Open_DevNode_Key :: Word32 -> Word32 -> Word32 -> Word32 -> Ptr () -> Word32 -> IO Word32
-- dnDevNode : DWORD -> Word32
-- samDesired : DWORD -> Word32
-- ulHardwareProfile : DWORD -> Word32
-- Disposition : DWORD -> Word32
-- phkDevice : HKEY* out -> Ptr ()
-- ulFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let cm_open_devnode_key =
foreign "CM_Open_DevNode_Key"
(uint32_t @-> uint32_t @-> uint32_t @-> uint32_t @-> (ptr void) @-> uint32_t @-> returning uint32_t)
(* dnDevNode : DWORD -> uint32_t *)
(* samDesired : DWORD -> uint32_t *)
(* ulHardwareProfile : DWORD -> uint32_t *)
(* Disposition : DWORD -> uint32_t *)
(* phkDevice : HKEY* out -> (ptr void) *)
(* ulFlags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library cfgmgr32 (t "CFGMGR32.dll"))
(cffi:use-foreign-library cfgmgr32)
(cffi:defcfun ("CM_Open_DevNode_Key" cm-open-dev-node-key :convention :stdcall) :uint32
(dn-dev-node :uint32) ; DWORD
(sam-desired :uint32) ; DWORD
(ul-hardware-profile :uint32) ; DWORD
(disposition :uint32) ; DWORD
(phk-device :pointer) ; HKEY* out
(ul-flags :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CM_Open_DevNode_Key = Win32::API::More->new('CFGMGR32',
'DWORD CM_Open_DevNode_Key(DWORD dnDevNode, DWORD samDesired, DWORD ulHardwareProfile, DWORD Disposition, HANDLE phkDevice, DWORD ulFlags)');
# my $ret = $CM_Open_DevNode_Key->Call($dnDevNode, $samDesired, $ulHardwareProfile, $Disposition, $phkDevice, $ulFlags);
# dnDevNode : DWORD -> DWORD
# samDesired : DWORD -> DWORD
# ulHardwareProfile : DWORD -> DWORD
# Disposition : DWORD -> DWORD
# phkDevice : HKEY* out -> HANDLE
# ulFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型