Question

I'm trying to call IOCTL_BTH_GET_LOCAL_INFO using DeviceIoControl, which I believe it can be done (accordingly to Bluetooth Profile Driver IOCTLs).

I'm on a Windows 7 x64 using Visual Studio 2012 (probably with default configuration).

The handle have a valid value (I removed the validation code) but DeviceIoControl always returns ERROR_INVALID_USER_BUFFER (error 1784).

Here's the code:

int main() {

    BTH_LOCAL_RADIO_INFO buffer;
    BOOL fStatus;
    HANDLE h;
    DWORD returned = 0;

    h = CreateFile(
        TEXT("\\\\.\\BthPan"), 
        GENERIC_READ | GENERIC_WRITE ,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL, 
        OPEN_EXISTING,
        0,
        NULL);


    fStatus = DeviceIoControl(
            h, 
            IOCTL_BTH_GET_LOCAL_INFO,
            NULL, 0,
            (LPVOID)&buffer, sizeof(BTH_LOCAL_RADIO_INFO),
            &returned,
            (LPOVERLAPPED) NULL
            );   
(...)

After some research I tried the following solutions:

  1. Changing the structure pack alignment to 1/4/8 byte (with VS options);
  2. Using values which are 8-byte aligned (later I've found out that this was already happening, even with data types smaller than 8 bytes). After a while I've read somewhere that DeviceIoControl deals with misaligment for you, so probably no need to worry about that.

All of the solutions above have failed. What do you think it is? VS have a bunch of configurations for Win32, but that never gave me a problem before (first time with IOCTL though).

I've seen some of that code on 32feet.NET, so probably it's just an error of mine (I can't see any difference).

Était-ce utile?

La solution

You're sending IOCTL_BTH_GET_LOCAL_INFO to the wrong device (Bluetooth Personal Area Network instead of Bluetooth Radio).

So I suggest you to use BluetoothFindFirstRadio, BluetoothFindNextRadio and BluetoothFindRadioClose to simply iterate through local Bluetooth radios, rather than to guess the correct DOS Device Names for them.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top