ホーム › Devices.Enumeration.Pnp › SwDeviceCreate
SwDeviceCreate
関数ソフトウェアデバイスを作成して列挙させる。
シグネチャ
// CFGMGR32.dll
#include <windows.h>
HRESULT SwDeviceCreate(
LPCWSTR pszEnumeratorName,
LPCWSTR pszParentDeviceInstance,
const SW_DEVICE_CREATE_INFO* pCreateInfo,
DWORD cPropertyCount,
const DEVPROPERTY* pProperties, // optional
SW_DEVICE_CREATE_CALLBACK pCallback,
void* pContext, // optional
HSWDEVICE* phSwDevice
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pszEnumeratorName | LPCWSTR | in |
| pszParentDeviceInstance | LPCWSTR | in |
| pCreateInfo | SW_DEVICE_CREATE_INFO* | in |
| cPropertyCount | DWORD | in |
| pProperties | DEVPROPERTY* | inoptional |
| pCallback | SW_DEVICE_CREATE_CALLBACK | in |
| pContext | void* | inoptional |
| phSwDevice | HSWDEVICE* | out |
戻り値の型: HRESULT
各言語での呼び出し定義
// CFGMGR32.dll
#include <windows.h>
HRESULT SwDeviceCreate(
LPCWSTR pszEnumeratorName,
LPCWSTR pszParentDeviceInstance,
const SW_DEVICE_CREATE_INFO* pCreateInfo,
DWORD cPropertyCount,
const DEVPROPERTY* pProperties, // optional
SW_DEVICE_CREATE_CALLBACK pCallback,
void* pContext, // optional
HSWDEVICE* phSwDevice
);[DllImport("CFGMGR32.dll", ExactSpelling = true)]
static extern int SwDeviceCreate(
[MarshalAs(UnmanagedType.LPWStr)] string pszEnumeratorName, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string pszParentDeviceInstance, // LPCWSTR
IntPtr pCreateInfo, // SW_DEVICE_CREATE_INFO*
uint cPropertyCount, // DWORD
IntPtr pProperties, // DEVPROPERTY* optional
IntPtr pCallback, // SW_DEVICE_CREATE_CALLBACK
IntPtr pContext, // void* optional
IntPtr phSwDevice // HSWDEVICE* out
);<DllImport("CFGMGR32.dll", ExactSpelling:=True)>
Public Shared Function SwDeviceCreate(
<MarshalAs(UnmanagedType.LPWStr)> pszEnumeratorName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> pszParentDeviceInstance As String, ' LPCWSTR
pCreateInfo As IntPtr, ' SW_DEVICE_CREATE_INFO*
cPropertyCount As UInteger, ' DWORD
pProperties As IntPtr, ' DEVPROPERTY* optional
pCallback As IntPtr, ' SW_DEVICE_CREATE_CALLBACK
pContext As IntPtr, ' void* optional
phSwDevice As IntPtr ' HSWDEVICE* out
) As Integer
End Function' pszEnumeratorName : LPCWSTR
' pszParentDeviceInstance : LPCWSTR
' pCreateInfo : SW_DEVICE_CREATE_INFO*
' cPropertyCount : DWORD
' pProperties : DEVPROPERTY* optional
' pCallback : SW_DEVICE_CREATE_CALLBACK
' pContext : void* optional
' phSwDevice : HSWDEVICE* out
Declare PtrSafe Function SwDeviceCreate Lib "cfgmgr32" ( _
ByVal pszEnumeratorName As LongPtr, _
ByVal pszParentDeviceInstance As LongPtr, _
ByVal pCreateInfo As LongPtr, _
ByVal cPropertyCount As Long, _
ByVal pProperties As LongPtr, _
ByVal pCallback As LongPtr, _
ByVal pContext As LongPtr, _
ByVal phSwDevice As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SwDeviceCreate = ctypes.windll.cfgmgr32.SwDeviceCreate
SwDeviceCreate.restype = ctypes.c_int
SwDeviceCreate.argtypes = [
wintypes.LPCWSTR, # pszEnumeratorName : LPCWSTR
wintypes.LPCWSTR, # pszParentDeviceInstance : LPCWSTR
ctypes.c_void_p, # pCreateInfo : SW_DEVICE_CREATE_INFO*
wintypes.DWORD, # cPropertyCount : DWORD
ctypes.c_void_p, # pProperties : DEVPROPERTY* optional
ctypes.c_void_p, # pCallback : SW_DEVICE_CREATE_CALLBACK
ctypes.POINTER(None), # pContext : void* optional
ctypes.c_void_p, # phSwDevice : HSWDEVICE* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('CFGMGR32.dll')
SwDeviceCreate = Fiddle::Function.new(
lib['SwDeviceCreate'],
[
Fiddle::TYPE_VOIDP, # pszEnumeratorName : LPCWSTR
Fiddle::TYPE_VOIDP, # pszParentDeviceInstance : LPCWSTR
Fiddle::TYPE_VOIDP, # pCreateInfo : SW_DEVICE_CREATE_INFO*
-Fiddle::TYPE_INT, # cPropertyCount : DWORD
Fiddle::TYPE_VOIDP, # pProperties : DEVPROPERTY* optional
Fiddle::TYPE_VOIDP, # pCallback : SW_DEVICE_CREATE_CALLBACK
Fiddle::TYPE_VOIDP, # pContext : void* optional
Fiddle::TYPE_VOIDP, # phSwDevice : HSWDEVICE* out
],
Fiddle::TYPE_INT)#[link(name = "cfgmgr32")]
extern "system" {
fn SwDeviceCreate(
pszEnumeratorName: *const u16, // LPCWSTR
pszParentDeviceInstance: *const u16, // LPCWSTR
pCreateInfo: *const SW_DEVICE_CREATE_INFO, // SW_DEVICE_CREATE_INFO*
cPropertyCount: u32, // DWORD
pProperties: *const DEVPROPERTY, // DEVPROPERTY* optional
pCallback: *const core::ffi::c_void, // SW_DEVICE_CREATE_CALLBACK
pContext: *mut (), // void* optional
phSwDevice: *mut *mut core::ffi::c_void // HSWDEVICE* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("CFGMGR32.dll")]
public static extern int SwDeviceCreate([MarshalAs(UnmanagedType.LPWStr)] string pszEnumeratorName, [MarshalAs(UnmanagedType.LPWStr)] string pszParentDeviceInstance, IntPtr pCreateInfo, uint cPropertyCount, IntPtr pProperties, IntPtr pCallback, IntPtr pContext, IntPtr phSwDevice);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CFGMGR32_SwDeviceCreate' -Namespace Win32 -PassThru
# $api::SwDeviceCreate(pszEnumeratorName, pszParentDeviceInstance, pCreateInfo, cPropertyCount, pProperties, pCallback, pContext, phSwDevice)#uselib "CFGMGR32.dll"
#func global SwDeviceCreate "SwDeviceCreate" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SwDeviceCreate pszEnumeratorName, pszParentDeviceInstance, varptr(pCreateInfo), cPropertyCount, varptr(pProperties), pCallback, pContext, phSwDevice ; 戻り値は stat
; pszEnumeratorName : LPCWSTR -> "sptr"
; pszParentDeviceInstance : LPCWSTR -> "sptr"
; pCreateInfo : SW_DEVICE_CREATE_INFO* -> "sptr"
; cPropertyCount : DWORD -> "sptr"
; pProperties : DEVPROPERTY* optional -> "sptr"
; pCallback : SW_DEVICE_CREATE_CALLBACK -> "sptr"
; pContext : void* optional -> "sptr"
; phSwDevice : HSWDEVICE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "CFGMGR32.dll" #cfunc global SwDeviceCreate "SwDeviceCreate" wstr, wstr, var, int, var, sptr, sptr, sptr ; res = SwDeviceCreate(pszEnumeratorName, pszParentDeviceInstance, pCreateInfo, cPropertyCount, pProperties, pCallback, pContext, phSwDevice) ; pszEnumeratorName : LPCWSTR -> "wstr" ; pszParentDeviceInstance : LPCWSTR -> "wstr" ; pCreateInfo : SW_DEVICE_CREATE_INFO* -> "var" ; cPropertyCount : DWORD -> "int" ; pProperties : DEVPROPERTY* optional -> "var" ; pCallback : SW_DEVICE_CREATE_CALLBACK -> "sptr" ; pContext : void* optional -> "sptr" ; phSwDevice : HSWDEVICE* out -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "CFGMGR32.dll" #cfunc global SwDeviceCreate "SwDeviceCreate" wstr, wstr, sptr, int, sptr, sptr, sptr, sptr ; res = SwDeviceCreate(pszEnumeratorName, pszParentDeviceInstance, varptr(pCreateInfo), cPropertyCount, varptr(pProperties), pCallback, pContext, phSwDevice) ; pszEnumeratorName : LPCWSTR -> "wstr" ; pszParentDeviceInstance : LPCWSTR -> "wstr" ; pCreateInfo : SW_DEVICE_CREATE_INFO* -> "sptr" ; cPropertyCount : DWORD -> "int" ; pProperties : DEVPROPERTY* optional -> "sptr" ; pCallback : SW_DEVICE_CREATE_CALLBACK -> "sptr" ; pContext : void* optional -> "sptr" ; phSwDevice : HSWDEVICE* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT SwDeviceCreate(LPCWSTR pszEnumeratorName, LPCWSTR pszParentDeviceInstance, SW_DEVICE_CREATE_INFO* pCreateInfo, DWORD cPropertyCount, DEVPROPERTY* pProperties, SW_DEVICE_CREATE_CALLBACK pCallback, void* pContext, HSWDEVICE* phSwDevice) #uselib "CFGMGR32.dll" #cfunc global SwDeviceCreate "SwDeviceCreate" wstr, wstr, var, int, var, intptr, intptr, intptr ; res = SwDeviceCreate(pszEnumeratorName, pszParentDeviceInstance, pCreateInfo, cPropertyCount, pProperties, pCallback, pContext, phSwDevice) ; pszEnumeratorName : LPCWSTR -> "wstr" ; pszParentDeviceInstance : LPCWSTR -> "wstr" ; pCreateInfo : SW_DEVICE_CREATE_INFO* -> "var" ; cPropertyCount : DWORD -> "int" ; pProperties : DEVPROPERTY* optional -> "var" ; pCallback : SW_DEVICE_CREATE_CALLBACK -> "intptr" ; pContext : void* optional -> "intptr" ; phSwDevice : HSWDEVICE* out -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT SwDeviceCreate(LPCWSTR pszEnumeratorName, LPCWSTR pszParentDeviceInstance, SW_DEVICE_CREATE_INFO* pCreateInfo, DWORD cPropertyCount, DEVPROPERTY* pProperties, SW_DEVICE_CREATE_CALLBACK pCallback, void* pContext, HSWDEVICE* phSwDevice) #uselib "CFGMGR32.dll" #cfunc global SwDeviceCreate "SwDeviceCreate" wstr, wstr, intptr, int, intptr, intptr, intptr, intptr ; res = SwDeviceCreate(pszEnumeratorName, pszParentDeviceInstance, varptr(pCreateInfo), cPropertyCount, varptr(pProperties), pCallback, pContext, phSwDevice) ; pszEnumeratorName : LPCWSTR -> "wstr" ; pszParentDeviceInstance : LPCWSTR -> "wstr" ; pCreateInfo : SW_DEVICE_CREATE_INFO* -> "intptr" ; cPropertyCount : DWORD -> "int" ; pProperties : DEVPROPERTY* optional -> "intptr" ; pCallback : SW_DEVICE_CREATE_CALLBACK -> "intptr" ; pContext : void* optional -> "intptr" ; phSwDevice : HSWDEVICE* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
cfgmgr32 = windows.NewLazySystemDLL("CFGMGR32.dll")
procSwDeviceCreate = cfgmgr32.NewProc("SwDeviceCreate")
)
// pszEnumeratorName (LPCWSTR), pszParentDeviceInstance (LPCWSTR), pCreateInfo (SW_DEVICE_CREATE_INFO*), cPropertyCount (DWORD), pProperties (DEVPROPERTY* optional), pCallback (SW_DEVICE_CREATE_CALLBACK), pContext (void* optional), phSwDevice (HSWDEVICE* out)
r1, _, err := procSwDeviceCreate.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszEnumeratorName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszParentDeviceInstance))),
uintptr(pCreateInfo),
uintptr(cPropertyCount),
uintptr(pProperties),
uintptr(pCallback),
uintptr(pContext),
uintptr(phSwDevice),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction SwDeviceCreate(
pszEnumeratorName: PWideChar; // LPCWSTR
pszParentDeviceInstance: PWideChar; // LPCWSTR
pCreateInfo: Pointer; // SW_DEVICE_CREATE_INFO*
cPropertyCount: DWORD; // DWORD
pProperties: Pointer; // DEVPROPERTY* optional
pCallback: Pointer; // SW_DEVICE_CREATE_CALLBACK
pContext: Pointer; // void* optional
phSwDevice: Pointer // HSWDEVICE* out
): Integer; stdcall;
external 'CFGMGR32.dll' name 'SwDeviceCreate';result := DllCall("CFGMGR32\SwDeviceCreate"
, "WStr", pszEnumeratorName ; LPCWSTR
, "WStr", pszParentDeviceInstance ; LPCWSTR
, "Ptr", pCreateInfo ; SW_DEVICE_CREATE_INFO*
, "UInt", cPropertyCount ; DWORD
, "Ptr", pProperties ; DEVPROPERTY* optional
, "Ptr", pCallback ; SW_DEVICE_CREATE_CALLBACK
, "Ptr", pContext ; void* optional
, "Ptr", phSwDevice ; HSWDEVICE* out
, "Int") ; return: HRESULT●SwDeviceCreate(pszEnumeratorName, pszParentDeviceInstance, pCreateInfo, cPropertyCount, pProperties, pCallback, pContext, phSwDevice) = DLL("CFGMGR32.dll", "int SwDeviceCreate(char*, char*, void*, dword, void*, void*, void*, void*)")
# 呼び出し: SwDeviceCreate(pszEnumeratorName, pszParentDeviceInstance, pCreateInfo, cPropertyCount, pProperties, pCallback, pContext, phSwDevice)
# pszEnumeratorName : LPCWSTR -> "char*"
# pszParentDeviceInstance : LPCWSTR -> "char*"
# pCreateInfo : SW_DEVICE_CREATE_INFO* -> "void*"
# cPropertyCount : DWORD -> "dword"
# pProperties : DEVPROPERTY* optional -> "void*"
# pCallback : SW_DEVICE_CREATE_CALLBACK -> "void*"
# pContext : void* optional -> "void*"
# phSwDevice : HSWDEVICE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。