BluetoothGATTGetDescriptorValue
関数シグネチャ
// BluetoothApis.dll
#include <windows.h>
HRESULT BluetoothGATTGetDescriptorValue(
HANDLE hDevice,
BTH_LE_GATT_DESCRIPTOR* Descriptor,
DWORD DescriptorValueDataSize,
BTH_LE_GATT_DESCRIPTOR_VALUE* DescriptorValue, // optional
WORD* DescriptorValueSizeRequired, // optional
DWORD Flags
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hDevice | HANDLE | in | サービスへのハンドル。 | ||||||||||||
| Descriptor | BTH_LE_GATT_DESCRIPTOR* | in | 取得するディスクリプター値の親ディスクリプターを格納した BTH_LE_GATT_DESCRIPTOR 構造体へのポインター。 | ||||||||||||
| DescriptorValueDataSize | DWORD | in | DescriptorValue パラメーターに割り当てられているバイト数。 | ||||||||||||
| DescriptorValue | BTH_LE_GATT_DESCRIPTOR_VALUE* | outoptional | ディスクリプター値を返す先の BTH_LE_GATT_DESCRIPTOR_VALUE 構造体へのポインター。 | ||||||||||||
| DescriptorValueSizeRequired | WORD* | outoptional | DescriptorValue が指すバッファーにデータを返すために追加で必要となるバイト数を格納する先のバッファーへのポインター。 | ||||||||||||
| Flags | DWORD | in | BluetoothGATTGetDescriptorValue の動作を変更するフラグ:
|
戻り値の型: HRESULT
公式ドキュメント
指定されたディスクリプターの値を取得します。
戻り値
BluetoothGATTGetDescriptorValue 関数は、次の値を返します:
| 戻り値 | 説明 |
|---|---|
| 操作は正常に完了しました。 | |
| バッファーパラメーターが NULL であるため、代わりに利用可能な項目数が返されます。 | |
| 親サービスとサービスハンドルの両方が指定されており、サービス階層が指定された親サービスハンドルに帰結しない場合に返されます。 | |
| DescriptorValue と DescriptorValueSizeRequired の両方が 0 です。 | |
| バッファーが指定されていますが、バッファーのサイズ (バイト単位) が必要な値より小さいです。 | |
| キャッシュから取得するようディスクリプター値が指定されましたが、そのディスクリプター値はキャッシュに存在しません。 | |
| キャッシュ内の現在のデータに不整合があると思われ、内部エラーの原因となっています。 | |
| 対象のサーバーが適切なネットワーク応答を返しませんでした。 | |
| 要求がタイムアウトしました。 | |
| 操作中にメモリが不足しました。 | |
| 指定された属性ハンドルは、このサーバーでは有効ではありませんでした。 | |
| 属性を読み取ることができません。 | |
| 属性に書き込むことができません。 | |
| 属性 PDU が無効でした。 | |
| この属性の読み取りまたは書き込みには認証が必要です。 | |
| 属性サーバーは、クライアントから受信した要求をサポートしていません。 | |
| 指定されたオフセットが属性の末尾を超えています。 | |
| この属性の読み取りまたは書き込みには承認が必要です。 | |
| キューに入れられた prepare write が多すぎます。 | |
| 指定された属性ハンドルの範囲内に属性が見つかりませんでした。 | |
| この属性は Read Blob Request を使用して読み取りまたは書き込みすることはできません。 | |
| このリンクの暗号化に使用されている暗号化キーのサイズが不足しています。 | |
| この操作に対して属性値の長さが無効です。 | |
| 要求された属性要求で、通常は発生しないエラーが発生したため、要求どおりに完了できませんでした。 | |
| この属性の読み取りまたは書き込みには暗号化が必要です。 | |
| 属性の型が、上位層の仕様で定義されたサポート対象のグループ化属性ではありません。 | |
| 要求を完了するためのリソースが不足しています。 | |
| 予約済みの範囲に含まれるエラーを受信しました。 |
解説(Remarks)
ディスクリプター値は、キャッシュに既に存在する場合はキャッシュから返されます。デバイスの属性はペアリングまたは関連付けの時点ですべてキャッシュされるため、ほとんどの場合はこれに該当します。ただし、キャッシュに存在しない場合、ディスクリプター値はデバイスから直接読み取られ、デバイスからの読み取りに成功した時点でキャッシュされます。BLUETOOTH_GATT_FLAG_FORCE_READ_FROM_CACHE または BLUETOOTH_GATT_FLAG_FORCE_READ_FROM_DEVICE が指定されている場合、ディスクリプター値は指定された方法で読み取られます。
返されたディスクリプター値は、デバイスから直接ディスクリプター値を取得できた場合にキャッシュされます。サービス変更イベントを受信しない限り、ディスクリプター値は変化しないものと想定されます。
プロファイルドライバーは、返されるディスクリプター値の配列を格納するのに十分な大きさのバッファーをあらかじめ割り当てる必要があります。呼び出し元は、DescriptorValueSizeRequired に NULL 以外の値を、DescriptorValue に NULL を渡すことで、必要なバッファーサイズを判断できます。
親サービスはキャッシュに存在している必要があり、存在しない場合、この関数は失敗します。親サービスは、BluetoothGATTGetServices または BluetoothGATTGetIncludedServices によって返されたサービスである必要があります。
例
////////////////////////////////////////////////////////////////////////////
// Determine Descriptor Value Buffer Size
////////////////////////////////////////////////////////////////////////////
hr = BluetoothGATTGetDescriptorValue(
hCurrService,
currGattDescriptor,
0,
NULL,
&descValueDataSize,
BLUETOOTH_GATT_FLAG_NONE);
if (HRESULT_FROM_WIN32(ERROR_MORE_DATA) != hr) {
PrintHr("BluetoothGATTGetDescriptorValue - Buffer Size", hr);
goto Done; // allow continuation
}
pDescValueBuffer = (PBTH_LE_GATT_DESCRIPTOR_VALUE)malloc(descValueDataSize);
if (NULL == pDescValueBuffer) {
printf("pDescValueBuffer out of memory\r\n");
goto Done;
} else {
RtlZeroMemory(pDescValueBuffer, descValueDataSize);
}
////////////////////////////////////////////////////////////////////////////
// Retrieve the Descriptor Value
////////////////////////////////////////////////////////////////////////////
hr = BluetoothGATTGetDescriptorValue(
hCurrService,
currGattDescriptor,
(ULONG)descValueDataSize,
pDescValueBuffer,
NULL,
BLUETOOTH_GATT_FLAG_NONE);
if (S_OK != hr) {
PrintHr("BluetoothGATTGetDescriptorValue - Actual Data", hr);
goto Done; // allow continuation
}
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// BluetoothApis.dll
#include <windows.h>
HRESULT BluetoothGATTGetDescriptorValue(
HANDLE hDevice,
BTH_LE_GATT_DESCRIPTOR* Descriptor,
DWORD DescriptorValueDataSize,
BTH_LE_GATT_DESCRIPTOR_VALUE* DescriptorValue, // optional
WORD* DescriptorValueSizeRequired, // optional
DWORD Flags
);[DllImport("BluetoothApis.dll", ExactSpelling = true)]
static extern int BluetoothGATTGetDescriptorValue(
IntPtr hDevice, // HANDLE
IntPtr Descriptor, // BTH_LE_GATT_DESCRIPTOR*
uint DescriptorValueDataSize, // DWORD
IntPtr DescriptorValue, // BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out
IntPtr DescriptorValueSizeRequired, // WORD* optional, out
uint Flags // DWORD
);<DllImport("BluetoothApis.dll", ExactSpelling:=True)>
Public Shared Function BluetoothGATTGetDescriptorValue(
hDevice As IntPtr, ' HANDLE
Descriptor As IntPtr, ' BTH_LE_GATT_DESCRIPTOR*
DescriptorValueDataSize As UInteger, ' DWORD
DescriptorValue As IntPtr, ' BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out
DescriptorValueSizeRequired As IntPtr, ' WORD* optional, out
Flags As UInteger ' DWORD
) As Integer
End Function' hDevice : HANDLE
' Descriptor : BTH_LE_GATT_DESCRIPTOR*
' DescriptorValueDataSize : DWORD
' DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out
' DescriptorValueSizeRequired : WORD* optional, out
' Flags : DWORD
Declare PtrSafe Function BluetoothGATTGetDescriptorValue Lib "bluetoothapis" ( _
ByVal hDevice As LongPtr, _
ByVal Descriptor As LongPtr, _
ByVal DescriptorValueDataSize As Long, _
ByVal DescriptorValue As LongPtr, _
ByVal DescriptorValueSizeRequired As LongPtr, _
ByVal Flags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
BluetoothGATTGetDescriptorValue = ctypes.windll.bluetoothapis.BluetoothGATTGetDescriptorValue
BluetoothGATTGetDescriptorValue.restype = ctypes.c_int
BluetoothGATTGetDescriptorValue.argtypes = [
wintypes.HANDLE, # hDevice : HANDLE
ctypes.c_void_p, # Descriptor : BTH_LE_GATT_DESCRIPTOR*
wintypes.DWORD, # DescriptorValueDataSize : DWORD
ctypes.c_void_p, # DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out
ctypes.POINTER(ctypes.c_ushort), # DescriptorValueSizeRequired : WORD* optional, out
wintypes.DWORD, # Flags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('BluetoothApis.dll')
BluetoothGATTGetDescriptorValue = Fiddle::Function.new(
lib['BluetoothGATTGetDescriptorValue'],
[
Fiddle::TYPE_VOIDP, # hDevice : HANDLE
Fiddle::TYPE_VOIDP, # Descriptor : BTH_LE_GATT_DESCRIPTOR*
-Fiddle::TYPE_INT, # DescriptorValueDataSize : DWORD
Fiddle::TYPE_VOIDP, # DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out
Fiddle::TYPE_VOIDP, # DescriptorValueSizeRequired : WORD* optional, out
-Fiddle::TYPE_INT, # Flags : DWORD
],
Fiddle::TYPE_INT)#[link(name = "bluetoothapis")]
extern "system" {
fn BluetoothGATTGetDescriptorValue(
hDevice: *mut core::ffi::c_void, // HANDLE
Descriptor: *mut BTH_LE_GATT_DESCRIPTOR, // BTH_LE_GATT_DESCRIPTOR*
DescriptorValueDataSize: u32, // DWORD
DescriptorValue: *mut BTH_LE_GATT_DESCRIPTOR_VALUE, // BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out
DescriptorValueSizeRequired: *mut u16, // WORD* optional, out
Flags: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("BluetoothApis.dll")]
public static extern int BluetoothGATTGetDescriptorValue(IntPtr hDevice, IntPtr Descriptor, uint DescriptorValueDataSize, IntPtr DescriptorValue, IntPtr DescriptorValueSizeRequired, uint Flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'BluetoothApis_BluetoothGATTGetDescriptorValue' -Namespace Win32 -PassThru
# $api::BluetoothGATTGetDescriptorValue(hDevice, Descriptor, DescriptorValueDataSize, DescriptorValue, DescriptorValueSizeRequired, Flags)#uselib "BluetoothApis.dll"
#func global BluetoothGATTGetDescriptorValue "BluetoothGATTGetDescriptorValue" sptr, sptr, sptr, sptr, sptr, sptr
; BluetoothGATTGetDescriptorValue hDevice, varptr(Descriptor), DescriptorValueDataSize, varptr(DescriptorValue), varptr(DescriptorValueSizeRequired), Flags ; 戻り値は stat
; hDevice : HANDLE -> "sptr"
; Descriptor : BTH_LE_GATT_DESCRIPTOR* -> "sptr"
; DescriptorValueDataSize : DWORD -> "sptr"
; DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out -> "sptr"
; DescriptorValueSizeRequired : WORD* optional, out -> "sptr"
; Flags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "BluetoothApis.dll" #cfunc global BluetoothGATTGetDescriptorValue "BluetoothGATTGetDescriptorValue" sptr, var, int, var, var, int ; res = BluetoothGATTGetDescriptorValue(hDevice, Descriptor, DescriptorValueDataSize, DescriptorValue, DescriptorValueSizeRequired, Flags) ; hDevice : HANDLE -> "sptr" ; Descriptor : BTH_LE_GATT_DESCRIPTOR* -> "var" ; DescriptorValueDataSize : DWORD -> "int" ; DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out -> "var" ; DescriptorValueSizeRequired : WORD* optional, out -> "var" ; Flags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "BluetoothApis.dll" #cfunc global BluetoothGATTGetDescriptorValue "BluetoothGATTGetDescriptorValue" sptr, sptr, int, sptr, sptr, int ; res = BluetoothGATTGetDescriptorValue(hDevice, varptr(Descriptor), DescriptorValueDataSize, varptr(DescriptorValue), varptr(DescriptorValueSizeRequired), Flags) ; hDevice : HANDLE -> "sptr" ; Descriptor : BTH_LE_GATT_DESCRIPTOR* -> "sptr" ; DescriptorValueDataSize : DWORD -> "int" ; DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out -> "sptr" ; DescriptorValueSizeRequired : WORD* optional, out -> "sptr" ; Flags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; HRESULT BluetoothGATTGetDescriptorValue(HANDLE hDevice, BTH_LE_GATT_DESCRIPTOR* Descriptor, DWORD DescriptorValueDataSize, BTH_LE_GATT_DESCRIPTOR_VALUE* DescriptorValue, WORD* DescriptorValueSizeRequired, DWORD Flags) #uselib "BluetoothApis.dll" #cfunc global BluetoothGATTGetDescriptorValue "BluetoothGATTGetDescriptorValue" intptr, var, int, var, var, int ; res = BluetoothGATTGetDescriptorValue(hDevice, Descriptor, DescriptorValueDataSize, DescriptorValue, DescriptorValueSizeRequired, Flags) ; hDevice : HANDLE -> "intptr" ; Descriptor : BTH_LE_GATT_DESCRIPTOR* -> "var" ; DescriptorValueDataSize : DWORD -> "int" ; DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out -> "var" ; DescriptorValueSizeRequired : WORD* optional, out -> "var" ; Flags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT BluetoothGATTGetDescriptorValue(HANDLE hDevice, BTH_LE_GATT_DESCRIPTOR* Descriptor, DWORD DescriptorValueDataSize, BTH_LE_GATT_DESCRIPTOR_VALUE* DescriptorValue, WORD* DescriptorValueSizeRequired, DWORD Flags) #uselib "BluetoothApis.dll" #cfunc global BluetoothGATTGetDescriptorValue "BluetoothGATTGetDescriptorValue" intptr, intptr, int, intptr, intptr, int ; res = BluetoothGATTGetDescriptorValue(hDevice, varptr(Descriptor), DescriptorValueDataSize, varptr(DescriptorValue), varptr(DescriptorValueSizeRequired), Flags) ; hDevice : HANDLE -> "intptr" ; Descriptor : BTH_LE_GATT_DESCRIPTOR* -> "intptr" ; DescriptorValueDataSize : DWORD -> "int" ; DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out -> "intptr" ; DescriptorValueSizeRequired : WORD* optional, out -> "intptr" ; Flags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
bluetoothapis = windows.NewLazySystemDLL("BluetoothApis.dll")
procBluetoothGATTGetDescriptorValue = bluetoothapis.NewProc("BluetoothGATTGetDescriptorValue")
)
// hDevice (HANDLE), Descriptor (BTH_LE_GATT_DESCRIPTOR*), DescriptorValueDataSize (DWORD), DescriptorValue (BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out), DescriptorValueSizeRequired (WORD* optional, out), Flags (DWORD)
r1, _, err := procBluetoothGATTGetDescriptorValue.Call(
uintptr(hDevice),
uintptr(Descriptor),
uintptr(DescriptorValueDataSize),
uintptr(DescriptorValue),
uintptr(DescriptorValueSizeRequired),
uintptr(Flags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction BluetoothGATTGetDescriptorValue(
hDevice: THandle; // HANDLE
Descriptor: Pointer; // BTH_LE_GATT_DESCRIPTOR*
DescriptorValueDataSize: DWORD; // DWORD
DescriptorValue: Pointer; // BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out
DescriptorValueSizeRequired: Pointer; // WORD* optional, out
Flags: DWORD // DWORD
): Integer; stdcall;
external 'BluetoothApis.dll' name 'BluetoothGATTGetDescriptorValue';result := DllCall("BluetoothApis\BluetoothGATTGetDescriptorValue"
, "Ptr", hDevice ; HANDLE
, "Ptr", Descriptor ; BTH_LE_GATT_DESCRIPTOR*
, "UInt", DescriptorValueDataSize ; DWORD
, "Ptr", DescriptorValue ; BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out
, "Ptr", DescriptorValueSizeRequired ; WORD* optional, out
, "UInt", Flags ; DWORD
, "Int") ; return: HRESULT●BluetoothGATTGetDescriptorValue(hDevice, Descriptor, DescriptorValueDataSize, DescriptorValue, DescriptorValueSizeRequired, Flags) = DLL("BluetoothApis.dll", "int BluetoothGATTGetDescriptorValue(void*, void*, dword, void*, void*, dword)")
# 呼び出し: BluetoothGATTGetDescriptorValue(hDevice, Descriptor, DescriptorValueDataSize, DescriptorValue, DescriptorValueSizeRequired, Flags)
# hDevice : HANDLE -> "void*"
# Descriptor : BTH_LE_GATT_DESCRIPTOR* -> "void*"
# DescriptorValueDataSize : DWORD -> "dword"
# DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out -> "void*"
# DescriptorValueSizeRequired : WORD* optional, out -> "void*"
# Flags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "bluetoothapis" fn BluetoothGATTGetDescriptorValue(
hDevice: ?*anyopaque, // HANDLE
Descriptor: [*c]BTH_LE_GATT_DESCRIPTOR, // BTH_LE_GATT_DESCRIPTOR*
DescriptorValueDataSize: u32, // DWORD
DescriptorValue: [*c]BTH_LE_GATT_DESCRIPTOR_VALUE, // BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out
DescriptorValueSizeRequired: [*c]u16, // WORD* optional, out
Flags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc BluetoothGATTGetDescriptorValue(
hDevice: pointer, # HANDLE
Descriptor: ptr BTH_LE_GATT_DESCRIPTOR, # BTH_LE_GATT_DESCRIPTOR*
DescriptorValueDataSize: uint32, # DWORD
DescriptorValue: ptr BTH_LE_GATT_DESCRIPTOR_VALUE, # BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out
DescriptorValueSizeRequired: ptr uint16, # WORD* optional, out
Flags: uint32 # DWORD
): int32 {.importc: "BluetoothGATTGetDescriptorValue", stdcall, dynlib: "BluetoothApis.dll".}pragma(lib, "bluetoothapis");
extern(Windows)
int BluetoothGATTGetDescriptorValue(
void* hDevice, // HANDLE
BTH_LE_GATT_DESCRIPTOR* Descriptor, // BTH_LE_GATT_DESCRIPTOR*
uint DescriptorValueDataSize, // DWORD
BTH_LE_GATT_DESCRIPTOR_VALUE* DescriptorValue, // BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out
ushort* DescriptorValueSizeRequired, // WORD* optional, out
uint Flags // DWORD
);ccall((:BluetoothGATTGetDescriptorValue, "BluetoothApis.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{BTH_LE_GATT_DESCRIPTOR}, UInt32, Ptr{BTH_LE_GATT_DESCRIPTOR_VALUE}, Ptr{UInt16}, UInt32),
hDevice, Descriptor, DescriptorValueDataSize, DescriptorValue, DescriptorValueSizeRequired, Flags)
# hDevice : HANDLE -> Ptr{Cvoid}
# Descriptor : BTH_LE_GATT_DESCRIPTOR* -> Ptr{BTH_LE_GATT_DESCRIPTOR}
# DescriptorValueDataSize : DWORD -> UInt32
# DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out -> Ptr{BTH_LE_GATT_DESCRIPTOR_VALUE}
# DescriptorValueSizeRequired : WORD* optional, out -> Ptr{UInt16}
# Flags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t BluetoothGATTGetDescriptorValue(
void* hDevice,
void* Descriptor,
uint32_t DescriptorValueDataSize,
void* DescriptorValue,
uint16_t* DescriptorValueSizeRequired,
uint32_t Flags);
]]
local bluetoothapis = ffi.load("bluetoothapis")
-- bluetoothapis.BluetoothGATTGetDescriptorValue(hDevice, Descriptor, DescriptorValueDataSize, DescriptorValue, DescriptorValueSizeRequired, Flags)
-- hDevice : HANDLE
-- Descriptor : BTH_LE_GATT_DESCRIPTOR*
-- DescriptorValueDataSize : DWORD
-- DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out
-- DescriptorValueSizeRequired : WORD* optional, out
-- Flags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('BluetoothApis.dll');
const BluetoothGATTGetDescriptorValue = lib.func('__stdcall', 'BluetoothGATTGetDescriptorValue', 'int32_t', ['void *', 'void *', 'uint32_t', 'void *', 'uint16_t *', 'uint32_t']);
// BluetoothGATTGetDescriptorValue(hDevice, Descriptor, DescriptorValueDataSize, DescriptorValue, DescriptorValueSizeRequired, Flags)
// hDevice : HANDLE -> 'void *'
// Descriptor : BTH_LE_GATT_DESCRIPTOR* -> 'void *'
// DescriptorValueDataSize : DWORD -> 'uint32_t'
// DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out -> 'void *'
// DescriptorValueSizeRequired : WORD* optional, out -> 'uint16_t *'
// Flags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("BluetoothApis.dll", {
BluetoothGATTGetDescriptorValue: { parameters: ["pointer", "pointer", "u32", "pointer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.BluetoothGATTGetDescriptorValue(hDevice, Descriptor, DescriptorValueDataSize, DescriptorValue, DescriptorValueSizeRequired, Flags)
// hDevice : HANDLE -> "pointer"
// Descriptor : BTH_LE_GATT_DESCRIPTOR* -> "pointer"
// DescriptorValueDataSize : DWORD -> "u32"
// DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out -> "pointer"
// DescriptorValueSizeRequired : WORD* optional, out -> "pointer"
// Flags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t BluetoothGATTGetDescriptorValue(
void* hDevice,
void* Descriptor,
uint32_t DescriptorValueDataSize,
void* DescriptorValue,
uint16_t* DescriptorValueSizeRequired,
uint32_t Flags);
C, "BluetoothApis.dll");
// $ffi->BluetoothGATTGetDescriptorValue(hDevice, Descriptor, DescriptorValueDataSize, DescriptorValue, DescriptorValueSizeRequired, Flags);
// hDevice : HANDLE
// Descriptor : BTH_LE_GATT_DESCRIPTOR*
// DescriptorValueDataSize : DWORD
// DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out
// DescriptorValueSizeRequired : WORD* optional, out
// Flags : DWORD
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Bluetoothapis extends StdCallLibrary {
Bluetoothapis INSTANCE = Native.load("bluetoothapis", Bluetoothapis.class);
int BluetoothGATTGetDescriptorValue(
Pointer hDevice, // HANDLE
Pointer Descriptor, // BTH_LE_GATT_DESCRIPTOR*
int DescriptorValueDataSize, // DWORD
Pointer DescriptorValue, // BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out
ShortByReference DescriptorValueSizeRequired, // WORD* optional, out
int Flags // DWORD
);
}@[Link("bluetoothapis")]
lib LibBluetoothApis
fun BluetoothGATTGetDescriptorValue = BluetoothGATTGetDescriptorValue(
hDevice : Void*, # HANDLE
Descriptor : BTH_LE_GATT_DESCRIPTOR*, # BTH_LE_GATT_DESCRIPTOR*
DescriptorValueDataSize : UInt32, # DWORD
DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE*, # BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out
DescriptorValueSizeRequired : UInt16*, # WORD* optional, out
Flags : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef BluetoothGATTGetDescriptorValueNative = Int32 Function(Pointer<Void>, Pointer<Void>, Uint32, Pointer<Void>, Pointer<Uint16>, Uint32);
typedef BluetoothGATTGetDescriptorValueDart = int Function(Pointer<Void>, Pointer<Void>, int, Pointer<Void>, Pointer<Uint16>, int);
final BluetoothGATTGetDescriptorValue = DynamicLibrary.open('BluetoothApis.dll')
.lookupFunction<BluetoothGATTGetDescriptorValueNative, BluetoothGATTGetDescriptorValueDart>('BluetoothGATTGetDescriptorValue');
// hDevice : HANDLE -> Pointer<Void>
// Descriptor : BTH_LE_GATT_DESCRIPTOR* -> Pointer<Void>
// DescriptorValueDataSize : DWORD -> Uint32
// DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out -> Pointer<Void>
// DescriptorValueSizeRequired : WORD* optional, out -> Pointer<Uint16>
// Flags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function BluetoothGATTGetDescriptorValue(
hDevice: THandle; // HANDLE
Descriptor: Pointer; // BTH_LE_GATT_DESCRIPTOR*
DescriptorValueDataSize: DWORD; // DWORD
DescriptorValue: Pointer; // BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out
DescriptorValueSizeRequired: Pointer; // WORD* optional, out
Flags: DWORD // DWORD
): Integer; stdcall;
external 'BluetoothApis.dll' name 'BluetoothGATTGetDescriptorValue';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "BluetoothGATTGetDescriptorValue"
c_BluetoothGATTGetDescriptorValue :: Ptr () -> Ptr () -> Word32 -> Ptr () -> Ptr Word16 -> Word32 -> IO Int32
-- hDevice : HANDLE -> Ptr ()
-- Descriptor : BTH_LE_GATT_DESCRIPTOR* -> Ptr ()
-- DescriptorValueDataSize : DWORD -> Word32
-- DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out -> Ptr ()
-- DescriptorValueSizeRequired : WORD* optional, out -> Ptr Word16
-- Flags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let bluetoothgattgetdescriptorvalue =
foreign "BluetoothGATTGetDescriptorValue"
((ptr void) @-> (ptr void) @-> uint32_t @-> (ptr void) @-> (ptr uint16_t) @-> uint32_t @-> returning int32_t)
(* hDevice : HANDLE -> (ptr void) *)
(* Descriptor : BTH_LE_GATT_DESCRIPTOR* -> (ptr void) *)
(* DescriptorValueDataSize : DWORD -> uint32_t *)
(* DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out -> (ptr void) *)
(* DescriptorValueSizeRequired : WORD* optional, out -> (ptr uint16_t) *)
(* Flags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library bluetoothapis (t "BluetoothApis.dll"))
(cffi:use-foreign-library bluetoothapis)
(cffi:defcfun ("BluetoothGATTGetDescriptorValue" bluetooth-gattget-descriptor-value :convention :stdcall) :int32
(h-device :pointer) ; HANDLE
(descriptor :pointer) ; BTH_LE_GATT_DESCRIPTOR*
(descriptor-value-data-size :uint32) ; DWORD
(descriptor-value :pointer) ; BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out
(descriptor-value-size-required :pointer) ; WORD* optional, out
(flags :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $BluetoothGATTGetDescriptorValue = Win32::API::More->new('BluetoothApis',
'int BluetoothGATTGetDescriptorValue(HANDLE hDevice, LPVOID Descriptor, DWORD DescriptorValueDataSize, LPVOID DescriptorValue, LPVOID DescriptorValueSizeRequired, DWORD Flags)');
# my $ret = $BluetoothGATTGetDescriptorValue->Call($hDevice, $Descriptor, $DescriptorValueDataSize, $DescriptorValue, $DescriptorValueSizeRequired, $Flags);
# hDevice : HANDLE -> HANDLE
# Descriptor : BTH_LE_GATT_DESCRIPTOR* -> LPVOID
# DescriptorValueDataSize : DWORD -> DWORD
# DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* optional, out -> LPVOID
# DescriptorValueSizeRequired : WORD* optional, out -> LPVOID
# Flags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。