ホーム › Devices.Bluetooth › BluetoothAuthenticateDevice
BluetoothAuthenticateDevice
関数パスキーを用いてBluetoothデバイスを認証しペアリングする。
シグネチャ
// bthprops.cpl
#include <windows.h>
DWORD BluetoothAuthenticateDevice(
HWND hwndParent, // optional
HANDLE hRadio, // optional
BLUETOOTH_DEVICE_INFO* pbtbi,
LPWSTR pszPasskey, // optional
DWORD ulPasskeyLength
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hwndParent | HWND | inoptional | 認証UIダイアログの親ウィンドウハンドル。NULL可。 |
| hRadio | HANDLE | inoptional | 認証に用いるBluetoothラジオのハンドル。NULL可。 |
| pbtbi | BLUETOOTH_DEVICE_INFO* | inout | 認証対象デバイスの情報構造体ポインタ。 |
| pszPasskey | LPWSTR | inoptional | 認証に使用するパスキー文字列。NULLでUI入力を促す。 |
| ulPasskeyLength | DWORD | in | pszPasskeyの文字数。最大16。 |
戻り値の型: DWORD
各言語での呼び出し定義
// bthprops.cpl
#include <windows.h>
DWORD BluetoothAuthenticateDevice(
HWND hwndParent, // optional
HANDLE hRadio, // optional
BLUETOOTH_DEVICE_INFO* pbtbi,
LPWSTR pszPasskey, // optional
DWORD ulPasskeyLength
);[DllImport("bthprops.cpl", ExactSpelling = true)]
static extern uint BluetoothAuthenticateDevice(
IntPtr hwndParent, // HWND optional
IntPtr hRadio, // HANDLE optional
IntPtr pbtbi, // BLUETOOTH_DEVICE_INFO* in/out
[MarshalAs(UnmanagedType.LPWStr)] string pszPasskey, // LPWSTR optional
uint ulPasskeyLength // DWORD
);<DllImport("bthprops.cpl", ExactSpelling:=True)>
Public Shared Function BluetoothAuthenticateDevice(
hwndParent As IntPtr, ' HWND optional
hRadio As IntPtr, ' HANDLE optional
pbtbi As IntPtr, ' BLUETOOTH_DEVICE_INFO* in/out
<MarshalAs(UnmanagedType.LPWStr)> pszPasskey As String, ' LPWSTR optional
ulPasskeyLength As UInteger ' DWORD
) As UInteger
End Function' hwndParent : HWND optional
' hRadio : HANDLE optional
' pbtbi : BLUETOOTH_DEVICE_INFO* in/out
' pszPasskey : LPWSTR optional
' ulPasskeyLength : DWORD
Declare PtrSafe Function BluetoothAuthenticateDevice Lib "bthprops.cpl" ( _
ByVal hwndParent As LongPtr, _
ByVal hRadio As LongPtr, _
ByVal pbtbi As LongPtr, _
ByVal pszPasskey As LongPtr, _
ByVal ulPasskeyLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
BluetoothAuthenticateDevice = ctypes.windll.LoadLibrary("bthprops.cpl").BluetoothAuthenticateDevice
BluetoothAuthenticateDevice.restype = wintypes.DWORD
BluetoothAuthenticateDevice.argtypes = [
wintypes.HANDLE, # hwndParent : HWND optional
wintypes.HANDLE, # hRadio : HANDLE optional
ctypes.c_void_p, # pbtbi : BLUETOOTH_DEVICE_INFO* in/out
wintypes.LPCWSTR, # pszPasskey : LPWSTR optional
wintypes.DWORD, # ulPasskeyLength : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('bthprops.cpl')
BluetoothAuthenticateDevice = Fiddle::Function.new(
lib['BluetoothAuthenticateDevice'],
[
Fiddle::TYPE_VOIDP, # hwndParent : HWND optional
Fiddle::TYPE_VOIDP, # hRadio : HANDLE optional
Fiddle::TYPE_VOIDP, # pbtbi : BLUETOOTH_DEVICE_INFO* in/out
Fiddle::TYPE_VOIDP, # pszPasskey : LPWSTR optional
-Fiddle::TYPE_INT, # ulPasskeyLength : DWORD
],
-Fiddle::TYPE_INT)#[link(name = "bthprops.cpl")]
extern "system" {
fn BluetoothAuthenticateDevice(
hwndParent: *mut core::ffi::c_void, // HWND optional
hRadio: *mut core::ffi::c_void, // HANDLE optional
pbtbi: *mut BLUETOOTH_DEVICE_INFO, // BLUETOOTH_DEVICE_INFO* in/out
pszPasskey: *mut u16, // LPWSTR optional
ulPasskeyLength: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("bthprops.cpl")]
public static extern uint BluetoothAuthenticateDevice(IntPtr hwndParent, IntPtr hRadio, IntPtr pbtbi, [MarshalAs(UnmanagedType.LPWStr)] string pszPasskey, uint ulPasskeyLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'bthprops.cpl_BluetoothAuthenticateDevice' -Namespace Win32 -PassThru
# $api::BluetoothAuthenticateDevice(hwndParent, hRadio, pbtbi, pszPasskey, ulPasskeyLength)#uselib "bthprops.cpl"
#func global BluetoothAuthenticateDevice "BluetoothAuthenticateDevice" sptr, sptr, sptr, sptr, sptr
; BluetoothAuthenticateDevice hwndParent, hRadio, varptr(pbtbi), pszPasskey, ulPasskeyLength ; 戻り値は stat
; hwndParent : HWND optional -> "sptr"
; hRadio : HANDLE optional -> "sptr"
; pbtbi : BLUETOOTH_DEVICE_INFO* in/out -> "sptr"
; pszPasskey : LPWSTR optional -> "sptr"
; ulPasskeyLength : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "bthprops.cpl" #cfunc global BluetoothAuthenticateDevice "BluetoothAuthenticateDevice" sptr, sptr, var, wstr, int ; res = BluetoothAuthenticateDevice(hwndParent, hRadio, pbtbi, pszPasskey, ulPasskeyLength) ; hwndParent : HWND optional -> "sptr" ; hRadio : HANDLE optional -> "sptr" ; pbtbi : BLUETOOTH_DEVICE_INFO* in/out -> "var" ; pszPasskey : LPWSTR optional -> "wstr" ; ulPasskeyLength : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "bthprops.cpl" #cfunc global BluetoothAuthenticateDevice "BluetoothAuthenticateDevice" sptr, sptr, sptr, wstr, int ; res = BluetoothAuthenticateDevice(hwndParent, hRadio, varptr(pbtbi), pszPasskey, ulPasskeyLength) ; hwndParent : HWND optional -> "sptr" ; hRadio : HANDLE optional -> "sptr" ; pbtbi : BLUETOOTH_DEVICE_INFO* in/out -> "sptr" ; pszPasskey : LPWSTR optional -> "wstr" ; ulPasskeyLength : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD BluetoothAuthenticateDevice(HWND hwndParent, HANDLE hRadio, BLUETOOTH_DEVICE_INFO* pbtbi, LPWSTR pszPasskey, DWORD ulPasskeyLength) #uselib "bthprops.cpl" #cfunc global BluetoothAuthenticateDevice "BluetoothAuthenticateDevice" intptr, intptr, var, wstr, int ; res = BluetoothAuthenticateDevice(hwndParent, hRadio, pbtbi, pszPasskey, ulPasskeyLength) ; hwndParent : HWND optional -> "intptr" ; hRadio : HANDLE optional -> "intptr" ; pbtbi : BLUETOOTH_DEVICE_INFO* in/out -> "var" ; pszPasskey : LPWSTR optional -> "wstr" ; ulPasskeyLength : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD BluetoothAuthenticateDevice(HWND hwndParent, HANDLE hRadio, BLUETOOTH_DEVICE_INFO* pbtbi, LPWSTR pszPasskey, DWORD ulPasskeyLength) #uselib "bthprops.cpl" #cfunc global BluetoothAuthenticateDevice "BluetoothAuthenticateDevice" intptr, intptr, intptr, wstr, int ; res = BluetoothAuthenticateDevice(hwndParent, hRadio, varptr(pbtbi), pszPasskey, ulPasskeyLength) ; hwndParent : HWND optional -> "intptr" ; hRadio : HANDLE optional -> "intptr" ; pbtbi : BLUETOOTH_DEVICE_INFO* in/out -> "intptr" ; pszPasskey : LPWSTR optional -> "wstr" ; ulPasskeyLength : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
bthprops_cpl = windows.NewLazySystemDLL("bthprops.cpl")
procBluetoothAuthenticateDevice = bthprops_cpl.NewProc("BluetoothAuthenticateDevice")
)
// hwndParent (HWND optional), hRadio (HANDLE optional), pbtbi (BLUETOOTH_DEVICE_INFO* in/out), pszPasskey (LPWSTR optional), ulPasskeyLength (DWORD)
r1, _, err := procBluetoothAuthenticateDevice.Call(
uintptr(hwndParent),
uintptr(hRadio),
uintptr(pbtbi),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPasskey))),
uintptr(ulPasskeyLength),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction BluetoothAuthenticateDevice(
hwndParent: THandle; // HWND optional
hRadio: THandle; // HANDLE optional
pbtbi: Pointer; // BLUETOOTH_DEVICE_INFO* in/out
pszPasskey: PWideChar; // LPWSTR optional
ulPasskeyLength: DWORD // DWORD
): DWORD; stdcall;
external 'bthprops.cpl' name 'BluetoothAuthenticateDevice';result := DllCall("bthprops.cpl\BluetoothAuthenticateDevice"
, "Ptr", hwndParent ; HWND optional
, "Ptr", hRadio ; HANDLE optional
, "Ptr", pbtbi ; BLUETOOTH_DEVICE_INFO* in/out
, "WStr", pszPasskey ; LPWSTR optional
, "UInt", ulPasskeyLength ; DWORD
, "UInt") ; return: DWORD●BluetoothAuthenticateDevice(hwndParent, hRadio, pbtbi, pszPasskey, ulPasskeyLength) = DLL("bthprops.cpl", "dword BluetoothAuthenticateDevice(void*, void*, void*, char*, dword)")
# 呼び出し: BluetoothAuthenticateDevice(hwndParent, hRadio, pbtbi, pszPasskey, ulPasskeyLength)
# hwndParent : HWND optional -> "void*"
# hRadio : HANDLE optional -> "void*"
# pbtbi : BLUETOOTH_DEVICE_INFO* in/out -> "void*"
# pszPasskey : LPWSTR optional -> "char*"
# ulPasskeyLength : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "bthprops.cpl" fn BluetoothAuthenticateDevice(
hwndParent: ?*anyopaque, // HWND optional
hRadio: ?*anyopaque, // HANDLE optional
pbtbi: [*c]BLUETOOTH_DEVICE_INFO, // BLUETOOTH_DEVICE_INFO* in/out
pszPasskey: [*c]const u16, // LPWSTR optional
ulPasskeyLength: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;proc BluetoothAuthenticateDevice(
hwndParent: pointer, # HWND optional
hRadio: pointer, # HANDLE optional
pbtbi: ptr BLUETOOTH_DEVICE_INFO, # BLUETOOTH_DEVICE_INFO* in/out
pszPasskey: WideCString, # LPWSTR optional
ulPasskeyLength: uint32 # DWORD
): uint32 {.importc: "BluetoothAuthenticateDevice", stdcall, dynlib: "bthprops.cpl".}pragma(lib, "bthprops.cpl");
extern(Windows)
uint BluetoothAuthenticateDevice(
void* hwndParent, // HWND optional
void* hRadio, // HANDLE optional
BLUETOOTH_DEVICE_INFO* pbtbi, // BLUETOOTH_DEVICE_INFO* in/out
const(wchar)* pszPasskey, // LPWSTR optional
uint ulPasskeyLength // DWORD
);ccall((:BluetoothAuthenticateDevice, "bthprops.cpl"), stdcall, UInt32,
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{BLUETOOTH_DEVICE_INFO}, Cwstring, UInt32),
hwndParent, hRadio, pbtbi, pszPasskey, ulPasskeyLength)
# hwndParent : HWND optional -> Ptr{Cvoid}
# hRadio : HANDLE optional -> Ptr{Cvoid}
# pbtbi : BLUETOOTH_DEVICE_INFO* in/out -> Ptr{BLUETOOTH_DEVICE_INFO}
# pszPasskey : LPWSTR optional -> Cwstring
# ulPasskeyLength : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t BluetoothAuthenticateDevice(
void* hwndParent,
void* hRadio,
void* pbtbi,
const uint16_t* pszPasskey,
uint32_t ulPasskeyLength);
]]
local bthprops.cpl = ffi.load("bthprops.cpl")
-- bthprops.cpl.BluetoothAuthenticateDevice(hwndParent, hRadio, pbtbi, pszPasskey, ulPasskeyLength)
-- hwndParent : HWND optional
-- hRadio : HANDLE optional
-- pbtbi : BLUETOOTH_DEVICE_INFO* in/out
-- pszPasskey : LPWSTR optional
-- ulPasskeyLength : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('bthprops.cpl');
const BluetoothAuthenticateDevice = lib.func('__stdcall', 'BluetoothAuthenticateDevice', 'uint32_t', ['void *', 'void *', 'void *', 'str16', 'uint32_t']);
// BluetoothAuthenticateDevice(hwndParent, hRadio, pbtbi, pszPasskey, ulPasskeyLength)
// hwndParent : HWND optional -> 'void *'
// hRadio : HANDLE optional -> 'void *'
// pbtbi : BLUETOOTH_DEVICE_INFO* in/out -> 'void *'
// pszPasskey : LPWSTR optional -> 'str16'
// ulPasskeyLength : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("bthprops.cpl", {
BluetoothAuthenticateDevice: { parameters: ["pointer", "pointer", "pointer", "buffer", "u32"], result: "u32" },
});
// lib.symbols.BluetoothAuthenticateDevice(hwndParent, hRadio, pbtbi, pszPasskey, ulPasskeyLength)
// hwndParent : HWND optional -> "pointer"
// hRadio : HANDLE optional -> "pointer"
// pbtbi : BLUETOOTH_DEVICE_INFO* in/out -> "pointer"
// pszPasskey : LPWSTR optional -> "buffer"
// ulPasskeyLength : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t BluetoothAuthenticateDevice(
void* hwndParent,
void* hRadio,
void* pbtbi,
const uint16_t* pszPasskey,
uint32_t ulPasskeyLength);
C, "bthprops.cpl");
// $ffi->BluetoothAuthenticateDevice(hwndParent, hRadio, pbtbi, pszPasskey, ulPasskeyLength);
// hwndParent : HWND optional
// hRadio : HANDLE optional
// pbtbi : BLUETOOTH_DEVICE_INFO* in/out
// pszPasskey : LPWSTR optional
// ulPasskeyLength : 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 Bthprops.cpl extends StdCallLibrary {
Bthprops.cpl INSTANCE = Native.load("bthprops.cpl", Bthprops.cpl.class);
int BluetoothAuthenticateDevice(
Pointer hwndParent, // HWND optional
Pointer hRadio, // HANDLE optional
Pointer pbtbi, // BLUETOOTH_DEVICE_INFO* in/out
WString pszPasskey, // LPWSTR optional
int ulPasskeyLength // DWORD
);
}@[Link("bthprops.cpl")]
lib Libbthprops.cpl
fun BluetoothAuthenticateDevice = BluetoothAuthenticateDevice(
hwndParent : Void*, # HWND optional
hRadio : Void*, # HANDLE optional
pbtbi : BLUETOOTH_DEVICE_INFO*, # BLUETOOTH_DEVICE_INFO* in/out
pszPasskey : UInt16*, # LPWSTR optional
ulPasskeyLength : UInt32 # DWORD
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef BluetoothAuthenticateDeviceNative = Uint32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Uint32);
typedef BluetoothAuthenticateDeviceDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Utf16>, int);
final BluetoothAuthenticateDevice = DynamicLibrary.open('bthprops.cpl')
.lookupFunction<BluetoothAuthenticateDeviceNative, BluetoothAuthenticateDeviceDart>('BluetoothAuthenticateDevice');
// hwndParent : HWND optional -> Pointer<Void>
// hRadio : HANDLE optional -> Pointer<Void>
// pbtbi : BLUETOOTH_DEVICE_INFO* in/out -> Pointer<Void>
// pszPasskey : LPWSTR optional -> Pointer<Utf16>
// ulPasskeyLength : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function BluetoothAuthenticateDevice(
hwndParent: THandle; // HWND optional
hRadio: THandle; // HANDLE optional
pbtbi: Pointer; // BLUETOOTH_DEVICE_INFO* in/out
pszPasskey: PWideChar; // LPWSTR optional
ulPasskeyLength: DWORD // DWORD
): DWORD; stdcall;
external 'bthprops.cpl' name 'BluetoothAuthenticateDevice';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "BluetoothAuthenticateDevice"
c_BluetoothAuthenticateDevice :: Ptr () -> Ptr () -> Ptr () -> CWString -> Word32 -> IO Word32
-- hwndParent : HWND optional -> Ptr ()
-- hRadio : HANDLE optional -> Ptr ()
-- pbtbi : BLUETOOTH_DEVICE_INFO* in/out -> Ptr ()
-- pszPasskey : LPWSTR optional -> CWString
-- ulPasskeyLength : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let bluetoothauthenticatedevice =
foreign "BluetoothAuthenticateDevice"
((ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr uint16_t) @-> uint32_t @-> returning uint32_t)
(* hwndParent : HWND optional -> (ptr void) *)
(* hRadio : HANDLE optional -> (ptr void) *)
(* pbtbi : BLUETOOTH_DEVICE_INFO* in/out -> (ptr void) *)
(* pszPasskey : LPWSTR optional -> (ptr uint16_t) *)
(* ulPasskeyLength : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library bthprops.cpl (t "bthprops.cpl"))
(cffi:use-foreign-library bthprops.cpl)
(cffi:defcfun ("BluetoothAuthenticateDevice" bluetooth-authenticate-device :convention :stdcall) :uint32
(hwnd-parent :pointer) ; HWND optional
(h-radio :pointer) ; HANDLE optional
(pbtbi :pointer) ; BLUETOOTH_DEVICE_INFO* in/out
(psz-passkey (:string :encoding :utf-16le)) ; LPWSTR optional
(ul-passkey-length :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $BluetoothAuthenticateDevice = Win32::API::More->new('bthprops.cpl',
'DWORD BluetoothAuthenticateDevice(HANDLE hwndParent, HANDLE hRadio, LPVOID pbtbi, LPCWSTR pszPasskey, DWORD ulPasskeyLength)');
# my $ret = $BluetoothAuthenticateDevice->Call($hwndParent, $hRadio, $pbtbi, $pszPasskey, $ulPasskeyLength);
# hwndParent : HWND optional -> HANDLE
# hRadio : HANDLE optional -> HANDLE
# pbtbi : BLUETOOTH_DEVICE_INFO* in/out -> LPVOID
# pszPasskey : LPWSTR optional -> LPCWSTR
# ulPasskeyLength : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f BluetoothAuthenticateDeviceEx — 認証要件を指定してBluetoothデバイスを認証する。