Win32 API 日本語リファレンス
ホームDevices.Enumeration.Pnp › SwDeviceInterfaceRegister

SwDeviceInterfaceRegister

関数
ソフトウェアデバイスのデバイスインターフェイスを登録する。
DLLCFGMGR32.dll呼出規約winapi対応OSwindows8.0

シグネチャ

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

HRESULT SwDeviceInterfaceRegister(
    HSWDEVICE hSwDevice,
    const GUID* pInterfaceClassGuid,
    LPCWSTR pszReferenceString,   // optional
    DWORD cPropertyCount,
    const DEVPROPERTY* pProperties,   // optional
    BOOL fEnabled,
    LPWSTR* ppszDeviceInterfaceId
);

パラメーター

名前方向
hSwDeviceHSWDEVICEin
pInterfaceClassGuidGUID*in
pszReferenceStringLPCWSTRinoptional
cPropertyCountDWORDin
pPropertiesDEVPROPERTY*inoptional
fEnabledBOOLin
ppszDeviceInterfaceIdLPWSTR*out

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SwDeviceInterfaceRegister(
    HSWDEVICE hSwDevice,
    const GUID* pInterfaceClassGuid,
    LPCWSTR pszReferenceString,   // optional
    DWORD cPropertyCount,
    const DEVPROPERTY* pProperties,   // optional
    BOOL fEnabled,
    LPWSTR* ppszDeviceInterfaceId
);
[DllImport("CFGMGR32.dll", ExactSpelling = true)]
static extern int SwDeviceInterfaceRegister(
    IntPtr hSwDevice,   // HSWDEVICE
    ref Guid pInterfaceClassGuid,   // GUID*
    [MarshalAs(UnmanagedType.LPWStr)] string pszReferenceString,   // LPCWSTR optional
    uint cPropertyCount,   // DWORD
    IntPtr pProperties,   // DEVPROPERTY* optional
    bool fEnabled,   // BOOL
    IntPtr ppszDeviceInterfaceId   // LPWSTR* out
);
<DllImport("CFGMGR32.dll", ExactSpelling:=True)>
Public Shared Function SwDeviceInterfaceRegister(
    hSwDevice As IntPtr,   ' HSWDEVICE
    ByRef pInterfaceClassGuid As Guid,   ' GUID*
    <MarshalAs(UnmanagedType.LPWStr)> pszReferenceString As String,   ' LPCWSTR optional
    cPropertyCount As UInteger,   ' DWORD
    pProperties As IntPtr,   ' DEVPROPERTY* optional
    fEnabled As Boolean,   ' BOOL
    ppszDeviceInterfaceId As IntPtr   ' LPWSTR* out
) As Integer
End Function
' hSwDevice : HSWDEVICE
' pInterfaceClassGuid : GUID*
' pszReferenceString : LPCWSTR optional
' cPropertyCount : DWORD
' pProperties : DEVPROPERTY* optional
' fEnabled : BOOL
' ppszDeviceInterfaceId : LPWSTR* out
Declare PtrSafe Function SwDeviceInterfaceRegister Lib "cfgmgr32" ( _
    ByVal hSwDevice As LongPtr, _
    ByVal pInterfaceClassGuid As LongPtr, _
    ByVal pszReferenceString As LongPtr, _
    ByVal cPropertyCount As Long, _
    ByVal pProperties As LongPtr, _
    ByVal fEnabled As Long, _
    ByVal ppszDeviceInterfaceId As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SwDeviceInterfaceRegister = ctypes.windll.cfgmgr32.SwDeviceInterfaceRegister
SwDeviceInterfaceRegister.restype = ctypes.c_int
SwDeviceInterfaceRegister.argtypes = [
    wintypes.HANDLE,  # hSwDevice : HSWDEVICE
    ctypes.c_void_p,  # pInterfaceClassGuid : GUID*
    wintypes.LPCWSTR,  # pszReferenceString : LPCWSTR optional
    wintypes.DWORD,  # cPropertyCount : DWORD
    ctypes.c_void_p,  # pProperties : DEVPROPERTY* optional
    wintypes.BOOL,  # fEnabled : BOOL
    ctypes.c_void_p,  # ppszDeviceInterfaceId : LPWSTR* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CFGMGR32.dll')
SwDeviceInterfaceRegister = Fiddle::Function.new(
  lib['SwDeviceInterfaceRegister'],
  [
    Fiddle::TYPE_VOIDP,  # hSwDevice : HSWDEVICE
    Fiddle::TYPE_VOIDP,  # pInterfaceClassGuid : GUID*
    Fiddle::TYPE_VOIDP,  # pszReferenceString : LPCWSTR optional
    -Fiddle::TYPE_INT,  # cPropertyCount : DWORD
    Fiddle::TYPE_VOIDP,  # pProperties : DEVPROPERTY* optional
    Fiddle::TYPE_INT,  # fEnabled : BOOL
    Fiddle::TYPE_VOIDP,  # ppszDeviceInterfaceId : LPWSTR* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "cfgmgr32")]
extern "system" {
    fn SwDeviceInterfaceRegister(
        hSwDevice: *mut core::ffi::c_void,  // HSWDEVICE
        pInterfaceClassGuid: *const GUID,  // GUID*
        pszReferenceString: *const u16,  // LPCWSTR optional
        cPropertyCount: u32,  // DWORD
        pProperties: *const DEVPROPERTY,  // DEVPROPERTY* optional
        fEnabled: i32,  // BOOL
        ppszDeviceInterfaceId: *mut *mut u16  // LPWSTR* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("CFGMGR32.dll")]
public static extern int SwDeviceInterfaceRegister(IntPtr hSwDevice, ref Guid pInterfaceClassGuid, [MarshalAs(UnmanagedType.LPWStr)] string pszReferenceString, uint cPropertyCount, IntPtr pProperties, bool fEnabled, IntPtr ppszDeviceInterfaceId);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CFGMGR32_SwDeviceInterfaceRegister' -Namespace Win32 -PassThru
# $api::SwDeviceInterfaceRegister(hSwDevice, pInterfaceClassGuid, pszReferenceString, cPropertyCount, pProperties, fEnabled, ppszDeviceInterfaceId)
#uselib "CFGMGR32.dll"
#func global SwDeviceInterfaceRegister "SwDeviceInterfaceRegister" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SwDeviceInterfaceRegister hSwDevice, varptr(pInterfaceClassGuid), pszReferenceString, cPropertyCount, varptr(pProperties), fEnabled, varptr(ppszDeviceInterfaceId)   ; 戻り値は stat
; hSwDevice : HSWDEVICE -> "sptr"
; pInterfaceClassGuid : GUID* -> "sptr"
; pszReferenceString : LPCWSTR optional -> "sptr"
; cPropertyCount : DWORD -> "sptr"
; pProperties : DEVPROPERTY* optional -> "sptr"
; fEnabled : BOOL -> "sptr"
; ppszDeviceInterfaceId : LPWSTR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "CFGMGR32.dll"
#cfunc global SwDeviceInterfaceRegister "SwDeviceInterfaceRegister" sptr, var, wstr, int, var, int, var
; res = SwDeviceInterfaceRegister(hSwDevice, pInterfaceClassGuid, pszReferenceString, cPropertyCount, pProperties, fEnabled, ppszDeviceInterfaceId)
; hSwDevice : HSWDEVICE -> "sptr"
; pInterfaceClassGuid : GUID* -> "var"
; pszReferenceString : LPCWSTR optional -> "wstr"
; cPropertyCount : DWORD -> "int"
; pProperties : DEVPROPERTY* optional -> "var"
; fEnabled : BOOL -> "int"
; ppszDeviceInterfaceId : LPWSTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT SwDeviceInterfaceRegister(HSWDEVICE hSwDevice, GUID* pInterfaceClassGuid, LPCWSTR pszReferenceString, DWORD cPropertyCount, DEVPROPERTY* pProperties, BOOL fEnabled, LPWSTR* ppszDeviceInterfaceId)
#uselib "CFGMGR32.dll"
#cfunc global SwDeviceInterfaceRegister "SwDeviceInterfaceRegister" intptr, var, wstr, int, var, int, var
; res = SwDeviceInterfaceRegister(hSwDevice, pInterfaceClassGuid, pszReferenceString, cPropertyCount, pProperties, fEnabled, ppszDeviceInterfaceId)
; hSwDevice : HSWDEVICE -> "intptr"
; pInterfaceClassGuid : GUID* -> "var"
; pszReferenceString : LPCWSTR optional -> "wstr"
; cPropertyCount : DWORD -> "int"
; pProperties : DEVPROPERTY* optional -> "var"
; fEnabled : BOOL -> "int"
; ppszDeviceInterfaceId : LPWSTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	cfgmgr32 = windows.NewLazySystemDLL("CFGMGR32.dll")
	procSwDeviceInterfaceRegister = cfgmgr32.NewProc("SwDeviceInterfaceRegister")
)

// hSwDevice (HSWDEVICE), pInterfaceClassGuid (GUID*), pszReferenceString (LPCWSTR optional), cPropertyCount (DWORD), pProperties (DEVPROPERTY* optional), fEnabled (BOOL), ppszDeviceInterfaceId (LPWSTR* out)
r1, _, err := procSwDeviceInterfaceRegister.Call(
	uintptr(hSwDevice),
	uintptr(pInterfaceClassGuid),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszReferenceString))),
	uintptr(cPropertyCount),
	uintptr(pProperties),
	uintptr(fEnabled),
	uintptr(ppszDeviceInterfaceId),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SwDeviceInterfaceRegister(
  hSwDevice: THandle;   // HSWDEVICE
  pInterfaceClassGuid: PGUID;   // GUID*
  pszReferenceString: PWideChar;   // LPCWSTR optional
  cPropertyCount: DWORD;   // DWORD
  pProperties: Pointer;   // DEVPROPERTY* optional
  fEnabled: BOOL;   // BOOL
  ppszDeviceInterfaceId: PPWideChar   // LPWSTR* out
): Integer; stdcall;
  external 'CFGMGR32.dll' name 'SwDeviceInterfaceRegister';
result := DllCall("CFGMGR32\SwDeviceInterfaceRegister"
    , "Ptr", hSwDevice   ; HSWDEVICE
    , "Ptr", pInterfaceClassGuid   ; GUID*
    , "WStr", pszReferenceString   ; LPCWSTR optional
    , "UInt", cPropertyCount   ; DWORD
    , "Ptr", pProperties   ; DEVPROPERTY* optional
    , "Int", fEnabled   ; BOOL
    , "Ptr", ppszDeviceInterfaceId   ; LPWSTR* out
    , "Int")   ; return: HRESULT
●SwDeviceInterfaceRegister(hSwDevice, pInterfaceClassGuid, pszReferenceString, cPropertyCount, pProperties, fEnabled, ppszDeviceInterfaceId) = DLL("CFGMGR32.dll", "int SwDeviceInterfaceRegister(void*, void*, char*, dword, void*, bool, void*)")
# 呼び出し: SwDeviceInterfaceRegister(hSwDevice, pInterfaceClassGuid, pszReferenceString, cPropertyCount, pProperties, fEnabled, ppszDeviceInterfaceId)
# hSwDevice : HSWDEVICE -> "void*"
# pInterfaceClassGuid : GUID* -> "void*"
# pszReferenceString : LPCWSTR optional -> "char*"
# cPropertyCount : DWORD -> "dword"
# pProperties : DEVPROPERTY* optional -> "void*"
# fEnabled : BOOL -> "bool"
# ppszDeviceInterfaceId : LPWSTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。