ホーム › Devices.Bluetooth › BluetoothGATTSetDescriptorValue
BluetoothGATTSetDescriptorValue
関数GATTディスクリプタに値を書き込む。
シグネチャ
// BluetoothApis.dll
#include <windows.h>
HRESULT BluetoothGATTSetDescriptorValue(
HANDLE hDevice,
BTH_LE_GATT_DESCRIPTOR* Descriptor,
BTH_LE_GATT_DESCRIPTOR_VALUE* DescriptorValue,
DWORD Flags
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hDevice | HANDLE | in | 対象のBLEデバイスを表すハンドル。CreateFileで開いたデバイスハンドルを指定する。 |
| Descriptor | BTH_LE_GATT_DESCRIPTOR* | in | 値を設定する対象のGATTディスクリプタを指す構造体ポインタ。BTH_LE_GATT_DESCRIPTOR型を渡す。 |
| DescriptorValue | BTH_LE_GATT_DESCRIPTOR_VALUE* | in | 書き込むディスクリプタ値を格納したBTH_LE_GATT_DESCRIPTOR_VALUE構造体へのポインタ。 |
| Flags | DWORD | in | 動作を制御するフラグ。通常は予約値として0を指定する。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// BluetoothApis.dll
#include <windows.h>
HRESULT BluetoothGATTSetDescriptorValue(
HANDLE hDevice,
BTH_LE_GATT_DESCRIPTOR* Descriptor,
BTH_LE_GATT_DESCRIPTOR_VALUE* DescriptorValue,
DWORD Flags
);[DllImport("BluetoothApis.dll", ExactSpelling = true)]
static extern int BluetoothGATTSetDescriptorValue(
IntPtr hDevice, // HANDLE
IntPtr Descriptor, // BTH_LE_GATT_DESCRIPTOR*
IntPtr DescriptorValue, // BTH_LE_GATT_DESCRIPTOR_VALUE*
uint Flags // DWORD
);<DllImport("BluetoothApis.dll", ExactSpelling:=True)>
Public Shared Function BluetoothGATTSetDescriptorValue(
hDevice As IntPtr, ' HANDLE
Descriptor As IntPtr, ' BTH_LE_GATT_DESCRIPTOR*
DescriptorValue As IntPtr, ' BTH_LE_GATT_DESCRIPTOR_VALUE*
Flags As UInteger ' DWORD
) As Integer
End Function' hDevice : HANDLE
' Descriptor : BTH_LE_GATT_DESCRIPTOR*
' DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE*
' Flags : DWORD
Declare PtrSafe Function BluetoothGATTSetDescriptorValue Lib "bluetoothapis" ( _
ByVal hDevice As LongPtr, _
ByVal Descriptor As LongPtr, _
ByVal DescriptorValue 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
BluetoothGATTSetDescriptorValue = ctypes.windll.bluetoothapis.BluetoothGATTSetDescriptorValue
BluetoothGATTSetDescriptorValue.restype = ctypes.c_int
BluetoothGATTSetDescriptorValue.argtypes = [
wintypes.HANDLE, # hDevice : HANDLE
ctypes.c_void_p, # Descriptor : BTH_LE_GATT_DESCRIPTOR*
ctypes.c_void_p, # DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE*
wintypes.DWORD, # Flags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('BluetoothApis.dll')
BluetoothGATTSetDescriptorValue = Fiddle::Function.new(
lib['BluetoothGATTSetDescriptorValue'],
[
Fiddle::TYPE_VOIDP, # hDevice : HANDLE
Fiddle::TYPE_VOIDP, # Descriptor : BTH_LE_GATT_DESCRIPTOR*
Fiddle::TYPE_VOIDP, # DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE*
-Fiddle::TYPE_INT, # Flags : DWORD
],
Fiddle::TYPE_INT)#[link(name = "bluetoothapis")]
extern "system" {
fn BluetoothGATTSetDescriptorValue(
hDevice: *mut core::ffi::c_void, // HANDLE
Descriptor: *mut BTH_LE_GATT_DESCRIPTOR, // BTH_LE_GATT_DESCRIPTOR*
DescriptorValue: *mut BTH_LE_GATT_DESCRIPTOR_VALUE, // BTH_LE_GATT_DESCRIPTOR_VALUE*
Flags: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("BluetoothApis.dll")]
public static extern int BluetoothGATTSetDescriptorValue(IntPtr hDevice, IntPtr Descriptor, IntPtr DescriptorValue, uint Flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'BluetoothApis_BluetoothGATTSetDescriptorValue' -Namespace Win32 -PassThru
# $api::BluetoothGATTSetDescriptorValue(hDevice, Descriptor, DescriptorValue, Flags)#uselib "BluetoothApis.dll"
#func global BluetoothGATTSetDescriptorValue "BluetoothGATTSetDescriptorValue" sptr, sptr, sptr, sptr
; BluetoothGATTSetDescriptorValue hDevice, varptr(Descriptor), varptr(DescriptorValue), Flags ; 戻り値は stat
; hDevice : HANDLE -> "sptr"
; Descriptor : BTH_LE_GATT_DESCRIPTOR* -> "sptr"
; DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* -> "sptr"
; Flags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "BluetoothApis.dll" #cfunc global BluetoothGATTSetDescriptorValue "BluetoothGATTSetDescriptorValue" sptr, var, var, int ; res = BluetoothGATTSetDescriptorValue(hDevice, Descriptor, DescriptorValue, Flags) ; hDevice : HANDLE -> "sptr" ; Descriptor : BTH_LE_GATT_DESCRIPTOR* -> "var" ; DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* -> "var" ; Flags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "BluetoothApis.dll" #cfunc global BluetoothGATTSetDescriptorValue "BluetoothGATTSetDescriptorValue" sptr, sptr, sptr, int ; res = BluetoothGATTSetDescriptorValue(hDevice, varptr(Descriptor), varptr(DescriptorValue), Flags) ; hDevice : HANDLE -> "sptr" ; Descriptor : BTH_LE_GATT_DESCRIPTOR* -> "sptr" ; DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* -> "sptr" ; Flags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT BluetoothGATTSetDescriptorValue(HANDLE hDevice, BTH_LE_GATT_DESCRIPTOR* Descriptor, BTH_LE_GATT_DESCRIPTOR_VALUE* DescriptorValue, DWORD Flags) #uselib "BluetoothApis.dll" #cfunc global BluetoothGATTSetDescriptorValue "BluetoothGATTSetDescriptorValue" intptr, var, var, int ; res = BluetoothGATTSetDescriptorValue(hDevice, Descriptor, DescriptorValue, Flags) ; hDevice : HANDLE -> "intptr" ; Descriptor : BTH_LE_GATT_DESCRIPTOR* -> "var" ; DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* -> "var" ; Flags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT BluetoothGATTSetDescriptorValue(HANDLE hDevice, BTH_LE_GATT_DESCRIPTOR* Descriptor, BTH_LE_GATT_DESCRIPTOR_VALUE* DescriptorValue, DWORD Flags) #uselib "BluetoothApis.dll" #cfunc global BluetoothGATTSetDescriptorValue "BluetoothGATTSetDescriptorValue" intptr, intptr, intptr, int ; res = BluetoothGATTSetDescriptorValue(hDevice, varptr(Descriptor), varptr(DescriptorValue), Flags) ; hDevice : HANDLE -> "intptr" ; Descriptor : BTH_LE_GATT_DESCRIPTOR* -> "intptr" ; DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* -> "intptr" ; Flags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
bluetoothapis = windows.NewLazySystemDLL("BluetoothApis.dll")
procBluetoothGATTSetDescriptorValue = bluetoothapis.NewProc("BluetoothGATTSetDescriptorValue")
)
// hDevice (HANDLE), Descriptor (BTH_LE_GATT_DESCRIPTOR*), DescriptorValue (BTH_LE_GATT_DESCRIPTOR_VALUE*), Flags (DWORD)
r1, _, err := procBluetoothGATTSetDescriptorValue.Call(
uintptr(hDevice),
uintptr(Descriptor),
uintptr(DescriptorValue),
uintptr(Flags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction BluetoothGATTSetDescriptorValue(
hDevice: THandle; // HANDLE
Descriptor: Pointer; // BTH_LE_GATT_DESCRIPTOR*
DescriptorValue: Pointer; // BTH_LE_GATT_DESCRIPTOR_VALUE*
Flags: DWORD // DWORD
): Integer; stdcall;
external 'BluetoothApis.dll' name 'BluetoothGATTSetDescriptorValue';result := DllCall("BluetoothApis\BluetoothGATTSetDescriptorValue"
, "Ptr", hDevice ; HANDLE
, "Ptr", Descriptor ; BTH_LE_GATT_DESCRIPTOR*
, "Ptr", DescriptorValue ; BTH_LE_GATT_DESCRIPTOR_VALUE*
, "UInt", Flags ; DWORD
, "Int") ; return: HRESULT●BluetoothGATTSetDescriptorValue(hDevice, Descriptor, DescriptorValue, Flags) = DLL("BluetoothApis.dll", "int BluetoothGATTSetDescriptorValue(void*, void*, void*, dword)")
# 呼び出し: BluetoothGATTSetDescriptorValue(hDevice, Descriptor, DescriptorValue, Flags)
# hDevice : HANDLE -> "void*"
# Descriptor : BTH_LE_GATT_DESCRIPTOR* -> "void*"
# DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* -> "void*"
# Flags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "bluetoothapis" fn BluetoothGATTSetDescriptorValue(
hDevice: ?*anyopaque, // HANDLE
Descriptor: [*c]BTH_LE_GATT_DESCRIPTOR, // BTH_LE_GATT_DESCRIPTOR*
DescriptorValue: [*c]BTH_LE_GATT_DESCRIPTOR_VALUE, // BTH_LE_GATT_DESCRIPTOR_VALUE*
Flags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc BluetoothGATTSetDescriptorValue(
hDevice: pointer, # HANDLE
Descriptor: ptr BTH_LE_GATT_DESCRIPTOR, # BTH_LE_GATT_DESCRIPTOR*
DescriptorValue: ptr BTH_LE_GATT_DESCRIPTOR_VALUE, # BTH_LE_GATT_DESCRIPTOR_VALUE*
Flags: uint32 # DWORD
): int32 {.importc: "BluetoothGATTSetDescriptorValue", stdcall, dynlib: "BluetoothApis.dll".}pragma(lib, "bluetoothapis");
extern(Windows)
int BluetoothGATTSetDescriptorValue(
void* hDevice, // HANDLE
BTH_LE_GATT_DESCRIPTOR* Descriptor, // BTH_LE_GATT_DESCRIPTOR*
BTH_LE_GATT_DESCRIPTOR_VALUE* DescriptorValue, // BTH_LE_GATT_DESCRIPTOR_VALUE*
uint Flags // DWORD
);ccall((:BluetoothGATTSetDescriptorValue, "BluetoothApis.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{BTH_LE_GATT_DESCRIPTOR}, Ptr{BTH_LE_GATT_DESCRIPTOR_VALUE}, UInt32),
hDevice, Descriptor, DescriptorValue, Flags)
# hDevice : HANDLE -> Ptr{Cvoid}
# Descriptor : BTH_LE_GATT_DESCRIPTOR* -> Ptr{BTH_LE_GATT_DESCRIPTOR}
# DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* -> Ptr{BTH_LE_GATT_DESCRIPTOR_VALUE}
# Flags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t BluetoothGATTSetDescriptorValue(
void* hDevice,
void* Descriptor,
void* DescriptorValue,
uint32_t Flags);
]]
local bluetoothapis = ffi.load("bluetoothapis")
-- bluetoothapis.BluetoothGATTSetDescriptorValue(hDevice, Descriptor, DescriptorValue, Flags)
-- hDevice : HANDLE
-- Descriptor : BTH_LE_GATT_DESCRIPTOR*
-- DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE*
-- Flags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('BluetoothApis.dll');
const BluetoothGATTSetDescriptorValue = lib.func('__stdcall', 'BluetoothGATTSetDescriptorValue', 'int32_t', ['void *', 'void *', 'void *', 'uint32_t']);
// BluetoothGATTSetDescriptorValue(hDevice, Descriptor, DescriptorValue, Flags)
// hDevice : HANDLE -> 'void *'
// Descriptor : BTH_LE_GATT_DESCRIPTOR* -> 'void *'
// DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* -> 'void *'
// Flags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("BluetoothApis.dll", {
BluetoothGATTSetDescriptorValue: { parameters: ["pointer", "pointer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.BluetoothGATTSetDescriptorValue(hDevice, Descriptor, DescriptorValue, Flags)
// hDevice : HANDLE -> "pointer"
// Descriptor : BTH_LE_GATT_DESCRIPTOR* -> "pointer"
// DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* -> "pointer"
// Flags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t BluetoothGATTSetDescriptorValue(
void* hDevice,
void* Descriptor,
void* DescriptorValue,
uint32_t Flags);
C, "BluetoothApis.dll");
// $ffi->BluetoothGATTSetDescriptorValue(hDevice, Descriptor, DescriptorValue, Flags);
// hDevice : HANDLE
// Descriptor : BTH_LE_GATT_DESCRIPTOR*
// DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE*
// 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 BluetoothGATTSetDescriptorValue(
Pointer hDevice, // HANDLE
Pointer Descriptor, // BTH_LE_GATT_DESCRIPTOR*
Pointer DescriptorValue, // BTH_LE_GATT_DESCRIPTOR_VALUE*
int Flags // DWORD
);
}@[Link("bluetoothapis")]
lib LibBluetoothApis
fun BluetoothGATTSetDescriptorValue = BluetoothGATTSetDescriptorValue(
hDevice : Void*, # HANDLE
Descriptor : BTH_LE_GATT_DESCRIPTOR*, # BTH_LE_GATT_DESCRIPTOR*
DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE*, # BTH_LE_GATT_DESCRIPTOR_VALUE*
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 BluetoothGATTSetDescriptorValueNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Uint32);
typedef BluetoothGATTSetDescriptorValueDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, int);
final BluetoothGATTSetDescriptorValue = DynamicLibrary.open('BluetoothApis.dll')
.lookupFunction<BluetoothGATTSetDescriptorValueNative, BluetoothGATTSetDescriptorValueDart>('BluetoothGATTSetDescriptorValue');
// hDevice : HANDLE -> Pointer<Void>
// Descriptor : BTH_LE_GATT_DESCRIPTOR* -> Pointer<Void>
// DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* -> Pointer<Void>
// Flags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function BluetoothGATTSetDescriptorValue(
hDevice: THandle; // HANDLE
Descriptor: Pointer; // BTH_LE_GATT_DESCRIPTOR*
DescriptorValue: Pointer; // BTH_LE_GATT_DESCRIPTOR_VALUE*
Flags: DWORD // DWORD
): Integer; stdcall;
external 'BluetoothApis.dll' name 'BluetoothGATTSetDescriptorValue';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "BluetoothGATTSetDescriptorValue"
c_BluetoothGATTSetDescriptorValue :: Ptr () -> Ptr () -> Ptr () -> Word32 -> IO Int32
-- hDevice : HANDLE -> Ptr ()
-- Descriptor : BTH_LE_GATT_DESCRIPTOR* -> Ptr ()
-- DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* -> Ptr ()
-- Flags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let bluetoothgattsetdescriptorvalue =
foreign "BluetoothGATTSetDescriptorValue"
((ptr void) @-> (ptr void) @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* hDevice : HANDLE -> (ptr void) *)
(* Descriptor : BTH_LE_GATT_DESCRIPTOR* -> (ptr void) *)
(* DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* -> (ptr void) *)
(* 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 ("BluetoothGATTSetDescriptorValue" bluetooth-gattset-descriptor-value :convention :stdcall) :int32
(h-device :pointer) ; HANDLE
(descriptor :pointer) ; BTH_LE_GATT_DESCRIPTOR*
(descriptor-value :pointer) ; BTH_LE_GATT_DESCRIPTOR_VALUE*
(flags :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $BluetoothGATTSetDescriptorValue = Win32::API::More->new('BluetoothApis',
'int BluetoothGATTSetDescriptorValue(HANDLE hDevice, LPVOID Descriptor, LPVOID DescriptorValue, DWORD Flags)');
# my $ret = $BluetoothGATTSetDescriptorValue->Call($hDevice, $Descriptor, $DescriptorValue, $Flags);
# hDevice : HANDLE -> HANDLE
# Descriptor : BTH_LE_GATT_DESCRIPTOR* -> LPVOID
# DescriptorValue : BTH_LE_GATT_DESCRIPTOR_VALUE* -> LPVOID
# Flags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。