ホーム › Devices.Bluetooth › BluetoothGATTSetCharacteristicValue
BluetoothGATTSetCharacteristicValue
関数GATTキャラクタリスティックに値を書き込む。
シグネチャ
// BluetoothApis.dll
#include <windows.h>
HRESULT BluetoothGATTSetCharacteristicValue(
HANDLE hDevice,
BTH_LE_GATT_CHARACTERISTIC* Characteristic,
BTH_LE_GATT_CHARACTERISTIC_VALUE* CharacteristicValue,
ULONGLONG ReliableWriteContext, // optional
DWORD Flags
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hDevice | HANDLE | in |
| Characteristic | BTH_LE_GATT_CHARACTERISTIC* | in |
| CharacteristicValue | BTH_LE_GATT_CHARACTERISTIC_VALUE* | in |
| ReliableWriteContext | ULONGLONG | inoptional |
| Flags | DWORD | in |
戻り値の型: HRESULT
各言語での呼び出し定義
// BluetoothApis.dll
#include <windows.h>
HRESULT BluetoothGATTSetCharacteristicValue(
HANDLE hDevice,
BTH_LE_GATT_CHARACTERISTIC* Characteristic,
BTH_LE_GATT_CHARACTERISTIC_VALUE* CharacteristicValue,
ULONGLONG ReliableWriteContext, // optional
DWORD Flags
);[DllImport("BluetoothApis.dll", ExactSpelling = true)]
static extern int BluetoothGATTSetCharacteristicValue(
IntPtr hDevice, // HANDLE
IntPtr Characteristic, // BTH_LE_GATT_CHARACTERISTIC*
IntPtr CharacteristicValue, // BTH_LE_GATT_CHARACTERISTIC_VALUE*
ulong ReliableWriteContext, // ULONGLONG optional
uint Flags // DWORD
);<DllImport("BluetoothApis.dll", ExactSpelling:=True)>
Public Shared Function BluetoothGATTSetCharacteristicValue(
hDevice As IntPtr, ' HANDLE
Characteristic As IntPtr, ' BTH_LE_GATT_CHARACTERISTIC*
CharacteristicValue As IntPtr, ' BTH_LE_GATT_CHARACTERISTIC_VALUE*
ReliableWriteContext As ULong, ' ULONGLONG optional
Flags As UInteger ' DWORD
) As Integer
End Function' hDevice : HANDLE
' Characteristic : BTH_LE_GATT_CHARACTERISTIC*
' CharacteristicValue : BTH_LE_GATT_CHARACTERISTIC_VALUE*
' ReliableWriteContext : ULONGLONG optional
' Flags : DWORD
Declare PtrSafe Function BluetoothGATTSetCharacteristicValue Lib "bluetoothapis" ( _
ByVal hDevice As LongPtr, _
ByVal Characteristic As LongPtr, _
ByVal CharacteristicValue As LongPtr, _
ByVal ReliableWriteContext As LongLong, _
ByVal Flags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
BluetoothGATTSetCharacteristicValue = ctypes.windll.bluetoothapis.BluetoothGATTSetCharacteristicValue
BluetoothGATTSetCharacteristicValue.restype = ctypes.c_int
BluetoothGATTSetCharacteristicValue.argtypes = [
wintypes.HANDLE, # hDevice : HANDLE
ctypes.c_void_p, # Characteristic : BTH_LE_GATT_CHARACTERISTIC*
ctypes.c_void_p, # CharacteristicValue : BTH_LE_GATT_CHARACTERISTIC_VALUE*
ctypes.c_ulonglong, # ReliableWriteContext : ULONGLONG optional
wintypes.DWORD, # Flags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('BluetoothApis.dll')
BluetoothGATTSetCharacteristicValue = Fiddle::Function.new(
lib['BluetoothGATTSetCharacteristicValue'],
[
Fiddle::TYPE_VOIDP, # hDevice : HANDLE
Fiddle::TYPE_VOIDP, # Characteristic : BTH_LE_GATT_CHARACTERISTIC*
Fiddle::TYPE_VOIDP, # CharacteristicValue : BTH_LE_GATT_CHARACTERISTIC_VALUE*
-Fiddle::TYPE_LONG_LONG, # ReliableWriteContext : ULONGLONG optional
-Fiddle::TYPE_INT, # Flags : DWORD
],
Fiddle::TYPE_INT)#[link(name = "bluetoothapis")]
extern "system" {
fn BluetoothGATTSetCharacteristicValue(
hDevice: *mut core::ffi::c_void, // HANDLE
Characteristic: *mut BTH_LE_GATT_CHARACTERISTIC, // BTH_LE_GATT_CHARACTERISTIC*
CharacteristicValue: *mut BTH_LE_GATT_CHARACTERISTIC_VALUE, // BTH_LE_GATT_CHARACTERISTIC_VALUE*
ReliableWriteContext: u64, // ULONGLONG optional
Flags: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("BluetoothApis.dll")]
public static extern int BluetoothGATTSetCharacteristicValue(IntPtr hDevice, IntPtr Characteristic, IntPtr CharacteristicValue, ulong ReliableWriteContext, uint Flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'BluetoothApis_BluetoothGATTSetCharacteristicValue' -Namespace Win32 -PassThru
# $api::BluetoothGATTSetCharacteristicValue(hDevice, Characteristic, CharacteristicValue, ReliableWriteContext, Flags)#uselib "BluetoothApis.dll"
#func global BluetoothGATTSetCharacteristicValue "BluetoothGATTSetCharacteristicValue" sptr, sptr, sptr, sptr, sptr
; BluetoothGATTSetCharacteristicValue hDevice, varptr(Characteristic), varptr(CharacteristicValue), ReliableWriteContext, Flags ; 戻り値は stat
; hDevice : HANDLE -> "sptr"
; Characteristic : BTH_LE_GATT_CHARACTERISTIC* -> "sptr"
; CharacteristicValue : BTH_LE_GATT_CHARACTERISTIC_VALUE* -> "sptr"
; ReliableWriteContext : ULONGLONG optional -> "sptr"
; Flags : DWORD -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "BluetoothApis.dll" #cfunc global BluetoothGATTSetCharacteristicValue "BluetoothGATTSetCharacteristicValue" sptr, var, var, int64, int ; res = BluetoothGATTSetCharacteristicValue(hDevice, Characteristic, CharacteristicValue, ReliableWriteContext, Flags) ; hDevice : HANDLE -> "sptr" ; Characteristic : BTH_LE_GATT_CHARACTERISTIC* -> "var" ; CharacteristicValue : BTH_LE_GATT_CHARACTERISTIC_VALUE* -> "var" ; ReliableWriteContext : ULONGLONG optional -> "int64" ; Flags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。 ; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。#uselib "BluetoothApis.dll" #cfunc global BluetoothGATTSetCharacteristicValue "BluetoothGATTSetCharacteristicValue" sptr, sptr, sptr, int64, int ; res = BluetoothGATTSetCharacteristicValue(hDevice, varptr(Characteristic), varptr(CharacteristicValue), ReliableWriteContext, Flags) ; hDevice : HANDLE -> "sptr" ; Characteristic : BTH_LE_GATT_CHARACTERISTIC* -> "sptr" ; CharacteristicValue : BTH_LE_GATT_CHARACTERISTIC_VALUE* -> "sptr" ; ReliableWriteContext : ULONGLONG optional -> "int64" ; Flags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。 ; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
出力引数:
; HRESULT BluetoothGATTSetCharacteristicValue(HANDLE hDevice, BTH_LE_GATT_CHARACTERISTIC* Characteristic, BTH_LE_GATT_CHARACTERISTIC_VALUE* CharacteristicValue, ULONGLONG ReliableWriteContext, DWORD Flags) #uselib "BluetoothApis.dll" #cfunc global BluetoothGATTSetCharacteristicValue "BluetoothGATTSetCharacteristicValue" intptr, var, var, int64, int ; res = BluetoothGATTSetCharacteristicValue(hDevice, Characteristic, CharacteristicValue, ReliableWriteContext, Flags) ; hDevice : HANDLE -> "intptr" ; Characteristic : BTH_LE_GATT_CHARACTERISTIC* -> "var" ; CharacteristicValue : BTH_LE_GATT_CHARACTERISTIC_VALUE* -> "var" ; ReliableWriteContext : ULONGLONG optional -> "int64" ; Flags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT BluetoothGATTSetCharacteristicValue(HANDLE hDevice, BTH_LE_GATT_CHARACTERISTIC* Characteristic, BTH_LE_GATT_CHARACTERISTIC_VALUE* CharacteristicValue, ULONGLONG ReliableWriteContext, DWORD Flags) #uselib "BluetoothApis.dll" #cfunc global BluetoothGATTSetCharacteristicValue "BluetoothGATTSetCharacteristicValue" intptr, intptr, intptr, int64, int ; res = BluetoothGATTSetCharacteristicValue(hDevice, varptr(Characteristic), varptr(CharacteristicValue), ReliableWriteContext, Flags) ; hDevice : HANDLE -> "intptr" ; Characteristic : BTH_LE_GATT_CHARACTERISTIC* -> "intptr" ; CharacteristicValue : BTH_LE_GATT_CHARACTERISTIC_VALUE* -> "intptr" ; ReliableWriteContext : ULONGLONG optional -> "int64" ; Flags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
bluetoothapis = windows.NewLazySystemDLL("BluetoothApis.dll")
procBluetoothGATTSetCharacteristicValue = bluetoothapis.NewProc("BluetoothGATTSetCharacteristicValue")
)
// hDevice (HANDLE), Characteristic (BTH_LE_GATT_CHARACTERISTIC*), CharacteristicValue (BTH_LE_GATT_CHARACTERISTIC_VALUE*), ReliableWriteContext (ULONGLONG optional), Flags (DWORD)
r1, _, err := procBluetoothGATTSetCharacteristicValue.Call(
uintptr(hDevice),
uintptr(Characteristic),
uintptr(CharacteristicValue),
uintptr(ReliableWriteContext),
uintptr(Flags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction BluetoothGATTSetCharacteristicValue(
hDevice: THandle; // HANDLE
Characteristic: Pointer; // BTH_LE_GATT_CHARACTERISTIC*
CharacteristicValue: Pointer; // BTH_LE_GATT_CHARACTERISTIC_VALUE*
ReliableWriteContext: UInt64; // ULONGLONG optional
Flags: DWORD // DWORD
): Integer; stdcall;
external 'BluetoothApis.dll' name 'BluetoothGATTSetCharacteristicValue';result := DllCall("BluetoothApis\BluetoothGATTSetCharacteristicValue"
, "Ptr", hDevice ; HANDLE
, "Ptr", Characteristic ; BTH_LE_GATT_CHARACTERISTIC*
, "Ptr", CharacteristicValue ; BTH_LE_GATT_CHARACTERISTIC_VALUE*
, "Int64", ReliableWriteContext ; ULONGLONG optional
, "UInt", Flags ; DWORD
, "Int") ; return: HRESULT●BluetoothGATTSetCharacteristicValue(hDevice, Characteristic, CharacteristicValue, ReliableWriteContext, Flags) = DLL("BluetoothApis.dll", "int BluetoothGATTSetCharacteristicValue(void*, void*, void*, qword, dword)")
# 呼び出し: BluetoothGATTSetCharacteristicValue(hDevice, Characteristic, CharacteristicValue, ReliableWriteContext, Flags)
# hDevice : HANDLE -> "void*"
# Characteristic : BTH_LE_GATT_CHARACTERISTIC* -> "void*"
# CharacteristicValue : BTH_LE_GATT_CHARACTERISTIC_VALUE* -> "void*"
# ReliableWriteContext : ULONGLONG optional -> "qword"
# Flags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。