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

BluetoothSdpGetString

関数
SDPレコードから指定オフセットの文字列を取得する。
DLLBluetoothApis.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD BluetoothSdpGetString(
    BYTE* pRecordStream,
    DWORD cbRecordLength,
    const SDP_STRING_TYPE_DATA* pStringData,   // optional
    WORD usStringOffset,
    LPWSTR pszString,
    DWORD* pcchStringLength
);

パラメーター

名前方向説明
pRecordStreamBYTE*in文字列を取得する対象SDPレコードのバイトストリームへのポインタ。
cbRecordLengthDWORDinpRecordStreamのバイト長。
pStringDataSDP_STRING_TYPE_DATA*inoptional言語ベースのオフセット解決に用いる文字列型データ構造体ポインタ。NULL可。
usStringOffsetWORDin取得する文字列属性のベースオフセットを示す16ビット値。
pszStringLPWSTRout取得した文字列を受け取るワイド文字バッファ。NULLで必要サイズ照会。
pcchStringLengthDWORD*inout入力でバッファの文字数、出力で必要文字数を表すポインタ。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD BluetoothSdpGetString(
    BYTE* pRecordStream,
    DWORD cbRecordLength,
    const SDP_STRING_TYPE_DATA* pStringData,   // optional
    WORD usStringOffset,
    LPWSTR pszString,
    DWORD* pcchStringLength
);
[DllImport("BluetoothApis.dll", ExactSpelling = true)]
static extern uint BluetoothSdpGetString(
    IntPtr pRecordStream,   // BYTE*
    uint cbRecordLength,   // DWORD
    IntPtr pStringData,   // SDP_STRING_TYPE_DATA* optional
    ushort usStringOffset,   // WORD
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszString,   // LPWSTR out
    ref uint pcchStringLength   // DWORD* in/out
);
<DllImport("BluetoothApis.dll", ExactSpelling:=True)>
Public Shared Function BluetoothSdpGetString(
    pRecordStream As IntPtr,   ' BYTE*
    cbRecordLength As UInteger,   ' DWORD
    pStringData As IntPtr,   ' SDP_STRING_TYPE_DATA* optional
    usStringOffset As UShort,   ' WORD
    <MarshalAs(UnmanagedType.LPWStr)> pszString As System.Text.StringBuilder,   ' LPWSTR out
    ByRef pcchStringLength As UInteger   ' DWORD* in/out
) As UInteger
End Function
' pRecordStream : BYTE*
' cbRecordLength : DWORD
' pStringData : SDP_STRING_TYPE_DATA* optional
' usStringOffset : WORD
' pszString : LPWSTR out
' pcchStringLength : DWORD* in/out
Declare PtrSafe Function BluetoothSdpGetString Lib "bluetoothapis" ( _
    ByVal pRecordStream As LongPtr, _
    ByVal cbRecordLength As Long, _
    ByVal pStringData As LongPtr, _
    ByVal usStringOffset As Integer, _
    ByVal pszString As LongPtr, _
    ByRef pcchStringLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

BluetoothSdpGetString = ctypes.windll.bluetoothapis.BluetoothSdpGetString
BluetoothSdpGetString.restype = wintypes.DWORD
BluetoothSdpGetString.argtypes = [
    ctypes.POINTER(ctypes.c_ubyte),  # pRecordStream : BYTE*
    wintypes.DWORD,  # cbRecordLength : DWORD
    ctypes.c_void_p,  # pStringData : SDP_STRING_TYPE_DATA* optional
    ctypes.c_ushort,  # usStringOffset : WORD
    wintypes.LPWSTR,  # pszString : LPWSTR out
    ctypes.POINTER(wintypes.DWORD),  # pcchStringLength : DWORD* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('BluetoothApis.dll')
BluetoothSdpGetString = Fiddle::Function.new(
  lib['BluetoothSdpGetString'],
  [
    Fiddle::TYPE_VOIDP,  # pRecordStream : BYTE*
    -Fiddle::TYPE_INT,  # cbRecordLength : DWORD
    Fiddle::TYPE_VOIDP,  # pStringData : SDP_STRING_TYPE_DATA* optional
    -Fiddle::TYPE_SHORT,  # usStringOffset : WORD
    Fiddle::TYPE_VOIDP,  # pszString : LPWSTR out
    Fiddle::TYPE_VOIDP,  # pcchStringLength : DWORD* in/out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "bluetoothapis")]
extern "system" {
    fn BluetoothSdpGetString(
        pRecordStream: *mut u8,  // BYTE*
        cbRecordLength: u32,  // DWORD
        pStringData: *const SDP_STRING_TYPE_DATA,  // SDP_STRING_TYPE_DATA* optional
        usStringOffset: u16,  // WORD
        pszString: *mut u16,  // LPWSTR out
        pcchStringLength: *mut u32  // DWORD* in/out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("BluetoothApis.dll")]
public static extern uint BluetoothSdpGetString(IntPtr pRecordStream, uint cbRecordLength, IntPtr pStringData, ushort usStringOffset, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszString, ref uint pcchStringLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'BluetoothApis_BluetoothSdpGetString' -Namespace Win32 -PassThru
# $api::BluetoothSdpGetString(pRecordStream, cbRecordLength, pStringData, usStringOffset, pszString, pcchStringLength)
#uselib "BluetoothApis.dll"
#func global BluetoothSdpGetString "BluetoothSdpGetString" sptr, sptr, sptr, sptr, sptr, sptr
; BluetoothSdpGetString varptr(pRecordStream), cbRecordLength, varptr(pStringData), usStringOffset, varptr(pszString), varptr(pcchStringLength)   ; 戻り値は stat
; pRecordStream : BYTE* -> "sptr"
; cbRecordLength : DWORD -> "sptr"
; pStringData : SDP_STRING_TYPE_DATA* optional -> "sptr"
; usStringOffset : WORD -> "sptr"
; pszString : LPWSTR out -> "sptr"
; pcchStringLength : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "BluetoothApis.dll"
#cfunc global BluetoothSdpGetString "BluetoothSdpGetString" var, int, var, int, var, var
; res = BluetoothSdpGetString(pRecordStream, cbRecordLength, pStringData, usStringOffset, pszString, pcchStringLength)
; pRecordStream : BYTE* -> "var"
; cbRecordLength : DWORD -> "int"
; pStringData : SDP_STRING_TYPE_DATA* optional -> "var"
; usStringOffset : WORD -> "int"
; pszString : LPWSTR out -> "var"
; pcchStringLength : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD BluetoothSdpGetString(BYTE* pRecordStream, DWORD cbRecordLength, SDP_STRING_TYPE_DATA* pStringData, WORD usStringOffset, LPWSTR pszString, DWORD* pcchStringLength)
#uselib "BluetoothApis.dll"
#cfunc global BluetoothSdpGetString "BluetoothSdpGetString" var, int, var, int, var, var
; res = BluetoothSdpGetString(pRecordStream, cbRecordLength, pStringData, usStringOffset, pszString, pcchStringLength)
; pRecordStream : BYTE* -> "var"
; cbRecordLength : DWORD -> "int"
; pStringData : SDP_STRING_TYPE_DATA* optional -> "var"
; usStringOffset : WORD -> "int"
; pszString : LPWSTR out -> "var"
; pcchStringLength : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	bluetoothapis = windows.NewLazySystemDLL("BluetoothApis.dll")
	procBluetoothSdpGetString = bluetoothapis.NewProc("BluetoothSdpGetString")
)

// pRecordStream (BYTE*), cbRecordLength (DWORD), pStringData (SDP_STRING_TYPE_DATA* optional), usStringOffset (WORD), pszString (LPWSTR out), pcchStringLength (DWORD* in/out)
r1, _, err := procBluetoothSdpGetString.Call(
	uintptr(pRecordStream),
	uintptr(cbRecordLength),
	uintptr(pStringData),
	uintptr(usStringOffset),
	uintptr(pszString),
	uintptr(pcchStringLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function BluetoothSdpGetString(
  pRecordStream: Pointer;   // BYTE*
  cbRecordLength: DWORD;   // DWORD
  pStringData: Pointer;   // SDP_STRING_TYPE_DATA* optional
  usStringOffset: Word;   // WORD
  pszString: PWideChar;   // LPWSTR out
  pcchStringLength: Pointer   // DWORD* in/out
): DWORD; stdcall;
  external 'BluetoothApis.dll' name 'BluetoothSdpGetString';
result := DllCall("BluetoothApis\BluetoothSdpGetString"
    , "Ptr", pRecordStream   ; BYTE*
    , "UInt", cbRecordLength   ; DWORD
    , "Ptr", pStringData   ; SDP_STRING_TYPE_DATA* optional
    , "UShort", usStringOffset   ; WORD
    , "Ptr", pszString   ; LPWSTR out
    , "Ptr", pcchStringLength   ; DWORD* in/out
    , "UInt")   ; return: DWORD
●BluetoothSdpGetString(pRecordStream, cbRecordLength, pStringData, usStringOffset, pszString, pcchStringLength) = DLL("BluetoothApis.dll", "dword BluetoothSdpGetString(void*, dword, void*, int, char*, void*)")
# 呼び出し: BluetoothSdpGetString(pRecordStream, cbRecordLength, pStringData, usStringOffset, pszString, pcchStringLength)
# pRecordStream : BYTE* -> "void*"
# cbRecordLength : DWORD -> "dword"
# pStringData : SDP_STRING_TYPE_DATA* optional -> "void*"
# usStringOffset : WORD -> "int"
# pszString : LPWSTR out -> "char*"
# pcchStringLength : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "bluetoothapis" fn BluetoothSdpGetString(
    pRecordStream: [*c]u8, // BYTE*
    cbRecordLength: u32, // DWORD
    pStringData: [*c]SDP_STRING_TYPE_DATA, // SDP_STRING_TYPE_DATA* optional
    usStringOffset: u16, // WORD
    pszString: [*c]u16, // LPWSTR out
    pcchStringLength: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) u32;
proc BluetoothSdpGetString(
    pRecordStream: ptr uint8,  # BYTE*
    cbRecordLength: uint32,  # DWORD
    pStringData: ptr SDP_STRING_TYPE_DATA,  # SDP_STRING_TYPE_DATA* optional
    usStringOffset: uint16,  # WORD
    pszString: ptr uint16,  # LPWSTR out
    pcchStringLength: ptr uint32  # DWORD* in/out
): uint32 {.importc: "BluetoothSdpGetString", stdcall, dynlib: "BluetoothApis.dll".}
pragma(lib, "bluetoothapis");
extern(Windows)
uint BluetoothSdpGetString(
    ubyte* pRecordStream,   // BYTE*
    uint cbRecordLength,   // DWORD
    SDP_STRING_TYPE_DATA* pStringData,   // SDP_STRING_TYPE_DATA* optional
    ushort usStringOffset,   // WORD
    wchar* pszString,   // LPWSTR out
    uint* pcchStringLength   // DWORD* in/out
);
ccall((:BluetoothSdpGetString, "BluetoothApis.dll"), stdcall, UInt32,
      (Ptr{UInt8}, UInt32, Ptr{SDP_STRING_TYPE_DATA}, UInt16, Ptr{UInt16}, Ptr{UInt32}),
      pRecordStream, cbRecordLength, pStringData, usStringOffset, pszString, pcchStringLength)
# pRecordStream : BYTE* -> Ptr{UInt8}
# cbRecordLength : DWORD -> UInt32
# pStringData : SDP_STRING_TYPE_DATA* optional -> Ptr{SDP_STRING_TYPE_DATA}
# usStringOffset : WORD -> UInt16
# pszString : LPWSTR out -> Ptr{UInt16}
# pcchStringLength : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t BluetoothSdpGetString(
    uint8_t* pRecordStream,
    uint32_t cbRecordLength,
    void* pStringData,
    uint16_t usStringOffset,
    uint16_t* pszString,
    uint32_t* pcchStringLength);
]]
local bluetoothapis = ffi.load("bluetoothapis")
-- bluetoothapis.BluetoothSdpGetString(pRecordStream, cbRecordLength, pStringData, usStringOffset, pszString, pcchStringLength)
-- pRecordStream : BYTE*
-- cbRecordLength : DWORD
-- pStringData : SDP_STRING_TYPE_DATA* optional
-- usStringOffset : WORD
-- pszString : LPWSTR out
-- pcchStringLength : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('BluetoothApis.dll');
const BluetoothSdpGetString = lib.func('__stdcall', 'BluetoothSdpGetString', 'uint32_t', ['uint8_t *', 'uint32_t', 'void *', 'uint16_t', 'uint16_t *', 'uint32_t *']);
// BluetoothSdpGetString(pRecordStream, cbRecordLength, pStringData, usStringOffset, pszString, pcchStringLength)
// pRecordStream : BYTE* -> 'uint8_t *'
// cbRecordLength : DWORD -> 'uint32_t'
// pStringData : SDP_STRING_TYPE_DATA* optional -> 'void *'
// usStringOffset : WORD -> 'uint16_t'
// pszString : LPWSTR out -> 'uint16_t *'
// pcchStringLength : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("BluetoothApis.dll", {
  BluetoothSdpGetString: { parameters: ["pointer", "u32", "pointer", "u16", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.BluetoothSdpGetString(pRecordStream, cbRecordLength, pStringData, usStringOffset, pszString, pcchStringLength)
// pRecordStream : BYTE* -> "pointer"
// cbRecordLength : DWORD -> "u32"
// pStringData : SDP_STRING_TYPE_DATA* optional -> "pointer"
// usStringOffset : WORD -> "u16"
// pszString : LPWSTR out -> "buffer"
// pcchStringLength : DWORD* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t BluetoothSdpGetString(
    uint8_t* pRecordStream,
    uint32_t cbRecordLength,
    void* pStringData,
    uint16_t usStringOffset,
    uint16_t* pszString,
    uint32_t* pcchStringLength);
C, "BluetoothApis.dll");
// $ffi->BluetoothSdpGetString(pRecordStream, cbRecordLength, pStringData, usStringOffset, pszString, pcchStringLength);
// pRecordStream : BYTE*
// cbRecordLength : DWORD
// pStringData : SDP_STRING_TYPE_DATA* optional
// usStringOffset : WORD
// pszString : LPWSTR out
// pcchStringLength : DWORD* in/out
// 構造体/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 BluetoothSdpGetString(
        byte[] pRecordStream,   // BYTE*
        int cbRecordLength,   // DWORD
        Pointer pStringData,   // SDP_STRING_TYPE_DATA* optional
        short usStringOffset,   // WORD
        char[] pszString,   // LPWSTR out
        IntByReference pcchStringLength   // DWORD* in/out
    );
}
@[Link("bluetoothapis")]
lib LibBluetoothApis
  fun BluetoothSdpGetString = BluetoothSdpGetString(
    pRecordStream : UInt8*,   # BYTE*
    cbRecordLength : UInt32,   # DWORD
    pStringData : SDP_STRING_TYPE_DATA*,   # SDP_STRING_TYPE_DATA* optional
    usStringOffset : UInt16,   # WORD
    pszString : UInt16*,   # LPWSTR out
    pcchStringLength : UInt32*   # DWORD* in/out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef BluetoothSdpGetStringNative = Uint32 Function(Pointer<Uint8>, Uint32, Pointer<Void>, Uint16, Pointer<Utf16>, Pointer<Uint32>);
typedef BluetoothSdpGetStringDart = int Function(Pointer<Uint8>, int, Pointer<Void>, int, Pointer<Utf16>, Pointer<Uint32>);
final BluetoothSdpGetString = DynamicLibrary.open('BluetoothApis.dll')
    .lookupFunction<BluetoothSdpGetStringNative, BluetoothSdpGetStringDart>('BluetoothSdpGetString');
// pRecordStream : BYTE* -> Pointer<Uint8>
// cbRecordLength : DWORD -> Uint32
// pStringData : SDP_STRING_TYPE_DATA* optional -> Pointer<Void>
// usStringOffset : WORD -> Uint16
// pszString : LPWSTR out -> Pointer<Utf16>
// pcchStringLength : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function BluetoothSdpGetString(
  pRecordStream: Pointer;   // BYTE*
  cbRecordLength: DWORD;   // DWORD
  pStringData: Pointer;   // SDP_STRING_TYPE_DATA* optional
  usStringOffset: Word;   // WORD
  pszString: PWideChar;   // LPWSTR out
  pcchStringLength: Pointer   // DWORD* in/out
): DWORD; stdcall;
  external 'BluetoothApis.dll' name 'BluetoothSdpGetString';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "BluetoothSdpGetString"
  c_BluetoothSdpGetString :: Ptr Word8 -> Word32 -> Ptr () -> Word16 -> CWString -> Ptr Word32 -> IO Word32
-- pRecordStream : BYTE* -> Ptr Word8
-- cbRecordLength : DWORD -> Word32
-- pStringData : SDP_STRING_TYPE_DATA* optional -> Ptr ()
-- usStringOffset : WORD -> Word16
-- pszString : LPWSTR out -> CWString
-- pcchStringLength : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let bluetoothsdpgetstring =
  foreign "BluetoothSdpGetString"
    ((ptr uint8_t) @-> uint32_t @-> (ptr void) @-> uint16_t @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* pRecordStream : BYTE* -> (ptr uint8_t) *)
(* cbRecordLength : DWORD -> uint32_t *)
(* pStringData : SDP_STRING_TYPE_DATA* optional -> (ptr void) *)
(* usStringOffset : WORD -> uint16_t *)
(* pszString : LPWSTR out -> (ptr uint16_t) *)
(* pcchStringLength : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library bluetoothapis (t "BluetoothApis.dll"))
(cffi:use-foreign-library bluetoothapis)

(cffi:defcfun ("BluetoothSdpGetString" bluetooth-sdp-get-string :convention :stdcall) :uint32
  (p-record-stream :pointer)   ; BYTE*
  (cb-record-length :uint32)   ; DWORD
  (p-string-data :pointer)   ; SDP_STRING_TYPE_DATA* optional
  (us-string-offset :uint16)   ; WORD
  (psz-string :pointer)   ; LPWSTR out
  (pcch-string-length :pointer))   ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $BluetoothSdpGetString = Win32::API::More->new('BluetoothApis',
    'DWORD BluetoothSdpGetString(LPVOID pRecordStream, DWORD cbRecordLength, LPVOID pStringData, WORD usStringOffset, LPWSTR pszString, LPVOID pcchStringLength)');
# my $ret = $BluetoothSdpGetString->Call($pRecordStream, $cbRecordLength, $pStringData, $usStringOffset, $pszString, $pcchStringLength);
# pRecordStream : BYTE* -> LPVOID
# cbRecordLength : DWORD -> DWORD
# pStringData : SDP_STRING_TYPE_DATA* optional -> LPVOID
# usStringOffset : WORD -> WORD
# pszString : LPWSTR out -> LPWSTR
# pcchStringLength : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型