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

BluetoothSetServiceState

関数
Bluetoothデバイスの指定サービスを有効または無効にする。
DLLBluetoothApis.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// BluetoothApis.dll
#include <windows.h>

DWORD BluetoothSetServiceState(
    HANDLE hRadio,   // optional
    const BLUETOOTH_DEVICE_INFO* pbtdi,
    const GUID* pGuidService,
    DWORD dwServiceFlags
);

パラメーター

名前方向
hRadioHANDLEinoptional
pbtdiBLUETOOTH_DEVICE_INFO*in
pGuidServiceGUID*in
dwServiceFlagsDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

// BluetoothApis.dll
#include <windows.h>

DWORD BluetoothSetServiceState(
    HANDLE hRadio,   // optional
    const BLUETOOTH_DEVICE_INFO* pbtdi,
    const GUID* pGuidService,
    DWORD dwServiceFlags
);
[DllImport("BluetoothApis.dll", ExactSpelling = true)]
static extern uint BluetoothSetServiceState(
    IntPtr hRadio,   // HANDLE optional
    IntPtr pbtdi,   // BLUETOOTH_DEVICE_INFO*
    ref Guid pGuidService,   // GUID*
    uint dwServiceFlags   // DWORD
);
<DllImport("BluetoothApis.dll", ExactSpelling:=True)>
Public Shared Function BluetoothSetServiceState(
    hRadio As IntPtr,   ' HANDLE optional
    pbtdi As IntPtr,   ' BLUETOOTH_DEVICE_INFO*
    ByRef pGuidService As Guid,   ' GUID*
    dwServiceFlags As UInteger   ' DWORD
) As UInteger
End Function
' hRadio : HANDLE optional
' pbtdi : BLUETOOTH_DEVICE_INFO*
' pGuidService : GUID*
' dwServiceFlags : DWORD
Declare PtrSafe Function BluetoothSetServiceState Lib "bluetoothapis" ( _
    ByVal hRadio As LongPtr, _
    ByVal pbtdi As LongPtr, _
    ByVal pGuidService As LongPtr, _
    ByVal dwServiceFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

BluetoothSetServiceState = ctypes.windll.bluetoothapis.BluetoothSetServiceState
BluetoothSetServiceState.restype = wintypes.DWORD
BluetoothSetServiceState.argtypes = [
    wintypes.HANDLE,  # hRadio : HANDLE optional
    ctypes.c_void_p,  # pbtdi : BLUETOOTH_DEVICE_INFO*
    ctypes.c_void_p,  # pGuidService : GUID*
    wintypes.DWORD,  # dwServiceFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('BluetoothApis.dll')
BluetoothSetServiceState = Fiddle::Function.new(
  lib['BluetoothSetServiceState'],
  [
    Fiddle::TYPE_VOIDP,  # hRadio : HANDLE optional
    Fiddle::TYPE_VOIDP,  # pbtdi : BLUETOOTH_DEVICE_INFO*
    Fiddle::TYPE_VOIDP,  # pGuidService : GUID*
    -Fiddle::TYPE_INT,  # dwServiceFlags : DWORD
  ],
  -Fiddle::TYPE_INT)
#[link(name = "bluetoothapis")]
extern "system" {
    fn BluetoothSetServiceState(
        hRadio: *mut core::ffi::c_void,  // HANDLE optional
        pbtdi: *const BLUETOOTH_DEVICE_INFO,  // BLUETOOTH_DEVICE_INFO*
        pGuidService: *const GUID,  // GUID*
        dwServiceFlags: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("BluetoothApis.dll")]
public static extern uint BluetoothSetServiceState(IntPtr hRadio, IntPtr pbtdi, ref Guid pGuidService, uint dwServiceFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'BluetoothApis_BluetoothSetServiceState' -Namespace Win32 -PassThru
# $api::BluetoothSetServiceState(hRadio, pbtdi, pGuidService, dwServiceFlags)
#uselib "BluetoothApis.dll"
#func global BluetoothSetServiceState "BluetoothSetServiceState" sptr, sptr, sptr, sptr
; BluetoothSetServiceState hRadio, varptr(pbtdi), varptr(pGuidService), dwServiceFlags   ; 戻り値は stat
; hRadio : HANDLE optional -> "sptr"
; pbtdi : BLUETOOTH_DEVICE_INFO* -> "sptr"
; pGuidService : GUID* -> "sptr"
; dwServiceFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "BluetoothApis.dll"
#cfunc global BluetoothSetServiceState "BluetoothSetServiceState" sptr, var, var, int
; res = BluetoothSetServiceState(hRadio, pbtdi, pGuidService, dwServiceFlags)
; hRadio : HANDLE optional -> "sptr"
; pbtdi : BLUETOOTH_DEVICE_INFO* -> "var"
; pGuidService : GUID* -> "var"
; dwServiceFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD BluetoothSetServiceState(HANDLE hRadio, BLUETOOTH_DEVICE_INFO* pbtdi, GUID* pGuidService, DWORD dwServiceFlags)
#uselib "BluetoothApis.dll"
#cfunc global BluetoothSetServiceState "BluetoothSetServiceState" intptr, var, var, int
; res = BluetoothSetServiceState(hRadio, pbtdi, pGuidService, dwServiceFlags)
; hRadio : HANDLE optional -> "intptr"
; pbtdi : BLUETOOTH_DEVICE_INFO* -> "var"
; pGuidService : GUID* -> "var"
; dwServiceFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	bluetoothapis = windows.NewLazySystemDLL("BluetoothApis.dll")
	procBluetoothSetServiceState = bluetoothapis.NewProc("BluetoothSetServiceState")
)

// hRadio (HANDLE optional), pbtdi (BLUETOOTH_DEVICE_INFO*), pGuidService (GUID*), dwServiceFlags (DWORD)
r1, _, err := procBluetoothSetServiceState.Call(
	uintptr(hRadio),
	uintptr(pbtdi),
	uintptr(pGuidService),
	uintptr(dwServiceFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function BluetoothSetServiceState(
  hRadio: THandle;   // HANDLE optional
  pbtdi: Pointer;   // BLUETOOTH_DEVICE_INFO*
  pGuidService: PGUID;   // GUID*
  dwServiceFlags: DWORD   // DWORD
): DWORD; stdcall;
  external 'BluetoothApis.dll' name 'BluetoothSetServiceState';
result := DllCall("BluetoothApis\BluetoothSetServiceState"
    , "Ptr", hRadio   ; HANDLE optional
    , "Ptr", pbtdi   ; BLUETOOTH_DEVICE_INFO*
    , "Ptr", pGuidService   ; GUID*
    , "UInt", dwServiceFlags   ; DWORD
    , "UInt")   ; return: DWORD
●BluetoothSetServiceState(hRadio, pbtdi, pGuidService, dwServiceFlags) = DLL("BluetoothApis.dll", "dword BluetoothSetServiceState(void*, void*, void*, dword)")
# 呼び出し: BluetoothSetServiceState(hRadio, pbtdi, pGuidService, dwServiceFlags)
# hRadio : HANDLE optional -> "void*"
# pbtdi : BLUETOOTH_DEVICE_INFO* -> "void*"
# pGuidService : GUID* -> "void*"
# dwServiceFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。