C++ BluetoothSelectDevices是否包含MS错误?

C++ BluetoothSelectDevices是否包含MS错误?,c++,winapi,bluetooth,visual-c++-2008,C++,Winapi,Bluetooth,Visual C++ 2008,因此,我将应用程序中不可预知的崩溃缩小到BluetoothSelectDevices功能。它应该允许用户选择设备 #include <windows.h> #include <Bthsdpdef.h> #include <BluetoothAPIs.h> #pragma comment(lib, "bthprops") #pragma comment(lib, "user32") bool getDevice(void) { BLUETOOTH_SE

因此,我将应用程序中不可预知的崩溃缩小到BluetoothSelectDevices功能。它应该允许用户选择设备

#include <windows.h>
#include <Bthsdpdef.h>
#include <BluetoothAPIs.h>
#pragma comment(lib, "bthprops")
#pragma comment(lib, "user32")

bool getDevice(void)
{
    BLUETOOTH_SELECT_DEVICE_PARAMS btsdp = { sizeof(btsdp) };

    btsdp.hwndParent = NULL; // hDlg; // "set to NULL for no parent."
    btsdp.fShowUnknown = TRUE;
//  btsdp.fAddNewDeviceWizard = TRUE;
    btsdp.fShowAuthenticated = TRUE;

    BOOL b = BluetoothSelectDevices( &btsdp );
    if ( b )
    {
//         BLUETOOTH_DEVICE_INFO * pbtdi = btsdp.pDevices;
//         for ( ULONG cDevice = 0; cDevice < btsdp.cNumDevices; cDevice ++ )
//         {
//             if ( pbtdi->fAuthenticated || pbtdi->fRemembered )
//             {
//                 //
//                 //  TODO:      Do something usefull with the device info
//                 //
//             }
//
//             pbtdi = (BLUETOOTH_DEVICE_INFO *) ((LPBYTE)pbtdi + pbtdi->dwSize);
//         }

        BluetoothSelectDevicesFree( &btsdp );
    }
    else
    {
        if (GetLastError() != ERROR_CANCELLED)
            MessageBox(NULL, "BluetoothSelectDevices failed.", "Error", MB_OK);
        return false;
    }

    return true;
}
int main(void){for (int i = 0; i < 10 && getDevice(); i++);return 0;}

谢谢。

你认为把整个结构设为0是其初始化的第一步吗?阿列克谢,谢谢你的建议。是的,我试过了,还是一样。
memset(&btsdp, 0, sizeof(btsdp));
btsdp.dwSize = sizeof(BLUETOOTH_SELECT_DEVICE_PARAMS);
btsdp.cNumOfClasses = 0; // search for all devices
btsdp.prgClassOfDevices = NULL;
btsdp.pszInfo = L"Select Device..";
btsdp.hwndParent = NULL;
btsdp.fForceAuthentication = FALSE;
btsdp.fShowAuthenticated = TRUE;
btsdp.fShowRemembered = TRUE;
btsdp.fShowUnknown = TRUE;
btsdp.fAddNewDeviceWizard = FALSE;
btsdp.fSkipServicesPage = FALSE;
btsdp.pfnDeviceCallback = NULL; // no callback
btsdp.pvParam = NULL;
btsdp.cNumDevices = 0; // no limit
btsdp.pDevices = NULL;