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

BLUETOOTH_DEVICE_INFO

構造体
サイズx64: 560 バイト / x86: 560 バイト

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

フィールド

フィールドサイズx64x86説明
dwSizeDWORD4+0+0この構造体のバイト単位サイズ。呼び出し前に設定する必要がある。
AddressBLUETOOTH_ADDRESS8+8+8リモートデバイスのBluetoothアドレス。
ulClassofDeviceDWORD4+16+16リモートデバイスのClass of Device値。機器種別を示す。
fConnectedBOOL4+20+20デバイスが現在接続中かを示すBOOL値。TRUEで接続。
fRememberedBOOL4+24+24デバイスが記憶済み(ペアリング履歴あり)かを示すBOOL値。
fAuthenticatedBOOL4+28+28デバイスが認証済みかを示すBOOL値。TRUEで認証完了。
stLastSeenSYSTEMTIME16+32+32デバイスを最後に検出した日時を示すSYSTEMTIME(UTC)。
stLastUsedSYSTEMTIME16+48+48デバイスを最後に使用した日時を示すSYSTEMTIME(UTC)。
szNameWCHAR496+64+64デバイスのフレンドリ名を保持するワイド文字配列。

各言語での定義

#include <windows.h>

// BLUETOOTH_ADDRESS  (x64 8 / x86 8 バイト)
typedef struct BLUETOOTH_ADDRESS {
    _Anonymous_e__Union Anonymous;
} BLUETOOTH_ADDRESS;

// SYSTEMTIME  (x64 16 / x86 16 バイト)
typedef struct SYSTEMTIME {
    WORD wYear;
    WORD wMonth;
    WORD wDayOfWeek;
    WORD wDay;
    WORD wHour;
    WORD wMinute;
    WORD wSecond;
    WORD wMilliseconds;
} SYSTEMTIME;

// BLUETOOTH_DEVICE_INFO  (x64 560 / x86 560 バイト)
typedef struct BLUETOOTH_DEVICE_INFO {
    DWORD dwSize;
    BLUETOOTH_ADDRESS Address;
    DWORD ulClassofDevice;
    BOOL fConnected;
    BOOL fRemembered;
    BOOL fAuthenticated;
    SYSTEMTIME stLastSeen;
    SYSTEMTIME stLastUsed;
    WCHAR szName[248];
} BLUETOOTH_DEVICE_INFO;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct BLUETOOTH_ADDRESS
{
    public _Anonymous_e__Union Anonymous;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SYSTEMTIME
{
    public ushort wYear;
    public ushort wMonth;
    public ushort wDayOfWeek;
    public ushort wDay;
    public ushort wHour;
    public ushort wMinute;
    public ushort wSecond;
    public ushort wMilliseconds;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct BLUETOOTH_DEVICE_INFO
{
    public uint dwSize;
    public BLUETOOTH_ADDRESS Address;
    public uint ulClassofDevice;
    [MarshalAs(UnmanagedType.Bool)] public bool fConnected;
    [MarshalAs(UnmanagedType.Bool)] public bool fRemembered;
    [MarshalAs(UnmanagedType.Bool)] public bool fAuthenticated;
    public SYSTEMTIME stLastSeen;
    public SYSTEMTIME stLastUsed;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 248)] public string szName;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure BLUETOOTH_ADDRESS
    Public Anonymous As _Anonymous_e__Union
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure SYSTEMTIME
    Public wYear As UShort
    Public wMonth As UShort
    Public wDayOfWeek As UShort
    Public wDay As UShort
    Public wHour As UShort
    Public wMinute As UShort
    Public wSecond As UShort
    Public wMilliseconds As UShort
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure BLUETOOTH_DEVICE_INFO
    Public dwSize As UInteger
    Public Address As BLUETOOTH_ADDRESS
    Public ulClassofDevice As UInteger
    <MarshalAs(UnmanagedType.Bool)> Public fConnected As Boolean
    <MarshalAs(UnmanagedType.Bool)> Public fRemembered As Boolean
    <MarshalAs(UnmanagedType.Bool)> Public fAuthenticated As Boolean
    Public stLastSeen As SYSTEMTIME
    Public stLastUsed As SYSTEMTIME
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=248)> Public szName As String
End Structure
import ctypes
from ctypes import wintypes

class BLUETOOTH_ADDRESS(ctypes.Structure):
    _fields_ = [
        ("Anonymous", _Anonymous_e__Union),
    ]

class SYSTEMTIME(ctypes.Structure):
    _fields_ = [
        ("wYear", ctypes.c_ushort),
        ("wMonth", ctypes.c_ushort),
        ("wDayOfWeek", ctypes.c_ushort),
        ("wDay", ctypes.c_ushort),
        ("wHour", ctypes.c_ushort),
        ("wMinute", ctypes.c_ushort),
        ("wSecond", ctypes.c_ushort),
        ("wMilliseconds", ctypes.c_ushort),
    ]

class BLUETOOTH_DEVICE_INFO(ctypes.Structure):
    _fields_ = [
        ("dwSize", wintypes.DWORD),
        ("Address", BLUETOOTH_ADDRESS),
        ("ulClassofDevice", wintypes.DWORD),
        ("fConnected", wintypes.BOOL),
        ("fRemembered", wintypes.BOOL),
        ("fAuthenticated", wintypes.BOOL),
        ("stLastSeen", SYSTEMTIME),
        ("stLastUsed", SYSTEMTIME),
        ("szName", ctypes.c_wchar * 248),
    ]
#[repr(C)]
pub struct BLUETOOTH_ADDRESS {
    pub Anonymous: _Anonymous_e__Union,
}

#[repr(C)]
pub struct SYSTEMTIME {
    pub wYear: u16,
    pub wMonth: u16,
    pub wDayOfWeek: u16,
    pub wDay: u16,
    pub wHour: u16,
    pub wMinute: u16,
    pub wSecond: u16,
    pub wMilliseconds: u16,
}

#[repr(C)]
pub struct BLUETOOTH_DEVICE_INFO {
    pub dwSize: u32,
    pub Address: BLUETOOTH_ADDRESS,
    pub ulClassofDevice: u32,
    pub fConnected: i32,
    pub fRemembered: i32,
    pub fAuthenticated: i32,
    pub stLastSeen: SYSTEMTIME,
    pub stLastUsed: SYSTEMTIME,
    pub szName: [u16; 248],
}
import "golang.org/x/sys/windows"

type BLUETOOTH_ADDRESS struct {
	Anonymous _Anonymous_e__Union
}

type SYSTEMTIME struct {
	wYear uint16
	wMonth uint16
	wDayOfWeek uint16
	wDay uint16
	wHour uint16
	wMinute uint16
	wSecond uint16
	wMilliseconds uint16
}

type BLUETOOTH_DEVICE_INFO struct {
	dwSize uint32
	Address BLUETOOTH_ADDRESS
	ulClassofDevice uint32
	fConnected int32
	fRemembered int32
	fAuthenticated int32
	stLastSeen SYSTEMTIME
	stLastUsed SYSTEMTIME
	szName [248]uint16
}
type
  BLUETOOTH_ADDRESS = record
    Anonymous: _Anonymous_e__Union;
  end;

  SYSTEMTIME = record
    wYear: Word;
    wMonth: Word;
    wDayOfWeek: Word;
    wDay: Word;
    wHour: Word;
    wMinute: Word;
    wSecond: Word;
    wMilliseconds: Word;
  end;

  BLUETOOTH_DEVICE_INFO = record
    dwSize: DWORD;
    Address: BLUETOOTH_ADDRESS;
    ulClassofDevice: DWORD;
    fConnected: BOOL;
    fRemembered: BOOL;
    fAuthenticated: BOOL;
    stLastSeen: SYSTEMTIME;
    stLastUsed: SYSTEMTIME;
    szName: array[0..247] of WideChar;
  end;
const BLUETOOTH_ADDRESS = extern struct {
    Anonymous: _Anonymous_e__Union,
};

const SYSTEMTIME = extern struct {
    wYear: u16,
    wMonth: u16,
    wDayOfWeek: u16,
    wDay: u16,
    wHour: u16,
    wMinute: u16,
    wSecond: u16,
    wMilliseconds: u16,
};

const BLUETOOTH_DEVICE_INFO = extern struct {
    dwSize: u32,
    Address: BLUETOOTH_ADDRESS,
    ulClassofDevice: u32,
    fConnected: i32,
    fRemembered: i32,
    fAuthenticated: i32,
    stLastSeen: SYSTEMTIME,
    stLastUsed: SYSTEMTIME,
    szName: [248]u16,
};
type
  BLUETOOTH_ADDRESS {.bycopy.} = object
    Anonymous: _Anonymous_e__Union

  SYSTEMTIME {.bycopy.} = object
    wYear: uint16
    wMonth: uint16
    wDayOfWeek: uint16
    wDay: uint16
    wHour: uint16
    wMinute: uint16
    wSecond: uint16
    wMilliseconds: uint16

  BLUETOOTH_DEVICE_INFO {.bycopy.} = object
    dwSize: uint32
    Address: BLUETOOTH_ADDRESS
    ulClassofDevice: uint32
    fConnected: int32
    fRemembered: int32
    fAuthenticated: int32
    stLastSeen: SYSTEMTIME
    stLastUsed: SYSTEMTIME
    szName: array[248, uint16]
struct BLUETOOTH_ADDRESS
{
    _Anonymous_e__Union Anonymous;
}

struct SYSTEMTIME
{
    ushort wYear;
    ushort wMonth;
    ushort wDayOfWeek;
    ushort wDay;
    ushort wHour;
    ushort wMinute;
    ushort wSecond;
    ushort wMilliseconds;
}

struct BLUETOOTH_DEVICE_INFO
{
    uint dwSize;
    BLUETOOTH_ADDRESS Address;
    uint ulClassofDevice;
    int fConnected;
    int fRemembered;
    int fAuthenticated;
    SYSTEMTIME stLastSeen;
    SYSTEMTIME stLastUsed;
    wchar[248] szName;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; BLUETOOTH_DEVICE_INFO サイズ: 560 バイト(x64)
dim st, 140    ; 4byte整数×140(構造体サイズ 560 / 4 切り上げ)
; dwSize : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; Address : BLUETOOTH_ADDRESS (+8, 8byte)  varptr(st)+8 を基点に操作(8byte:入れ子/配列)
; ulClassofDevice : DWORD (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; fConnected : BOOL (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; fRemembered : BOOL (+24, 4byte)  st.6 = 値  /  値 = st.6   (lpoke/lpeek も可)
; fAuthenticated : BOOL (+28, 4byte)  st.7 = 値  /  値 = st.7   (lpoke/lpeek も可)
; stLastSeen : SYSTEMTIME (+32, 16byte)  varptr(st)+32 を基点に操作(16byte:入れ子/配列)
; stLastUsed : SYSTEMTIME (+48, 16byte)  varptr(st)+48 を基点に操作(16byte:入れ子/配列)
; szName : WCHAR (+64, 496byte)  varptr(st)+64 を基点に操作(496byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global BLUETOOTH_ADDRESS
    #field byte Anonymous 8
#endstruct

#defstruct global SYSTEMTIME
    #field short wYear
    #field short wMonth
    #field short wDayOfWeek
    #field short wDay
    #field short wHour
    #field short wMinute
    #field short wSecond
    #field short wMilliseconds
#endstruct

#defstruct global BLUETOOTH_DEVICE_INFO
    #field int dwSize
    #field BLUETOOTH_ADDRESS Address
    #field int ulClassofDevice
    #field bool fConnected
    #field bool fRemembered
    #field bool fAuthenticated
    #field SYSTEMTIME stLastSeen
    #field SYSTEMTIME stLastUsed
    #field wchar szName 248
#endstruct

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