ホーム › Devices.Bluetooth › BluetoothGATTRegisterEvent
BluetoothGATTRegisterEvent
関数GATTサービスの値変化イベント通知を登録する。
シグネチャ
// BluetoothApis.dll
#include <windows.h>
HRESULT BluetoothGATTRegisterEvent(
HANDLE hService,
BTH_LE_GATT_EVENT_TYPE EventType,
void* EventParameterIn,
PFNBLUETOOTH_GATT_EVENT_CALLBACK Callback,
void* CallbackContext, // optional
INT_PTR* pEventHandle,
DWORD Flags
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hService | HANDLE | in | イベントを登録する対象のGATTサービスを表すハンドル。 |
| EventType | BTH_LE_GATT_EVENT_TYPE | in | 登録するイベントの種別を示す列挙値。特性値変更通知などを指定する。 |
| EventParameterIn | void* | in | イベント種別に応じた入力パラメータ構造体へのポインタ。NULL可の場合がある。 |
| Callback | PFNBLUETOOTH_GATT_EVENT_CALLBACK | in | イベント発生時に呼び出されるコールバック関数へのポインタ。 |
| CallbackContext | void* | inoptional | コールバックへ引き渡される任意のユーザーコンテキスト。NULL可。 |
| pEventHandle | INT_PTR* | out | 登録したイベントを識別するハンドルを受け取る出力ポインタ。後の登録解除に使う。 |
| Flags | DWORD | in | 動作を制御するフラグ。通常は予約値として0を指定する。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// BluetoothApis.dll
#include <windows.h>
HRESULT BluetoothGATTRegisterEvent(
HANDLE hService,
BTH_LE_GATT_EVENT_TYPE EventType,
void* EventParameterIn,
PFNBLUETOOTH_GATT_EVENT_CALLBACK Callback,
void* CallbackContext, // optional
INT_PTR* pEventHandle,
DWORD Flags
);[DllImport("BluetoothApis.dll", ExactSpelling = true)]
static extern int BluetoothGATTRegisterEvent(
IntPtr hService, // HANDLE
int EventType, // BTH_LE_GATT_EVENT_TYPE
IntPtr EventParameterIn, // void*
IntPtr Callback, // PFNBLUETOOTH_GATT_EVENT_CALLBACK
IntPtr CallbackContext, // void* optional
out IntPtr pEventHandle, // INT_PTR* out
uint Flags // DWORD
);<DllImport("BluetoothApis.dll", ExactSpelling:=True)>
Public Shared Function BluetoothGATTRegisterEvent(
hService As IntPtr, ' HANDLE
EventType As Integer, ' BTH_LE_GATT_EVENT_TYPE
EventParameterIn As IntPtr, ' void*
Callback As IntPtr, ' PFNBLUETOOTH_GATT_EVENT_CALLBACK
CallbackContext As IntPtr, ' void* optional
<Out> ByRef pEventHandle As IntPtr, ' INT_PTR* out
Flags As UInteger ' DWORD
) As Integer
End Function' hService : HANDLE
' EventType : BTH_LE_GATT_EVENT_TYPE
' EventParameterIn : void*
' Callback : PFNBLUETOOTH_GATT_EVENT_CALLBACK
' CallbackContext : void* optional
' pEventHandle : INT_PTR* out
' Flags : DWORD
Declare PtrSafe Function BluetoothGATTRegisterEvent Lib "bluetoothapis" ( _
ByVal hService As LongPtr, _
ByVal EventType As Long, _
ByVal EventParameterIn As LongPtr, _
ByVal Callback As LongPtr, _
ByVal CallbackContext As LongPtr, _
ByRef pEventHandle 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
BluetoothGATTRegisterEvent = ctypes.windll.bluetoothapis.BluetoothGATTRegisterEvent
BluetoothGATTRegisterEvent.restype = ctypes.c_int
BluetoothGATTRegisterEvent.argtypes = [
wintypes.HANDLE, # hService : HANDLE
ctypes.c_int, # EventType : BTH_LE_GATT_EVENT_TYPE
ctypes.POINTER(None), # EventParameterIn : void*
ctypes.c_void_p, # Callback : PFNBLUETOOTH_GATT_EVENT_CALLBACK
ctypes.POINTER(None), # CallbackContext : void* optional
ctypes.POINTER(ctypes.c_ssize_t), # pEventHandle : INT_PTR* out
wintypes.DWORD, # Flags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('BluetoothApis.dll')
BluetoothGATTRegisterEvent = Fiddle::Function.new(
lib['BluetoothGATTRegisterEvent'],
[
Fiddle::TYPE_VOIDP, # hService : HANDLE
Fiddle::TYPE_INT, # EventType : BTH_LE_GATT_EVENT_TYPE
Fiddle::TYPE_VOIDP, # EventParameterIn : void*
Fiddle::TYPE_VOIDP, # Callback : PFNBLUETOOTH_GATT_EVENT_CALLBACK
Fiddle::TYPE_VOIDP, # CallbackContext : void* optional
Fiddle::TYPE_VOIDP, # pEventHandle : INT_PTR* out
-Fiddle::TYPE_INT, # Flags : DWORD
],
Fiddle::TYPE_INT)#[link(name = "bluetoothapis")]
extern "system" {
fn BluetoothGATTRegisterEvent(
hService: *mut core::ffi::c_void, // HANDLE
EventType: i32, // BTH_LE_GATT_EVENT_TYPE
EventParameterIn: *mut (), // void*
Callback: *const core::ffi::c_void, // PFNBLUETOOTH_GATT_EVENT_CALLBACK
CallbackContext: *mut (), // void* optional
pEventHandle: *mut isize, // INT_PTR* out
Flags: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("BluetoothApis.dll")]
public static extern int BluetoothGATTRegisterEvent(IntPtr hService, int EventType, IntPtr EventParameterIn, IntPtr Callback, IntPtr CallbackContext, out IntPtr pEventHandle, uint Flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'BluetoothApis_BluetoothGATTRegisterEvent' -Namespace Win32 -PassThru
# $api::BluetoothGATTRegisterEvent(hService, EventType, EventParameterIn, Callback, CallbackContext, pEventHandle, Flags)#uselib "BluetoothApis.dll"
#func global BluetoothGATTRegisterEvent "BluetoothGATTRegisterEvent" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; BluetoothGATTRegisterEvent hService, EventType, EventParameterIn, Callback, CallbackContext, varptr(pEventHandle), Flags ; 戻り値は stat
; hService : HANDLE -> "sptr"
; EventType : BTH_LE_GATT_EVENT_TYPE -> "sptr"
; EventParameterIn : void* -> "sptr"
; Callback : PFNBLUETOOTH_GATT_EVENT_CALLBACK -> "sptr"
; CallbackContext : void* optional -> "sptr"
; pEventHandle : INT_PTR* out -> "sptr"
; Flags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "BluetoothApis.dll" #cfunc global BluetoothGATTRegisterEvent "BluetoothGATTRegisterEvent" sptr, int, sptr, sptr, sptr, var, int ; res = BluetoothGATTRegisterEvent(hService, EventType, EventParameterIn, Callback, CallbackContext, pEventHandle, Flags) ; hService : HANDLE -> "sptr" ; EventType : BTH_LE_GATT_EVENT_TYPE -> "int" ; EventParameterIn : void* -> "sptr" ; Callback : PFNBLUETOOTH_GATT_EVENT_CALLBACK -> "sptr" ; CallbackContext : void* optional -> "sptr" ; pEventHandle : INT_PTR* out -> "var" ; Flags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "BluetoothApis.dll" #cfunc global BluetoothGATTRegisterEvent "BluetoothGATTRegisterEvent" sptr, int, sptr, sptr, sptr, sptr, int ; res = BluetoothGATTRegisterEvent(hService, EventType, EventParameterIn, Callback, CallbackContext, varptr(pEventHandle), Flags) ; hService : HANDLE -> "sptr" ; EventType : BTH_LE_GATT_EVENT_TYPE -> "int" ; EventParameterIn : void* -> "sptr" ; Callback : PFNBLUETOOTH_GATT_EVENT_CALLBACK -> "sptr" ; CallbackContext : void* optional -> "sptr" ; pEventHandle : INT_PTR* out -> "sptr" ; Flags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT BluetoothGATTRegisterEvent(HANDLE hService, BTH_LE_GATT_EVENT_TYPE EventType, void* EventParameterIn, PFNBLUETOOTH_GATT_EVENT_CALLBACK Callback, void* CallbackContext, INT_PTR* pEventHandle, DWORD Flags) #uselib "BluetoothApis.dll" #cfunc global BluetoothGATTRegisterEvent "BluetoothGATTRegisterEvent" intptr, int, intptr, intptr, intptr, var, int ; res = BluetoothGATTRegisterEvent(hService, EventType, EventParameterIn, Callback, CallbackContext, pEventHandle, Flags) ; hService : HANDLE -> "intptr" ; EventType : BTH_LE_GATT_EVENT_TYPE -> "int" ; EventParameterIn : void* -> "intptr" ; Callback : PFNBLUETOOTH_GATT_EVENT_CALLBACK -> "intptr" ; CallbackContext : void* optional -> "intptr" ; pEventHandle : INT_PTR* out -> "var" ; Flags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT BluetoothGATTRegisterEvent(HANDLE hService, BTH_LE_GATT_EVENT_TYPE EventType, void* EventParameterIn, PFNBLUETOOTH_GATT_EVENT_CALLBACK Callback, void* CallbackContext, INT_PTR* pEventHandle, DWORD Flags) #uselib "BluetoothApis.dll" #cfunc global BluetoothGATTRegisterEvent "BluetoothGATTRegisterEvent" intptr, int, intptr, intptr, intptr, intptr, int ; res = BluetoothGATTRegisterEvent(hService, EventType, EventParameterIn, Callback, CallbackContext, varptr(pEventHandle), Flags) ; hService : HANDLE -> "intptr" ; EventType : BTH_LE_GATT_EVENT_TYPE -> "int" ; EventParameterIn : void* -> "intptr" ; Callback : PFNBLUETOOTH_GATT_EVENT_CALLBACK -> "intptr" ; CallbackContext : void* optional -> "intptr" ; pEventHandle : INT_PTR* out -> "intptr" ; Flags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
bluetoothapis = windows.NewLazySystemDLL("BluetoothApis.dll")
procBluetoothGATTRegisterEvent = bluetoothapis.NewProc("BluetoothGATTRegisterEvent")
)
// hService (HANDLE), EventType (BTH_LE_GATT_EVENT_TYPE), EventParameterIn (void*), Callback (PFNBLUETOOTH_GATT_EVENT_CALLBACK), CallbackContext (void* optional), pEventHandle (INT_PTR* out), Flags (DWORD)
r1, _, err := procBluetoothGATTRegisterEvent.Call(
uintptr(hService),
uintptr(EventType),
uintptr(EventParameterIn),
uintptr(Callback),
uintptr(CallbackContext),
uintptr(pEventHandle),
uintptr(Flags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction BluetoothGATTRegisterEvent(
hService: THandle; // HANDLE
EventType: Integer; // BTH_LE_GATT_EVENT_TYPE
EventParameterIn: Pointer; // void*
Callback: Pointer; // PFNBLUETOOTH_GATT_EVENT_CALLBACK
CallbackContext: Pointer; // void* optional
pEventHandle: Pointer; // INT_PTR* out
Flags: DWORD // DWORD
): Integer; stdcall;
external 'BluetoothApis.dll' name 'BluetoothGATTRegisterEvent';result := DllCall("BluetoothApis\BluetoothGATTRegisterEvent"
, "Ptr", hService ; HANDLE
, "Int", EventType ; BTH_LE_GATT_EVENT_TYPE
, "Ptr", EventParameterIn ; void*
, "Ptr", Callback ; PFNBLUETOOTH_GATT_EVENT_CALLBACK
, "Ptr", CallbackContext ; void* optional
, "Ptr", pEventHandle ; INT_PTR* out
, "UInt", Flags ; DWORD
, "Int") ; return: HRESULT●BluetoothGATTRegisterEvent(hService, EventType, EventParameterIn, Callback, CallbackContext, pEventHandle, Flags) = DLL("BluetoothApis.dll", "int BluetoothGATTRegisterEvent(void*, int, void*, void*, void*, void*, dword)")
# 呼び出し: BluetoothGATTRegisterEvent(hService, EventType, EventParameterIn, Callback, CallbackContext, pEventHandle, Flags)
# hService : HANDLE -> "void*"
# EventType : BTH_LE_GATT_EVENT_TYPE -> "int"
# EventParameterIn : void* -> "void*"
# Callback : PFNBLUETOOTH_GATT_EVENT_CALLBACK -> "void*"
# CallbackContext : void* optional -> "void*"
# pEventHandle : INT_PTR* out -> "void*"
# Flags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。