static bool available(){
		bool res = false;
		HANDLE info;
		BLUETOOTH_FIND_RADIO_PARAMS params;
		params.dwSize = sizeof(params);
		HBLUETOOTH_RADIO_FIND find = BluetoothFindFirstRadio(&params, &info);
		if(find != 0) {
			res = true;
			CloseHandle(info);
		}
		BluetoothFindRadioClose(find);
		return res;
	}
Esempio n. 2
0
int _tmain(int argc, _TCHAR* argv[])
{
    while(true) {
        m_bt = BluetoothFindFirstRadio(&m_bt_find_radio, &m_radio);

        int m_radio_id = 0;
        do {
            m_radio_id++;

            BluetoothGetRadioInfo(m_radio, &m_bt_info);

            wprintf(L"Radio %d:\r\n", m_radio_id);
            wprintf(L"\tName: %s\r\n", m_bt_info.szName);
            wprintf(L"\tAddress: %02x:%02x:%02x:%02x:%02x:%02x\r\n", m_bt_info.address.rgBytes[1], m_bt_info.address.rgBytes[0], m_bt_info.address.rgBytes[2], m_bt_info.address.rgBytes[3], m_bt_info.address.rgBytes[4], m_bt_info.address.rgBytes[5]);
            wprintf(L"\tClass: 0x%08x\r\n", m_bt_info.ulClassofDevice);
            wprintf(L"\tManufacturer: 0x%04x\r\n", m_bt_info.manufacturer);

            m_search_params.hRadio = m_radio;

            ::ZeroMemory(&m_device_info, sizeof(BLUETOOTH_DEVICE_INFO));
            m_device_info.dwSize = sizeof(BLUETOOTH_DEVICE_INFO);

            m_bt_dev = BluetoothFindFirstDevice(&m_search_params, &m_device_info);

            int m_device_id = 0;
            do {
                m_device_id++;

                wprintf(L"\tDevice %d:\r\n", m_device_id);
                wprintf(L"\t\tName: %s\r\n", m_device_info.szName);
                wprintf(L"\t\tAddress: %02x:%02x:%02x:%02x:%02x:%02x\r\n", m_device_info.Address.rgBytes[1], m_device_info.Address.rgBytes[0], m_device_info.Address.rgBytes[2], m_device_info.Address.rgBytes[3], m_device_info.Address.rgBytes[4], m_device_info.Address.rgBytes[5]);
                wprintf(L"\t\tClass: 0x%08x\r\n", m_device_info.ulClassofDevice);
                wprintf(L"\t\tConnected: %s\r\n", m_device_info.fConnected ? L"true" : L"false");
                wprintf(L"\t\tAuthenticated: %s\r\n", m_device_info.fAuthenticated ? L"true" : L"false");
                wprintf(L"\t\tRemembered: %s\r\n", m_device_info.fRemembered ? L"true" : L"false");

            } while(BluetoothFindNextDevice(m_bt_dev, &m_device_info));

            BluetoothFindDeviceClose(m_bt_dev);

        } while(BluetoothFindNextRadio(&m_bt_find_radio, &m_radio));

        BluetoothFindRadioClose(m_bt);

        Sleep(10000);
    }

    return 0;
}
Esempio n. 3
0
HRESULT AbstractGattService::Initialize(
    _In_ IWDFDevice* pDevice,
    _In_ BthLEDevice * pBthLEDevice)
{
    HRESULT hr = S_OK;

    m_hEventSync = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (NULL == m_hEventSync)
    {
        hr = HRESULT_FROM_WIN32(GetLastError());
        CHECK_HR(hr, "Failed to create the queue sync event");
    }

    if (SUCCEEDED(hr))
    {
        hr = GetDeviceAddressFromDevice(pDevice, &m_BthDeviceAddress);
    }

    if (SUCCEEDED(hr))
    {
        m_pDevice = pDevice;
        m_pBthLEDevice = pBthLEDevice;

        HBLUETOOTH_RADIO_FIND hRadioFind = NULL;
        BLUETOOTH_FIND_RADIO_PARAMS frp = {sizeof(BLUETOOTH_FIND_RADIO_PARAMS)};

        hRadioFind = BluetoothFindFirstRadio(&frp, &m_hRadioHandle);
        if (NULL != hRadioFind) {
            BluetoothFindRadioClose(hRadioFind);
            hRadioFind = NULL;
        }

        if (NULL == m_hRadioHandle)
        {
            hr = E_FAIL;
            CHECK_HR(hr, "Failed to open a BT radio handle");
        }
    }

    if (SUCCEEDED(hr))
    {
        hr = StartMessagePump();
    }

    return hr;
}
static bool
find_first_bluetooth_radio(HANDLE *hRadio)
{
    bool success= false;
    assert(hRadio != nullptr);

    BLUETOOTH_FIND_RADIO_PARAMS radio_params;
    radio_params.dwSize = sizeof(BLUETOOTH_FIND_RADIO_PARAMS);

    HBLUETOOTH_RADIO_FIND hFind = BluetoothFindFirstRadio(&radio_params, hRadio);
    if (hFind) 
    {
        BluetoothFindRadioClose(hFind);
        success= true;
    }

    return success;
}
Esempio n. 5
0
int
windows_get_first_bluetooth_radio(HANDLE *hRadio)
{
    if (!hRadio) {
        return 1;
    }

    BLUETOOTH_FIND_RADIO_PARAMS radio_params;
    radio_params.dwSize = sizeof(BLUETOOTH_FIND_RADIO_PARAMS);

    HBLUETOOTH_RADIO_FIND hFind = BluetoothFindFirstRadio(&radio_params, hRadio);

    if (!hFind) {
        WINPAIR_DEBUG("Failed to enumerate Bluetooth radios");
        return 1;
    }

    BluetoothFindRadioClose(hFind);

    return 0;
}
Esempio n. 6
0
void *CVSCPBTDetectWrkTread::Entry()
{
    BLUETOOTH_FIND_RADIO_PARAMS bt_find_radio = {
        sizeof( BLUETOOTH_FIND_RADIO_PARAMS )
    };

    BLUETOOTH_RADIO_INFO bt_info = {
        sizeof( BLUETOOTH_RADIO_INFO ),
        0,
    };

    BLUETOOTH_DEVICE_SEARCH_PARAMS search_params = {
        sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS),
        1,
        0,
        1,
        1,
        1,
        1,  // Timeout
        NULL
    };

    BLUETOOTH_DEVICE_INFO device_info = {
        sizeof( BLUETOOTH_DEVICE_INFO ),
        0,
    };

    HANDLE radio = NULL;
    HBLUETOOTH_RADIO_FIND bt = NULL;
    HBLUETOOTH_DEVICE_FIND bt_dev = NULL;

    // First log on to the host and get configuration 
    // variables
    
    if ( VSCP_ERROR_SUCCESS != m_srv.doCmdOpen( m_pObj->m_host,
                                                    m_pObj->m_username,
                                                    m_pObj->m_password ) ) {
        return NULL;
    }

    // Find the channel id
    uint32_t ChannelID;
    m_srv.doCmdGetChannelID( &ChannelID );

    // It is possible that there is configuration data the server holds 
    // that we need to read in. 
    // We look for 
    //      prefix_period Seconds between scans.
    //      prefix_zone Zone to use for Token Activity
    //      prefix_subzone Subzone to use for Token Activity
    //      prefix_bsendtoken Send Token activity. Class=20 (Information, Type=37 
    //      prefix_bsenddetect Send detect event. Class=20 (Information), Type=49
    //      prefix_detectzone
    //      prefix_detectsubzone
    //
    //      Future defines.
    //      ===============
    //      prefix_onaddresses - List with addresses that will generate on-event
    //      prefix_offaddresses - List with addresses that will generate off-event

    bool bSendTokenActivity = true;     // Sending Token Activity is default behaviour.
    bool bSendDetect = false;           // Sending detect events must be enabled.
    uint16_t pausTime = 1;              // default svan period is one seconds.
    uint8_t zone = 0;                   // Zone for token activity.
    uint8_t subzone = 0;                // Subzone for token activity.
    uint8_t detectIndex = 0;            // Index used for detect event.
    uint8_t detectZone = 0;             // Zone used for detect event.
    uint8_t detectSubzone = 0;          // Subzone used for detect events.
    bool bDisableRadiodetect= false;    // Don't report radio discovery.

    wxString        strAddress;
    _deviceHash     deviceHashPrev;
    _deviceHash     deviceHashNow;
    CDetectedDevice *pDevice;

    int intvalue;
    bool bvalue;
    if ( VSCP_ERROR_SUCCESS == m_srv.getVariableInt( m_pObj->m_prefix + _( "_pausetime" ), &intvalue ) ) {
        if ( intvalue >= 0 ) pausTime = intvalue;
    }

    if ( VSCP_ERROR_SUCCESS == m_srv.getVariableInt( m_pObj->m_prefix + _( "_zone" ), &intvalue ) ) {
        zone = intvalue;
    }

    if ( VSCP_ERROR_SUCCESS == m_srv.getVariableInt( m_pObj->m_prefix + _( "_subzone" ), &intvalue ) ) {
        subzone = intvalue;
    }

    if ( VSCP_ERROR_SUCCESS == m_srv.getVariableInt( m_pObj->m_prefix + _( "_detectindex" ), &intvalue ) ) {
        detectIndex = intvalue;
    }

    if ( VSCP_ERROR_SUCCESS == m_srv.getVariableInt( m_pObj->m_prefix + _( "_detectzone" ), &intvalue ) ) {
        detectZone = intvalue;
    }

    if ( VSCP_ERROR_SUCCESS == m_srv.getVariableInt( m_pObj->m_prefix + _( "_detectsubzone" ), &intvalue ) ) {
        detectSubzone = intvalue;
    }

    if ( VSCP_ERROR_SUCCESS == m_srv.getVariableBool( m_pObj->m_prefix + _( "_send_token_activity" ), &bvalue ) ) {
        bSendTokenActivity = bvalue;
    }

    if ( VSCP_ERROR_SUCCESS == m_srv.getVariableBool( m_pObj->m_prefix + _( "_send_detect" ), &bvalue ) ) {
        bSendDetect = bvalue;
    }

    if ( VSCP_ERROR_SUCCESS == m_srv.getVariableBool( m_pObj->m_prefix + _( "_disable_radio_detect" ), &bvalue ) ) {
        bDisableRadiodetect = bvalue;
    }

    // Close the channel
    m_srv.doCmdClose();

    while ( !TestDestroy() && !m_pObj->m_bQuit ) {

        bt = BluetoothFindFirstRadio( &bt_find_radio, &radio );
    
        int radio_id = 0;
        do {

            radio_id++;

            if ( ERROR_SUCCESS == BluetoothGetRadioInfo( radio, &bt_info ) ) {

                strAddress.Printf( _("%02x:%02x:%02x:%02x:%02x:%02x"), 
                                        bt_info.address.rgBytes[ 0 ], 
                                        bt_info.address.rgBytes[ 1 ], 
                                        bt_info.address.rgBytes[ 2 ], 
                                        bt_info.address.rgBytes[ 3 ], 
                                        bt_info.address.rgBytes[ 4 ], 
                                        bt_info.address.rgBytes[ 5 ] );

                if ( deviceHashPrev.count( strAddress ) &&
                    ( NULL != ( pDevice = deviceHashPrev[ strAddress ] ) ) ) {
                    // Address is known and in the table 
                    pDevice->m_bfound = true;
                }
                else {

                    if ( !bDisableRadiodetect ) {

                        // Add the new device 
                        pDevice = new CDetectedDevice();
                        if ( NULL != pDevice ) {
                            pDevice->m_radio_id = radio_id;
                            pDevice->m_device_id = 0;
                            memcpy( pDevice->m_address, bt_info.address.rgBytes, 6 );
                            pDevice->m_name = bt_info.szName;
                            pDevice->m_class = bt_info.ulClassofDevice;
                            pDevice->m_manufacturer = bt_info.manufacturer;
                            deviceHashNow[ strAddress ] = pDevice;
                        }

                    }

                }

                search_params.hRadio = radio;

                ::ZeroMemory( &device_info, sizeof( BLUETOOTH_DEVICE_INFO ) );
                device_info.dwSize = sizeof( BLUETOOTH_DEVICE_INFO );

                if ( NULL != ( bt_dev = BluetoothFindFirstDevice( &search_params, &device_info ) ) ) {

                    int device_id = 0;
                    do {

                        device_id++;

                        strAddress.Printf( _("%02x:%02x:%02x:%02x:%02x:%02x"), 
                                                device_info.Address.rgBytes[ 0 ], 
                                                device_info.Address.rgBytes[ 1 ], 
                                                device_info.Address.rgBytes[ 2 ], 
                                                device_info.Address.rgBytes[ 3 ], 
                                                device_info.Address.rgBytes[ 4 ], 
                                                device_info.Address.rgBytes[ 5 ]);

                        if ( deviceHashPrev.count( strAddress ) &&
                                ( NULL != ( pDevice = deviceHashPrev[ strAddress ] ) ) ) {
                            // Address is known and in the table 
                            pDevice->m_bfound = true;
                        }
                        else {
                            
                            // Add the new device 
                            pDevice = new CDetectedDevice();
                            if ( NULL != pDevice ) {
                                pDevice->m_radio_id = radio_id;
                                pDevice->m_device_id = device_id;
                                memcpy( pDevice->m_address, device_info.Address.rgBytes, 6 );
                                pDevice->m_name = device_info.szName;
                                pDevice->m_class = device_info.ulClassofDevice;
                                memcpy( &pDevice->m_lastSeen, &device_info.stLastSeen, sizeof( SYSTEMTIME ) );
                                deviceHashNow[ strAddress ] = pDevice;
                            }   
                          
                        }

                    } while ( BluetoothFindNextDevice( bt_dev, &device_info ) );

                    BluetoothFindDeviceClose( bt_dev );
                }
            }

        } while ( BluetoothFindNextRadio( &bt_find_radio, &radio ) );

        BluetoothFindRadioClose( bt );

        // Go through devices that have been lost since last run
        
        _deviceHash::iterator itPrev;
        for ( itPrev = deviceHashPrev.begin(); itPrev != deviceHashPrev.end(); ++itPrev ) {

            wxString key = itPrev->first;
            CDetectedDevice *pDev = itPrev->second;
            if ( NULL == pDev ) {
                continue;
            }
            
            if ( false == pDev->m_bfound ) {

                if ( bSendTokenActivity ) {

                    vscpEventEx evx;

                    memset( evx.GUID, 0, 16 );   // Use interface GUID
                    evx.vscp_class = VSCP_CLASS2_LEVEL1_INFORMATION;
                    evx.vscp_type = VSCP_TYPE_INFORMATION_TOKEN_ACTIVITY;
                    evx.timestamp = wxDateTime::Now().GetTicks();
                    evx.head = VSCP_PRIORITY_NORMAL;
                    evx.sizeData = 8;
                    evx.data[ 0 ] = ( 18 << 2 ) + 2;   // Bluetooth device + "Released" 
                    evx.data[ 1 ] = zone;
                    evx.data[ 2 ] = subzone;
                    evx.data[ 3 ] = 0;               // Frame 0
                    evx.data[ 4 ] = pDev->m_address[ 0 ];
                    evx.data[ 5 ] = pDev->m_address[ 1 ];
                    evx.data[ 6 ] = pDev->m_address[ 2 ];
                    evx.data[ 7 ] = pDev->m_address[ 3 ];
   
                    sendEvent( evx ); // Send the event

                    memset( evx.GUID, 0, 16 );   // Use interface GUID
                    evx.vscp_class = VSCP_CLASS2_LEVEL1_INFORMATION;
                    evx.vscp_type = VSCP_TYPE_INFORMATION_TOKEN_ACTIVITY;
                    evx.timestamp = wxDateTime::Now().GetMillisecond();
                    evx.head = VSCP_PRIORITY_NORMAL;
                    evx.sizeData = 6;
                    evx.data[ 0 ] = ( 18 << 2 ) + 2;   // Bluetooth device + "Released" 
                    evx.data[ 1 ] = zone;
                    evx.data[ 2 ] = subzone;
                    evx.data[ 3 ] = 1;               // Frame 1
                    evx.data[ 4 ] = pDev->m_address[ 4 ];
                    evx.data[ 5 ] = pDev->m_address[ 5 ];

                    sendEvent( evx );

                }

                // Remove it
                delete pDev;
                deviceHashPrev[ key ] = NULL;

            }
            else {

                // Prepare for next detection loop
                pDev->m_bfound = false;

            }

        }

        // Go through devices that have been found since last run
        
        _deviceHash::iterator itNow;
        for ( itNow = deviceHashNow.begin(); itNow != deviceHashNow.end(); ++itNow ) {
            
            wxString key = itNow->first;
            CDetectedDevice *pDev = itNow->second;

            if ( NULL == pDev ) {
                continue;
            }

            // Save it in previously found devices
            deviceHashPrev[ key ] =  pDev;
            deviceHashNow[ key ] = NULL;

            if ( bSendTokenActivity ) {

                // Tell the world we found it
                vscpEventEx evx;

                memset( evx.GUID, 0, 16 );   // Use interface GUID
                evx.vscp_class = VSCP_CLASS2_LEVEL1_INFORMATION;
                evx.vscp_type = VSCP_TYPE_INFORMATION_TOKEN_ACTIVITY;
                evx.timestamp = wxDateTime::Now().GetMillisecond();
                evx.head = VSCP_PRIORITY_NORMAL;
                evx.sizeData = 8;
                evx.data[ 0 ] = ( 18 << 2 ) + 1;   // Bluetooth device + "Touched" 
                evx.data[ 1 ] = zone;
                evx.data[ 2 ] = subzone;
                evx.data[ 3 ] = 0;               // Frame 0
                evx.data[ 4 ] = pDev->m_address[ 0 ];
                evx.data[ 5 ] = pDev->m_address[ 1 ];
                evx.data[ 6 ] = pDev->m_address[ 2 ];
                evx.data[ 7 ] = pDev->m_address[ 3 ];

                sendEvent( evx );    // Send the event

                memset( evx.GUID, 0, 16 );   // Use interface GUID
                evx.vscp_class = VSCP_CLASS2_LEVEL1_INFORMATION;
                evx.vscp_type = VSCP_TYPE_INFORMATION_TOKEN_ACTIVITY;
                evx.timestamp = wxDateTime::Now().GetMillisecond();
                evx.head = VSCP_PRIORITY_NORMAL;
                evx.sizeData = 6;
                evx.data[ 0 ] = ( 18 << 2 ) + 1;   // Bluetooth device + "Touched" 
                evx.data[ 1 ] = zone;
                evx.data[ 2 ] = subzone;
                evx.data[ 3 ] = 1;               // Frame 1
                evx.data[ 4 ] = pDev->m_address[ 4 ];
                evx.data[ 5 ] = pDev->m_address[ 5 ];

                sendEvent( evx );    // Send the event
            
            }


            if ( bSendDetect ) {
            
                // Tell the world we detected it
                vscpEventEx evx;

                memset( evx.GUID, 0, 16 );   // Use interface GUID
                evx.vscp_class = VSCP_CLASS2_LEVEL1_INFORMATION;
                evx.vscp_type = VSCP_TYPE_INFORMATION_DETECT;
                evx.timestamp = wxDateTime::Now().GetMillisecond();
                evx.head = VSCP_PRIORITY_NORMAL;
                evx.sizeData = 3;
                evx.data[ 0 ] = detectIndex;
                evx.data[ 1 ] = detectZone;
                evx.data[ 2 ] = detectSubzone;

                sendEvent( evx );    // Send the event
            
            }       
            
        }

        wxSleep( pausTime );

    } // detect loop

    return NULL;  
}
Esempio n. 7
0
CString CDlgDialbox::EnumComPort() {
	CString sRtn = "";
	//161229 list bluetooth com port

	BLUETOOTH_FIND_RADIO_PARAMS btFindRadioParams = {sizeof(BLUETOOTH_FIND_RADIO_PARAMS)};
	BLUETOOTH_RADIO_INFO btRadioInfo = {sizeof(BLUETOOTH_RADIO_INFO), 0};
	BLUETOOTH_DEVICE_SEARCH_PARAMS btDeviceSearchParams = {
		sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS), 
		TRUE,	//BOOL fReturnAuthenticated;
		TRUE,	//BOOL fReturnRemembered;
		TRUE,	//BOOL fReturnUnknown;
		TRUE,	//BOOL fReturnConnected;
		FALSE,	//BOOL fIssueInquiry;
		10,		//UCHAR cTimeoutMultiplier;
		NULL	//HANDLE hRadio;
	};

	BLUETOOTH_DEVICE_INFO btDeviceInfo = {sizeof(BLUETOOTH_DEVICE_INFO), 0};

	HANDLE hRadio = NULL;
	HBLUETOOTH_DEVICE_FIND hbtDeviceFind = NULL;

	HBLUETOOTH_RADIO_FIND hbtRadioFind = BluetoothFindFirstRadio(&btFindRadioParams, &hRadio);
	if (hbtRadioFind) {
		do {
			if (BluetoothGetRadioInfo(hRadio, &btRadioInfo) == ERROR_SUCCESS) {
				btDeviceSearchParams.hRadio = hRadio;
				ZeroMemory(&btDeviceInfo, sizeof(BLUETOOTH_DEVICE_INFO));
				btDeviceInfo.dwSize = sizeof(BLUETOOTH_DEVICE_INFO);

				hbtDeviceFind = BluetoothFindFirstDevice(&btDeviceSearchParams, &btDeviceInfo);
				if (hbtDeviceFind) {
					do {
						CString sDeviceName(btDeviceInfo.szName);
						CString sAddr;
						sAddr.Format("%02x%02x%02x%02x%02x%02x", 
							btDeviceInfo.Address.rgBytes[5],btDeviceInfo.Address.rgBytes[4], btDeviceInfo.Address.rgBytes[3],
									btDeviceInfo.Address.rgBytes[2], btDeviceInfo.Address.rgBytes[1], btDeviceInfo.Address.rgBytes[0]);
						sAddr.MakeUpper();
						CString sComPort = GetBthComPort(sAddr);
						if (!sComPort.IsEmpty() && (sDeviceName.Find(BLUETOOTH_DEVICENAME_KEY) >= 0)) {
							sRtn += sComPort + "\r" + sDeviceName + "\r";
						}

					} while (BluetoothFindNextDevice(hbtDeviceFind, &btDeviceInfo));
				}
				BluetoothFindDeviceClose(hbtDeviceFind);
			}
			CloseHandle(hRadio);
		} while (BluetoothFindNextRadio(hbtRadioFind, &hRadio));
		BluetoothFindRadioClose(hbtRadioFind);
	}

	//list other serial ports
	HKEY hKey = NULL;
	TCHAR tcName[256];
	BYTE cData[256];
	DWORD dwNameBuffSize = sizeof(tcName);
	DWORD dwDataBuffSize = sizeof(cData);
	if (!RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("HARDWARE\\DEVICEMAP\\SERIALCOMM" ), NULL, KEY_READ, &hKey)) {
		int i = 0;
		while (RegEnumValue(hKey, i, tcName, &dwNameBuffSize, NULL, NULL, cData, &dwDataBuffSize) == ERROR_SUCCESS) {
			if (!strstr(tcName, "BthModem")) {
				CString sPortName;
				sPortName.Format("%s\r%s\r", (char*)cData, tcName);
				sRtn += sPortName;
			}
			dwNameBuffSize = sizeof(tcName);
			dwDataBuffSize = sizeof(cData);
			i++;
		}
	}
	return sRtn;
}
Esempio n. 8
0
BOOL CHWCApp::InitInstance()
{
	// InitCommonControlsEx() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// Set this to include all the common control classes you want to use
	// in your application.
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();

	if (!AfxSocketInit())
	{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}


	// Initialize OLE libraries
	if (!AfxOleInit())
	{
		AfxMessageBox(IDP_OLE_INIT_FAILED);
		return FALSE;
	}

	AfxEnableControlContainer();

	// Create the shell manager, in case the dialog contains
	// any shell tree view or shell list view controls.
	CShellManager *pShellManager = new CShellManager;

	// Activate "Windows Native" visual manager for enabling themes in MFC controls
	CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	// of your final executable, you should remove from the following
	// the specific initialization routines you do not need
	// Change the registry key under which our settings are stored
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

	SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);

	// Bluetooth is pluged in ???
	HANDLE hRadio = NULL;
	BLUETOOTH_FIND_RADIO_PARAMS btfrp = { sizeof(btfrp) };
	HBLUETOOTH_RADIO_FIND hFind = BluetoothFindFirstRadio(&btfrp, &hRadio);
	if (NULL == hFind || hRadio == NULL)
	{
		CString str, strTitle;
		str.LoadString(IDS_NO_BTH_RADIO);
		strTitle.LoadString(IDS_TITLE);
		::MessageBox(NULL, str, strTitle, MB_OK | MB_ICONERROR);
		BluetoothFindRadioClose(hFind);
		CloseHandle(hRadio);
		return FALSE;
	}
	BluetoothFindRadioClose(hFind);
	CloseHandle(hRadio);

	// Filter Driver Exist???
	CString RtkFilterDevPath = L"\\\\.\\BtFilter\\RCUTool";
	HANDLE hBtDeviceHandle = CreateFile(
		RtkFilterDevPath,  
		GENERIC_READ|GENERIC_WRITE,
		FILE_SHARE_READ | FILE_SHARE_WRITE,
		NULL,
		OPEN_EXISTING,
		FILE_FLAG_OVERLAPPED,
		NULL);
	if(hBtDeviceHandle == INVALID_HANDLE_VALUE)
	{// Filter Driver not exist
		CString str, strTitle;
		str.LoadString(IDS_NO_RTK_FLTDRIVER);
		strTitle.LoadString(IDS_TITLE);
		::MessageBox(NULL, str, strTitle, MB_OK | MB_ICONERROR);
		return FALSE;
	}
	CloseHandle(hBtDeviceHandle);

	CHWCDlg dlg;
	m_pMainWnd = &dlg;
	INT_PTR nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}
	else if (nResponse == -1)
	{
		TRACE(traceAppMsg, 0, "Warning: dialog creation failed, so application is terminating unexpectedly.\n");
		TRACE(traceAppMsg, 0, "Warning: if you are using MFC controls on the dialog, you cannot #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS.\n");
	}

	// Delete the shell manager created above.
	if (pShellManager != NULL)
	{
		delete pShellManager;
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}
Esempio n. 9
0
// Scan local network for visible remote devices
static VALUE bt_devices_scan(VALUE self)
{
    WORD wVersionRequested = 0x202;
    HANDLE hRadio;
    BLUETOOTH_FIND_RADIO_PARAMS btfrp = { sizeof(btfrp) };

    HBLUETOOTH_RADIO_FIND hFind = BluetoothFindFirstRadio( &btfrp, &hRadio );

    VALUE devices_array = rb_ary_new();
    if ( NULL != hFind )
    {
        do
        {
            BLUETOOTH_DEVICE_INFO_STRUCT deviceInfo;

            deviceInfo.dwSize = sizeof(deviceInfo);

            BLUETOOTH_DEVICE_SEARCH_PARAMS deviceSearchParams;

            memset(&deviceSearchParams, 0, sizeof(deviceSearchParams));

            deviceSearchParams.dwSize = sizeof(deviceSearchParams);

            deviceSearchParams.fReturnAuthenticated = true;
            deviceSearchParams.fReturnRemembered = false;
            deviceSearchParams.fReturnUnknown = true;
            deviceSearchParams.fReturnConnected = true;
            deviceSearchParams.fIssueInquiry = true;
            deviceSearchParams.cTimeoutMultiplier = 1;

            deviceSearchParams.hRadio = hRadio;

            HANDLE hDeviceFind = BluetoothFindFirstDevice(&deviceSearchParams, &deviceInfo);

            if (NULL != hDeviceFind)
            {
                do
                {
                    BYTE *rgBytes = deviceInfo.Address.rgBytes;
                    //BluetoothDisplayDeviceProperties(0, &deviceInfo);
                    char addr[19] = { 0 };
                    char name[248] = { 0 };
                    wcstombs(name, deviceInfo.szName, sizeof(name));

                    snprintf(addr, sizeof(addr), "%02x:%02x:%02x:%02x:%02x:%02x",
                             rgBytes[5],
                             rgBytes[4],
                             rgBytes[3],
                             rgBytes[2],
                             rgBytes[1],
                             rgBytes[0]);

                    VALUE bt_dev = bt_device_new(bt_device_class,
                                                 rb_str_new2(name),
                                                 rb_str_new2(addr));
                    rb_ary_push(devices_array, bt_dev);
                }
                while(BluetoothFindNextDevice(hDeviceFind, &deviceInfo));

                BluetoothFindDeviceClose(hDeviceFind);
            }

            GUID guidServices[10];

            DWORD numServices = sizeof(guidServices);

            DWORD result = BluetoothEnumerateInstalledServices(hRadio, &deviceInfo, &numServices, guidServices);

            CloseHandle( hRadio );
        } while( BluetoothFindNextRadio( hFind, &hRadio ) );

        BluetoothFindRadioClose( hFind );
    }

    return devices_array;

}
Esempio n. 10
0
BOOL CSpiCommApp::InitInstance()
{
	// InitCommonControlsEx() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// Set this to include all the common control classes you want to use
	// in your application.
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();

    CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	CSpiCommDlg dlg;

	// Lets check if BT is plugged in
	HANDLE hRadio = INVALID_HANDLE_VALUE;
	BLUETOOTH_FIND_RADIO_PARAMS params = {sizeof(BLUETOOTH_FIND_RADIO_PARAMS)};
	HBLUETOOTH_RADIO_FIND hf = BluetoothFindFirstRadio(&params, &hRadio);
	if (hf == NULL)
	{
		MessageBox(NULL, L"Bluetooth radio is not present or not functioning.  Please plug in the dongle and try again.", L"Error", MB_OK);
		return FALSE;
	}
    CloseHandle(hRadio);
    BluetoothFindRadioClose(hf);

	// This application supports Microsoft on Win8 or BTW on Win7.
	if (IsOSWin8())
	{
		dlg.m_bWin8 = TRUE;
        if ((hLib = LoadLibrary(L"BluetoothApis.dll")) == NULL)
		{
			MessageBox(NULL, L"Failed to load BluetoothAPIs library", L"Error", MB_OK);
			return FALSE;
		}
        guidSvcSpiComm                = GUID_SPI_COMM_SERVICE;
        guidCharSpiCommControlPoint   = GUID_SPI_COMM_CHARACTERISTIC_CONTROL_POINT;
        guidCharSpiCommData           = GUID_SPI_COMM_CHARACTERISTIC_DATA;
	}
	else if (IsOSWin7())
	{
		dlg.m_bWin8 = FALSE;

        if ((hLib = LoadLibrary(L"BtwLeApi.Dll")) == NULL)
		{
			MessageBox(NULL, L"Broadcom Blueototh profile pack for Windows (BTW) has to be installed", L"Error", MB_OK);
			return FALSE;
		}
        BtwGuidFromGuid(&guidSvcSpiComm, &GUID_SPI_COMM_SERVICE);
        BtwGuidFromGuid(&guidCharSpiCommControlPoint, &GUID_SPI_COMM_CHARACTERISTIC_CONTROL_POINT);
        BtwGuidFromGuid(&guidCharSpiCommData, &GUID_SPI_COMM_CHARACTERISTIC_DATA);
	}
	else
	{
		MessageBox(NULL, L"This application requires Windows 8 or Windows 7 with Broadcom Bluetooth profile pack for Windows (BTW) installed", L"Error", MB_OK);
		return FALSE;
	}

	// Activate "Windows Native" visual manager for enabling themes in MFC controls
	CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	// of your final executable, you should remove from the following
	// the specific initialization routines you do not need
	// Change the registry key under which our settings are stored
	SetRegistryKey(_T("Broadcom"));

	m_pMainWnd = &dlg;
	INT_PTR nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
	}
	else if (nResponse == IDCANCEL)
	{
	}
	else if (nResponse == -1)
	{
	}
    if (hLib != NULL)
        FreeLibrary(hLib);

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}