ホーム › 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)。const std = @import("std");
extern "bluetoothapis" fn BluetoothGATTRegisterEvent(
hService: ?*anyopaque, // HANDLE
EventType: i32, // BTH_LE_GATT_EVENT_TYPE
EventParameterIn: ?*anyopaque, // void*
Callback: ?*anyopaque, // PFNBLUETOOTH_GATT_EVENT_CALLBACK
CallbackContext: ?*anyopaque, // void* optional
pEventHandle: [*c]isize, // INT_PTR* out
Flags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc BluetoothGATTRegisterEvent(
hService: pointer, # HANDLE
EventType: int32, # BTH_LE_GATT_EVENT_TYPE
EventParameterIn: pointer, # void*
Callback: pointer, # PFNBLUETOOTH_GATT_EVENT_CALLBACK
CallbackContext: pointer, # void* optional
pEventHandle: ptr int, # INT_PTR* out
Flags: uint32 # DWORD
): int32 {.importc: "BluetoothGATTRegisterEvent", stdcall, dynlib: "BluetoothApis.dll".}pragma(lib, "bluetoothapis");
extern(Windows)
int BluetoothGATTRegisterEvent(
void* hService, // HANDLE
int EventType, // BTH_LE_GATT_EVENT_TYPE
void* EventParameterIn, // void*
void* Callback, // PFNBLUETOOTH_GATT_EVENT_CALLBACK
void* CallbackContext, // void* optional
ptrdiff_t* pEventHandle, // INT_PTR* out
uint Flags // DWORD
);ccall((:BluetoothGATTRegisterEvent, "BluetoothApis.dll"), stdcall, Int32,
(Ptr{Cvoid}, Int32, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Int}, UInt32),
hService, EventType, EventParameterIn, Callback, CallbackContext, pEventHandle, Flags)
# hService : HANDLE -> Ptr{Cvoid}
# EventType : BTH_LE_GATT_EVENT_TYPE -> Int32
# EventParameterIn : void* -> Ptr{Cvoid}
# Callback : PFNBLUETOOTH_GATT_EVENT_CALLBACK -> Ptr{Cvoid}
# CallbackContext : void* optional -> Ptr{Cvoid}
# pEventHandle : INT_PTR* out -> Ptr{Int}
# Flags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t BluetoothGATTRegisterEvent(
void* hService,
int32_t EventType,
void* EventParameterIn,
void* Callback,
void* CallbackContext,
intptr_t* pEventHandle,
uint32_t Flags);
]]
local bluetoothapis = ffi.load("bluetoothapis")
-- bluetoothapis.BluetoothGATTRegisterEvent(hService, EventType, EventParameterIn, Callback, CallbackContext, pEventHandle, Flags)
-- hService : HANDLE
-- EventType : BTH_LE_GATT_EVENT_TYPE
-- EventParameterIn : void*
-- Callback : PFNBLUETOOTH_GATT_EVENT_CALLBACK
-- CallbackContext : void* optional
-- pEventHandle : INT_PTR* out
-- Flags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('BluetoothApis.dll');
const BluetoothGATTRegisterEvent = lib.func('__stdcall', 'BluetoothGATTRegisterEvent', 'int32_t', ['void *', 'int32_t', 'void *', 'void *', 'void *', 'intptr_t *', 'uint32_t']);
// BluetoothGATTRegisterEvent(hService, EventType, EventParameterIn, Callback, CallbackContext, pEventHandle, Flags)
// hService : HANDLE -> 'void *'
// EventType : BTH_LE_GATT_EVENT_TYPE -> 'int32_t'
// EventParameterIn : void* -> 'void *'
// Callback : PFNBLUETOOTH_GATT_EVENT_CALLBACK -> 'void *'
// CallbackContext : void* optional -> 'void *'
// pEventHandle : INT_PTR* out -> 'intptr_t *'
// Flags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。const lib = Deno.dlopen("BluetoothApis.dll", {
BluetoothGATTRegisterEvent: { parameters: ["pointer", "i32", "pointer", "pointer", "pointer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.BluetoothGATTRegisterEvent(hService, EventType, EventParameterIn, Callback, CallbackContext, pEventHandle, Flags)
// hService : HANDLE -> "pointer"
// EventType : BTH_LE_GATT_EVENT_TYPE -> "i32"
// EventParameterIn : void* -> "pointer"
// Callback : PFNBLUETOOTH_GATT_EVENT_CALLBACK -> "pointer"
// CallbackContext : void* optional -> "pointer"
// pEventHandle : INT_PTR* out -> "pointer"
// Flags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t BluetoothGATTRegisterEvent(
void* hService,
int32_t EventType,
void* EventParameterIn,
void* Callback,
void* CallbackContext,
intptr_t* pEventHandle,
uint32_t Flags);
C, "BluetoothApis.dll");
// $ffi->BluetoothGATTRegisterEvent(hService, EventType, EventParameterIn, Callback, CallbackContext, pEventHandle, Flags);
// hService : HANDLE
// EventType : BTH_LE_GATT_EVENT_TYPE
// EventParameterIn : void*
// Callback : PFNBLUETOOTH_GATT_EVENT_CALLBACK
// CallbackContext : void* optional
// pEventHandle : INT_PTR* 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 BluetoothGATTRegisterEvent(
Pointer hService, // HANDLE
int EventType, // BTH_LE_GATT_EVENT_TYPE
Pointer EventParameterIn, // void*
Callback Callback, // PFNBLUETOOTH_GATT_EVENT_CALLBACK
Pointer CallbackContext, // void* optional
LongByReference pEventHandle, // INT_PTR* out
int Flags // DWORD
);
}@[Link("bluetoothapis")]
lib LibBluetoothApis
fun BluetoothGATTRegisterEvent = BluetoothGATTRegisterEvent(
hService : Void*, # HANDLE
EventType : Int32, # BTH_LE_GATT_EVENT_TYPE
EventParameterIn : Void*, # void*
Callback : Void*, # PFNBLUETOOTH_GATT_EVENT_CALLBACK
CallbackContext : Void*, # void* optional
pEventHandle : LibC::SSizeT*, # INT_PTR* 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 BluetoothGATTRegisterEventNative = Int32 Function(Pointer<Void>, Int32, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<IntPtr>, Uint32);
typedef BluetoothGATTRegisterEventDart = int Function(Pointer<Void>, int, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<IntPtr>, int);
final BluetoothGATTRegisterEvent = DynamicLibrary.open('BluetoothApis.dll')
.lookupFunction<BluetoothGATTRegisterEventNative, BluetoothGATTRegisterEventDart>('BluetoothGATTRegisterEvent');
// hService : HANDLE -> Pointer<Void>
// EventType : BTH_LE_GATT_EVENT_TYPE -> Int32
// EventParameterIn : void* -> Pointer<Void>
// Callback : PFNBLUETOOTH_GATT_EVENT_CALLBACK -> Pointer<Void>
// CallbackContext : void* optional -> Pointer<Void>
// pEventHandle : INT_PTR* out -> Pointer<IntPtr>
// Flags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function 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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "BluetoothGATTRegisterEvent"
c_BluetoothGATTRegisterEvent :: Ptr () -> Int32 -> Ptr () -> Ptr () -> Ptr () -> Ptr CIntPtr -> Word32 -> IO Int32
-- hService : HANDLE -> Ptr ()
-- EventType : BTH_LE_GATT_EVENT_TYPE -> Int32
-- EventParameterIn : void* -> Ptr ()
-- Callback : PFNBLUETOOTH_GATT_EVENT_CALLBACK -> Ptr ()
-- CallbackContext : void* optional -> Ptr ()
-- pEventHandle : INT_PTR* out -> Ptr CIntPtr
-- Flags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let bluetoothgattregisterevent =
foreign "BluetoothGATTRegisterEvent"
((ptr void) @-> int32_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr intptr_t) @-> uint32_t @-> returning int32_t)
(* hService : HANDLE -> (ptr void) *)
(* EventType : BTH_LE_GATT_EVENT_TYPE -> int32_t *)
(* EventParameterIn : void* -> (ptr void) *)
(* Callback : PFNBLUETOOTH_GATT_EVENT_CALLBACK -> (ptr void) *)
(* CallbackContext : void* optional -> (ptr void) *)
(* pEventHandle : INT_PTR* out -> (ptr intptr_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 ("BluetoothGATTRegisterEvent" bluetooth-gattregister-event :convention :stdcall) :int32
(h-service :pointer) ; HANDLE
(event-type :int32) ; BTH_LE_GATT_EVENT_TYPE
(event-parameter-in :pointer) ; void*
(callback :pointer) ; PFNBLUETOOTH_GATT_EVENT_CALLBACK
(callback-context :pointer) ; void* optional
(p-event-handle :pointer) ; INT_PTR* out
(flags :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $BluetoothGATTRegisterEvent = Win32::API::More->new('BluetoothApis',
'int BluetoothGATTRegisterEvent(HANDLE hService, int EventType, LPVOID EventParameterIn, LPVOID Callback, LPVOID CallbackContext, LPVOID pEventHandle, DWORD Flags)');
# my $ret = $BluetoothGATTRegisterEvent->Call($hService, $EventType, $EventParameterIn, $Callback, $CallbackContext, $pEventHandle, $Flags);
# hService : HANDLE -> HANDLE
# EventType : BTH_LE_GATT_EVENT_TYPE -> int
# EventParameterIn : void* -> LPVOID
# Callback : PFNBLUETOOTH_GATT_EVENT_CALLBACK -> LPVOID
# CallbackContext : void* optional -> LPVOID
# pEventHandle : INT_PTR* out -> LPVOID
# Flags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。