Win32 API 日本語リファレンス
ホームDevices.Bluetooth › BluetoothAuthenticateDevice

BluetoothAuthenticateDevice

関数
パスキーを用いてBluetoothデバイスを認証しペアリングする。
DLLbthprops.cpl呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// bthprops.cpl
#include <windows.h>

DWORD BluetoothAuthenticateDevice(
    HWND hwndParent,   // optional
    HANDLE hRadio,   // optional
    BLUETOOTH_DEVICE_INFO* pbtbi,
    LPWSTR pszPasskey,   // optional
    DWORD ulPasskeyLength
);

パラメーター

名前方向
hwndParentHWNDinoptional
hRadioHANDLEinoptional
pbtbiBLUETOOTH_DEVICE_INFO*inout
pszPasskeyLPWSTRinoptional
ulPasskeyLengthDWORDin

戻り値の型: 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 方式にも切替可。
出力引数:
; 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 方式にも切替可。
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   // DWORD
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';
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)。