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

DevGetObjectPropertiesEx

関数
拡張パラメータ付きでデバイスオブジェクトのプロパティを取得する。
DLLapi-ms-win-devices-query-l1-1-1.dll呼出規約winapi

シグネチャ

// api-ms-win-devices-query-l1-1-1.dll
#include <windows.h>

HRESULT DevGetObjectPropertiesEx(
    DEV_OBJECT_TYPE ObjectType,
    LPCWSTR pszObjectId,
    DWORD QueryFlags,
    DWORD cRequestedProperties,
    const DEVPROPCOMPKEY* pRequestedProperties,
    DWORD cExtendedParameterCount,
    const DEV_QUERY_PARAMETER* pExtendedParameters,   // optional
    DWORD* pcPropertyCount,
    const DEVPROPERTY** ppProperties
);

パラメーター

名前方向
ObjectTypeDEV_OBJECT_TYPEin
pszObjectIdLPCWSTRin
QueryFlagsDWORDin
cRequestedPropertiesDWORDin
pRequestedPropertiesDEVPROPCOMPKEY*in
cExtendedParameterCountDWORDin
pExtendedParametersDEV_QUERY_PARAMETER*inoptional
pcPropertyCountDWORD*out
ppPropertiesDEVPROPERTY**out

戻り値の型: HRESULT

各言語での呼び出し定義

// api-ms-win-devices-query-l1-1-1.dll
#include <windows.h>

HRESULT DevGetObjectPropertiesEx(
    DEV_OBJECT_TYPE ObjectType,
    LPCWSTR pszObjectId,
    DWORD QueryFlags,
    DWORD cRequestedProperties,
    const DEVPROPCOMPKEY* pRequestedProperties,
    DWORD cExtendedParameterCount,
    const DEV_QUERY_PARAMETER* pExtendedParameters,   // optional
    DWORD* pcPropertyCount,
    const DEVPROPERTY** ppProperties
);
[DllImport("api-ms-win-devices-query-l1-1-1.dll", ExactSpelling = true)]
static extern int DevGetObjectPropertiesEx(
    int ObjectType,   // DEV_OBJECT_TYPE
    [MarshalAs(UnmanagedType.LPWStr)] string pszObjectId,   // LPCWSTR
    uint QueryFlags,   // DWORD
    uint cRequestedProperties,   // DWORD
    IntPtr pRequestedProperties,   // DEVPROPCOMPKEY*
    uint cExtendedParameterCount,   // DWORD
    IntPtr pExtendedParameters,   // DEV_QUERY_PARAMETER* optional
    out uint pcPropertyCount,   // DWORD* out
    IntPtr ppProperties   // DEVPROPERTY** out
);
<DllImport("api-ms-win-devices-query-l1-1-1.dll", ExactSpelling:=True)>
Public Shared Function DevGetObjectPropertiesEx(
    ObjectType As Integer,   ' DEV_OBJECT_TYPE
    <MarshalAs(UnmanagedType.LPWStr)> pszObjectId As String,   ' LPCWSTR
    QueryFlags As UInteger,   ' DWORD
    cRequestedProperties As UInteger,   ' DWORD
    pRequestedProperties As IntPtr,   ' DEVPROPCOMPKEY*
    cExtendedParameterCount As UInteger,   ' DWORD
    pExtendedParameters As IntPtr,   ' DEV_QUERY_PARAMETER* optional
    <Out> ByRef pcPropertyCount As UInteger,   ' DWORD* out
    ppProperties As IntPtr   ' DEVPROPERTY** out
) As Integer
End Function
' ObjectType : DEV_OBJECT_TYPE
' pszObjectId : LPCWSTR
' QueryFlags : DWORD
' cRequestedProperties : DWORD
' pRequestedProperties : DEVPROPCOMPKEY*
' cExtendedParameterCount : DWORD
' pExtendedParameters : DEV_QUERY_PARAMETER* optional
' pcPropertyCount : DWORD* out
' ppProperties : DEVPROPERTY** out
Declare PtrSafe Function DevGetObjectPropertiesEx Lib "api-ms-win-devices-query-l1-1-1" ( _
    ByVal ObjectType As Long, _
    ByVal pszObjectId As LongPtr, _
    ByVal QueryFlags As Long, _
    ByVal cRequestedProperties As Long, _
    ByVal pRequestedProperties As LongPtr, _
    ByVal cExtendedParameterCount As Long, _
    ByVal pExtendedParameters As LongPtr, _
    ByRef pcPropertyCount As Long, _
    ByVal ppProperties As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DevGetObjectPropertiesEx = ctypes.windll.LoadLibrary("api-ms-win-devices-query-l1-1-1.dll").DevGetObjectPropertiesEx
DevGetObjectPropertiesEx.restype = ctypes.c_int
DevGetObjectPropertiesEx.argtypes = [
    ctypes.c_int,  # ObjectType : DEV_OBJECT_TYPE
    wintypes.LPCWSTR,  # pszObjectId : LPCWSTR
    wintypes.DWORD,  # QueryFlags : DWORD
    wintypes.DWORD,  # cRequestedProperties : DWORD
    ctypes.c_void_p,  # pRequestedProperties : DEVPROPCOMPKEY*
    wintypes.DWORD,  # cExtendedParameterCount : DWORD
    ctypes.c_void_p,  # pExtendedParameters : DEV_QUERY_PARAMETER* optional
    ctypes.POINTER(wintypes.DWORD),  # pcPropertyCount : DWORD* out
    ctypes.c_void_p,  # ppProperties : DEVPROPERTY** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('api-ms-win-devices-query-l1-1-1.dll')
DevGetObjectPropertiesEx = Fiddle::Function.new(
  lib['DevGetObjectPropertiesEx'],
  [
    Fiddle::TYPE_INT,  # ObjectType : DEV_OBJECT_TYPE
    Fiddle::TYPE_VOIDP,  # pszObjectId : LPCWSTR
    -Fiddle::TYPE_INT,  # QueryFlags : DWORD
    -Fiddle::TYPE_INT,  # cRequestedProperties : DWORD
    Fiddle::TYPE_VOIDP,  # pRequestedProperties : DEVPROPCOMPKEY*
    -Fiddle::TYPE_INT,  # cExtendedParameterCount : DWORD
    Fiddle::TYPE_VOIDP,  # pExtendedParameters : DEV_QUERY_PARAMETER* optional
    Fiddle::TYPE_VOIDP,  # pcPropertyCount : DWORD* out
    Fiddle::TYPE_VOIDP,  # ppProperties : DEVPROPERTY** out
  ],
  Fiddle::TYPE_INT)
#[link(name = "api-ms-win-devices-query-l1-1-1")]
extern "system" {
    fn DevGetObjectPropertiesEx(
        ObjectType: i32,  // DEV_OBJECT_TYPE
        pszObjectId: *const u16,  // LPCWSTR
        QueryFlags: u32,  // DWORD
        cRequestedProperties: u32,  // DWORD
        pRequestedProperties: *const DEVPROPCOMPKEY,  // DEVPROPCOMPKEY*
        cExtendedParameterCount: u32,  // DWORD
        pExtendedParameters: *const DEV_QUERY_PARAMETER,  // DEV_QUERY_PARAMETER* optional
        pcPropertyCount: *mut u32,  // DWORD* out
        ppProperties: *const *const DEVPROPERTY  // DEVPROPERTY** out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("api-ms-win-devices-query-l1-1-1.dll")]
public static extern int DevGetObjectPropertiesEx(int ObjectType, [MarshalAs(UnmanagedType.LPWStr)] string pszObjectId, uint QueryFlags, uint cRequestedProperties, IntPtr pRequestedProperties, uint cExtendedParameterCount, IntPtr pExtendedParameters, out uint pcPropertyCount, IntPtr ppProperties);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-devices-query-l1-1-1_DevGetObjectPropertiesEx' -Namespace Win32 -PassThru
# $api::DevGetObjectPropertiesEx(ObjectType, pszObjectId, QueryFlags, cRequestedProperties, pRequestedProperties, cExtendedParameterCount, pExtendedParameters, pcPropertyCount, ppProperties)
#uselib "api-ms-win-devices-query-l1-1-1.dll"
#func global DevGetObjectPropertiesEx "DevGetObjectPropertiesEx" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; DevGetObjectPropertiesEx ObjectType, pszObjectId, QueryFlags, cRequestedProperties, varptr(pRequestedProperties), cExtendedParameterCount, varptr(pExtendedParameters), varptr(pcPropertyCount), varptr(ppProperties)   ; 戻り値は stat
; ObjectType : DEV_OBJECT_TYPE -> "sptr"
; pszObjectId : LPCWSTR -> "sptr"
; QueryFlags : DWORD -> "sptr"
; cRequestedProperties : DWORD -> "sptr"
; pRequestedProperties : DEVPROPCOMPKEY* -> "sptr"
; cExtendedParameterCount : DWORD -> "sptr"
; pExtendedParameters : DEV_QUERY_PARAMETER* optional -> "sptr"
; pcPropertyCount : DWORD* out -> "sptr"
; ppProperties : DEVPROPERTY** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "api-ms-win-devices-query-l1-1-1.dll"
#cfunc global DevGetObjectPropertiesEx "DevGetObjectPropertiesEx" int, wstr, int, int, var, int, var, var, var
; res = DevGetObjectPropertiesEx(ObjectType, pszObjectId, QueryFlags, cRequestedProperties, pRequestedProperties, cExtendedParameterCount, pExtendedParameters, pcPropertyCount, ppProperties)
; ObjectType : DEV_OBJECT_TYPE -> "int"
; pszObjectId : LPCWSTR -> "wstr"
; QueryFlags : DWORD -> "int"
; cRequestedProperties : DWORD -> "int"
; pRequestedProperties : DEVPROPCOMPKEY* -> "var"
; cExtendedParameterCount : DWORD -> "int"
; pExtendedParameters : DEV_QUERY_PARAMETER* optional -> "var"
; pcPropertyCount : DWORD* out -> "var"
; ppProperties : DEVPROPERTY** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT DevGetObjectPropertiesEx(DEV_OBJECT_TYPE ObjectType, LPCWSTR pszObjectId, DWORD QueryFlags, DWORD cRequestedProperties, DEVPROPCOMPKEY* pRequestedProperties, DWORD cExtendedParameterCount, DEV_QUERY_PARAMETER* pExtendedParameters, DWORD* pcPropertyCount, DEVPROPERTY** ppProperties)
#uselib "api-ms-win-devices-query-l1-1-1.dll"
#cfunc global DevGetObjectPropertiesEx "DevGetObjectPropertiesEx" int, wstr, int, int, var, int, var, var, var
; res = DevGetObjectPropertiesEx(ObjectType, pszObjectId, QueryFlags, cRequestedProperties, pRequestedProperties, cExtendedParameterCount, pExtendedParameters, pcPropertyCount, ppProperties)
; ObjectType : DEV_OBJECT_TYPE -> "int"
; pszObjectId : LPCWSTR -> "wstr"
; QueryFlags : DWORD -> "int"
; cRequestedProperties : DWORD -> "int"
; pRequestedProperties : DEVPROPCOMPKEY* -> "var"
; cExtendedParameterCount : DWORD -> "int"
; pExtendedParameters : DEV_QUERY_PARAMETER* optional -> "var"
; pcPropertyCount : DWORD* out -> "var"
; ppProperties : DEVPROPERTY** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	api_ms_win_devices_query_l1_1_1 = windows.NewLazySystemDLL("api-ms-win-devices-query-l1-1-1.dll")
	procDevGetObjectPropertiesEx = api_ms_win_devices_query_l1_1_1.NewProc("DevGetObjectPropertiesEx")
)

// ObjectType (DEV_OBJECT_TYPE), pszObjectId (LPCWSTR), QueryFlags (DWORD), cRequestedProperties (DWORD), pRequestedProperties (DEVPROPCOMPKEY*), cExtendedParameterCount (DWORD), pExtendedParameters (DEV_QUERY_PARAMETER* optional), pcPropertyCount (DWORD* out), ppProperties (DEVPROPERTY** out)
r1, _, err := procDevGetObjectPropertiesEx.Call(
	uintptr(ObjectType),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszObjectId))),
	uintptr(QueryFlags),
	uintptr(cRequestedProperties),
	uintptr(pRequestedProperties),
	uintptr(cExtendedParameterCount),
	uintptr(pExtendedParameters),
	uintptr(pcPropertyCount),
	uintptr(ppProperties),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function DevGetObjectPropertiesEx(
  ObjectType: Integer;   // DEV_OBJECT_TYPE
  pszObjectId: PWideChar;   // LPCWSTR
  QueryFlags: DWORD;   // DWORD
  cRequestedProperties: DWORD;   // DWORD
  pRequestedProperties: Pointer;   // DEVPROPCOMPKEY*
  cExtendedParameterCount: DWORD;   // DWORD
  pExtendedParameters: Pointer;   // DEV_QUERY_PARAMETER* optional
  pcPropertyCount: Pointer;   // DWORD* out
  ppProperties: Pointer   // DEVPROPERTY** out
): Integer; stdcall;
  external 'api-ms-win-devices-query-l1-1-1.dll' name 'DevGetObjectPropertiesEx';
result := DllCall("api-ms-win-devices-query-l1-1-1\DevGetObjectPropertiesEx"
    , "Int", ObjectType   ; DEV_OBJECT_TYPE
    , "WStr", pszObjectId   ; LPCWSTR
    , "UInt", QueryFlags   ; DWORD
    , "UInt", cRequestedProperties   ; DWORD
    , "Ptr", pRequestedProperties   ; DEVPROPCOMPKEY*
    , "UInt", cExtendedParameterCount   ; DWORD
    , "Ptr", pExtendedParameters   ; DEV_QUERY_PARAMETER* optional
    , "Ptr", pcPropertyCount   ; DWORD* out
    , "Ptr", ppProperties   ; DEVPROPERTY** out
    , "Int")   ; return: HRESULT
●DevGetObjectPropertiesEx(ObjectType, pszObjectId, QueryFlags, cRequestedProperties, pRequestedProperties, cExtendedParameterCount, pExtendedParameters, pcPropertyCount, ppProperties) = DLL("api-ms-win-devices-query-l1-1-1.dll", "int DevGetObjectPropertiesEx(int, char*, dword, dword, void*, dword, void*, void*, void*)")
# 呼び出し: DevGetObjectPropertiesEx(ObjectType, pszObjectId, QueryFlags, cRequestedProperties, pRequestedProperties, cExtendedParameterCount, pExtendedParameters, pcPropertyCount, ppProperties)
# ObjectType : DEV_OBJECT_TYPE -> "int"
# pszObjectId : LPCWSTR -> "char*"
# QueryFlags : DWORD -> "dword"
# cRequestedProperties : DWORD -> "dword"
# pRequestedProperties : DEVPROPCOMPKEY* -> "void*"
# cExtendedParameterCount : DWORD -> "dword"
# pExtendedParameters : DEV_QUERY_PARAMETER* optional -> "void*"
# pcPropertyCount : DWORD* out -> "void*"
# ppProperties : DEVPROPERTY** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。