📄 btfilter.cxx
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/**
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
Abstract:
Windows CE Bluetooth application sample
**/
#include <windows.h>
#include <windows.h>
#include <stdio.h>
#include <svsutil.hxx>
#include <bt_api.h>
static void SetFilter (BT_ADDR *pba) {
DWORD iRes;
if (pba)
iRes = BthSetInquiryFilter (pba);
else
iRes = BthClearInquiryFilter ();
if (iRes == ERROR_SUCCESS)
wprintf (L"Successfully %s event filter.\n", pba ? L"set" : L"cleared");
else
wprintf (L"Failed to %s event filter. Error %d\n", pba ? L"set" : L"clear", iRes);
}
int GetBA (BT_ADDR *pba, WCHAR *p) {
while (*p == ' ')
++p;
for (int i = 0 ; i < 12 ; ++i, ++p) {
if (! iswxdigit (*p))
return FALSE;
int c = *p;
if (c >= 'a')
c = c - 'a' + 0xa;
else if (c >= 'A')
c = c - 'A' + 0xa;
else c = c - '0';
if ((c < 0) || (c > 16))
return FALSE;
*pba = *pba * 16 + c;
}
if ((*p != ' ') && (*p != '\0'))
return FALSE;
return TRUE;
}
int wmain (int argc, WCHAR **argv) {
BT_ADDR ba;
if (argc == 2) {
if (wcsicmp (argv[1], L"clear") == 0)
SetFilter (NULL);
else if (GetBA (&ba, argv[1]))
SetFilter (&ba);
else
wprintf (L"Command not understood. Available options: %s {clear|bluetooth address}\n", argv[0]);
return 0;
}
wprintf (L"Bluetooth inquiry filter.\n");
wprintf (L"Clear previous filter (y/n)?");
WCHAR szResponse[_MAX_PATH];
wscanf (L"%s", szResponse);
if ((szResponse[0] == 'y') || (szResponse[0] == 'Y'))
SetFilter (NULL);
wprintf (L"Set new filter (y/n)?");
wscanf (L"%s", szResponse);
if ((szResponse[0] == 'y') || (szResponse[0] == 'Y')) {
wprintf (L"Input Bluetooth address: ");
wscanf (L"%s", szResponse);
if (GetBA (&ba, szResponse))
SetFilter(&ba);
else
wprintf (L"Incorrect Bluetooth address %s\n", szResponse);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -