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

BluetoothGATTGetServices

関数
BLEデバイスのGATTサービス一覧を取得する。
DLLBluetoothApis.dll呼出規約winapi対応OSwindows8.0

シグネチャ

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

HRESULT BluetoothGATTGetServices(
    HANDLE hDevice,
    WORD ServicesBufferCount,
    BTH_LE_GATT_SERVICE* ServicesBuffer,   // optional
    WORD* ServicesBufferActual,
    DWORD Flags
);

パラメーター

名前方向
hDeviceHANDLEin
ServicesBufferCountWORDin
ServicesBufferBTH_LE_GATT_SERVICE*outoptional
ServicesBufferActualWORD*out
FlagsDWORDin

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT BluetoothGATTGetServices(
    HANDLE hDevice,
    WORD ServicesBufferCount,
    BTH_LE_GATT_SERVICE* ServicesBuffer,   // optional
    WORD* ServicesBufferActual,
    DWORD Flags
);
[DllImport("BluetoothApis.dll", ExactSpelling = true)]
static extern int BluetoothGATTGetServices(
    IntPtr hDevice,   // HANDLE
    ushort ServicesBufferCount,   // WORD
    IntPtr ServicesBuffer,   // BTH_LE_GATT_SERVICE* optional, out
    out ushort ServicesBufferActual,   // WORD* out
    uint Flags   // DWORD
);
<DllImport("BluetoothApis.dll", ExactSpelling:=True)>
Public Shared Function BluetoothGATTGetServices(
    hDevice As IntPtr,   ' HANDLE
    ServicesBufferCount As UShort,   ' WORD
    ServicesBuffer As IntPtr,   ' BTH_LE_GATT_SERVICE* optional, out
    <Out> ByRef ServicesBufferActual As UShort,   ' WORD* out
    Flags As UInteger   ' DWORD
) As Integer
End Function
' hDevice : HANDLE
' ServicesBufferCount : WORD
' ServicesBuffer : BTH_LE_GATT_SERVICE* optional, out
' ServicesBufferActual : WORD* out
' Flags : DWORD
Declare PtrSafe Function BluetoothGATTGetServices Lib "bluetoothapis" ( _
    ByVal hDevice As LongPtr, _
    ByVal ServicesBufferCount As Integer, _
    ByVal ServicesBuffer As LongPtr, _
    ByRef ServicesBufferActual As Integer, _
    ByVal Flags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

BluetoothGATTGetServices = ctypes.windll.bluetoothapis.BluetoothGATTGetServices
BluetoothGATTGetServices.restype = ctypes.c_int
BluetoothGATTGetServices.argtypes = [
    wintypes.HANDLE,  # hDevice : HANDLE
    ctypes.c_ushort,  # ServicesBufferCount : WORD
    ctypes.c_void_p,  # ServicesBuffer : BTH_LE_GATT_SERVICE* optional, out
    ctypes.POINTER(ctypes.c_ushort),  # ServicesBufferActual : WORD* out
    wintypes.DWORD,  # Flags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('BluetoothApis.dll')
BluetoothGATTGetServices = Fiddle::Function.new(
  lib['BluetoothGATTGetServices'],
  [
    Fiddle::TYPE_VOIDP,  # hDevice : HANDLE
    -Fiddle::TYPE_SHORT,  # ServicesBufferCount : WORD
    Fiddle::TYPE_VOIDP,  # ServicesBuffer : BTH_LE_GATT_SERVICE* optional, out
    Fiddle::TYPE_VOIDP,  # ServicesBufferActual : WORD* out
    -Fiddle::TYPE_INT,  # Flags : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "bluetoothapis")]
extern "system" {
    fn BluetoothGATTGetServices(
        hDevice: *mut core::ffi::c_void,  // HANDLE
        ServicesBufferCount: u16,  // WORD
        ServicesBuffer: *mut BTH_LE_GATT_SERVICE,  // BTH_LE_GATT_SERVICE* optional, out
        ServicesBufferActual: *mut u16,  // WORD* out
        Flags: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("BluetoothApis.dll")]
public static extern int BluetoothGATTGetServices(IntPtr hDevice, ushort ServicesBufferCount, IntPtr ServicesBuffer, out ushort ServicesBufferActual, uint Flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'BluetoothApis_BluetoothGATTGetServices' -Namespace Win32 -PassThru
# $api::BluetoothGATTGetServices(hDevice, ServicesBufferCount, ServicesBuffer, ServicesBufferActual, Flags)
#uselib "BluetoothApis.dll"
#func global BluetoothGATTGetServices "BluetoothGATTGetServices" sptr, sptr, sptr, sptr, sptr
; BluetoothGATTGetServices hDevice, ServicesBufferCount, varptr(ServicesBuffer), varptr(ServicesBufferActual), Flags   ; 戻り値は stat
; hDevice : HANDLE -> "sptr"
; ServicesBufferCount : WORD -> "sptr"
; ServicesBuffer : BTH_LE_GATT_SERVICE* optional, out -> "sptr"
; ServicesBufferActual : WORD* out -> "sptr"
; Flags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "BluetoothApis.dll"
#cfunc global BluetoothGATTGetServices "BluetoothGATTGetServices" sptr, int, var, var, int
; res = BluetoothGATTGetServices(hDevice, ServicesBufferCount, ServicesBuffer, ServicesBufferActual, Flags)
; hDevice : HANDLE -> "sptr"
; ServicesBufferCount : WORD -> "int"
; ServicesBuffer : BTH_LE_GATT_SERVICE* optional, out -> "var"
; ServicesBufferActual : WORD* out -> "var"
; Flags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT BluetoothGATTGetServices(HANDLE hDevice, WORD ServicesBufferCount, BTH_LE_GATT_SERVICE* ServicesBuffer, WORD* ServicesBufferActual, DWORD Flags)
#uselib "BluetoothApis.dll"
#cfunc global BluetoothGATTGetServices "BluetoothGATTGetServices" intptr, int, var, var, int
; res = BluetoothGATTGetServices(hDevice, ServicesBufferCount, ServicesBuffer, ServicesBufferActual, Flags)
; hDevice : HANDLE -> "intptr"
; ServicesBufferCount : WORD -> "int"
; ServicesBuffer : BTH_LE_GATT_SERVICE* optional, out -> "var"
; ServicesBufferActual : WORD* out -> "var"
; Flags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	bluetoothapis = windows.NewLazySystemDLL("BluetoothApis.dll")
	procBluetoothGATTGetServices = bluetoothapis.NewProc("BluetoothGATTGetServices")
)

// hDevice (HANDLE), ServicesBufferCount (WORD), ServicesBuffer (BTH_LE_GATT_SERVICE* optional, out), ServicesBufferActual (WORD* out), Flags (DWORD)
r1, _, err := procBluetoothGATTGetServices.Call(
	uintptr(hDevice),
	uintptr(ServicesBufferCount),
	uintptr(ServicesBuffer),
	uintptr(ServicesBufferActual),
	uintptr(Flags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function BluetoothGATTGetServices(
  hDevice: THandle;   // HANDLE
  ServicesBufferCount: Word;   // WORD
  ServicesBuffer: Pointer;   // BTH_LE_GATT_SERVICE* optional, out
  ServicesBufferActual: Pointer;   // WORD* out
  Flags: DWORD   // DWORD
): Integer; stdcall;
  external 'BluetoothApis.dll' name 'BluetoothGATTGetServices';
result := DllCall("BluetoothApis\BluetoothGATTGetServices"
    , "Ptr", hDevice   ; HANDLE
    , "UShort", ServicesBufferCount   ; WORD
    , "Ptr", ServicesBuffer   ; BTH_LE_GATT_SERVICE* optional, out
    , "Ptr", ServicesBufferActual   ; WORD* out
    , "UInt", Flags   ; DWORD
    , "Int")   ; return: HRESULT
●BluetoothGATTGetServices(hDevice, ServicesBufferCount, ServicesBuffer, ServicesBufferActual, Flags) = DLL("BluetoothApis.dll", "int BluetoothGATTGetServices(void*, int, void*, void*, dword)")
# 呼び出し: BluetoothGATTGetServices(hDevice, ServicesBufferCount, ServicesBuffer, ServicesBufferActual, Flags)
# hDevice : HANDLE -> "void*"
# ServicesBufferCount : WORD -> "int"
# ServicesBuffer : BTH_LE_GATT_SERVICE* optional, out -> "void*"
# ServicesBufferActual : WORD* out -> "void*"
# Flags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。