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

SP_DEVINFO_DATA

構造体
サイズx64: 32 バイト / x86: 28 バイトパッキング1

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
cbSizeDWORD4+0+0この構造体のバイト単位サイズ。呼び出し前に必ず設定する。
ClassGuidGUID16+4+4デバイスのセットアップクラスを示すGUID。
DevInstDWORD4+20+20デバイスインスタンスを示すハンドル値(devnodeハンドル)。
ReservedUINT_PTR8/4+24+24システム内部利用の予約領域。参照・変更してはならない。

各言語での定義

#include <windows.h>

// SP_DEVINFO_DATA  (x64 32 / x86 28 バイト)
#pragma pack(push, 1)
typedef struct SP_DEVINFO_DATA {
    DWORD cbSize;
    GUID ClassGuid;
    DWORD DevInst;
    UINT_PTR Reserved;
} SP_DEVINFO_DATA;
#pragma pack(pop)
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct SP_DEVINFO_DATA
{
    public uint cbSize;
    public Guid ClassGuid;
    public uint DevInst;
    public UIntPtr Reserved;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure SP_DEVINFO_DATA
    Public cbSize As UInteger
    Public ClassGuid As Guid
    Public DevInst As UInteger
    Public Reserved As UIntPtr
End Structure
import ctypes
from ctypes import wintypes

class SP_DEVINFO_DATA(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ("cbSize", wintypes.DWORD),
        ("ClassGuid", GUID),
        ("DevInst", wintypes.DWORD),
        ("Reserved", ctypes.c_size_t),
    ]
#[repr(C, packed(1))]
pub struct SP_DEVINFO_DATA {
    pub cbSize: u32,
    pub ClassGuid: GUID,
    pub DevInst: u32,
    pub Reserved: usize,
}
import "golang.org/x/sys/windows"

type SP_DEVINFO_DATA struct {
	cbSize uint32
	ClassGuid windows.GUID
	DevInst uint32
	Reserved uintptr
}
type
  SP_DEVINFO_DATA = packed record
    cbSize: DWORD;
    ClassGuid: TGUID;
    DevInst: DWORD;
    Reserved: NativeUInt;
  end;
const SP_DEVINFO_DATA = extern struct {
    cbSize: u32,
    ClassGuid: GUID,
    DevInst: u32,
    Reserved: usize,
};
type
  SP_DEVINFO_DATA {.packed.} = object
    cbSize: uint32
    ClassGuid: GUID
    DevInst: uint32
    Reserved: uint
align(1)
struct SP_DEVINFO_DATA
{
    uint cbSize;
    GUID ClassGuid;
    uint DevInst;
    size_t Reserved;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; SP_DEVINFO_DATA サイズ: 28 バイト(x86)
dim st, 7    ; 4byte整数×7(構造体サイズ 28 / 4 切り上げ)
; cbSize : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; ClassGuid : GUID (+4, 16byte)  varptr(st)+4 を基点に操作(16byte:入れ子/配列)
; DevInst : DWORD (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; Reserved : UINT_PTR (+24, 4byte)  st.6 = 値  /  値 = st.6   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; SP_DEVINFO_DATA サイズ: 32 バイト(x64)
dim st, 8    ; 4byte整数×8(構造体サイズ 32 / 4 切り上げ)
; cbSize : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; ClassGuid : GUID (+4, 16byte)  varptr(st)+4 を基点に操作(16byte:入れ子/配列)
; DevInst : DWORD (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; Reserved : UINT_PTR (+24, 8byte)  qpoke st,24,値 / qpeek(st,24)  ※IronHSPのみ。3.7/3.8は lpoke st,24,下位 : lpoke st,28,上位
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global GUID, pack=1
    #field int Data1
    #field short Data2
    #field short Data3
    #field byte Data4 8
#endstruct

#defstruct global SP_DEVINFO_DATA, pack=1
    #field int cbSize
    #field GUID ClassGuid
    #field int DevInst
    #field intptr Reserved
#endstruct

stdim st, SP_DEVINFO_DATA        ; NSTRUCT 変数を確保
st->cbSize = 100
mes "cbSize=" + st->cbSize