春暖花开
雪化了,花开了,春天来了
posts - 149,comments - 125,trackbacks - 0

蓝牙无线电有打开、关闭、可发现三种状态,那么我们如何实现编程控制呢?

蓝牙设备的三种状态
enum BTH_RADIO_MODE {
  BTH_POWER_OFF,
  BTH_CONNECTABLE,
  BTH_DISCOVERABLE
};

API介绍
BthGetMode
作用
This function is used to retrieve the current mode of operation of the Bluetooth radio.
原型
int BthGetMode(DWORD* pdwMode);
返回值
Returns ERROR_SUCCESS on success or returns an error code on failure.

BthSetMode
作用
This function is used to set the Bluetooth mode of operation and reflect it in the control panel. This function is also used

to persist that state across hardware insertion and reboot.
原型
int BthSetMode(DWORD dwMode );
返回值
Returns ERROR_SUCCESS on success or returns an error code on failure.

环境
OS Versions: Windows CE .NET 4.2 and later
Header: Declared in bthutil.h
Library: Use bthutil.lib

代码示例
功能:获取蓝牙设备状态,如果设备状态是关闭的,则将其设为可发现。设置是否成功,给出提示。

第一步

首先需要添加头文件和库文件
#include <bthutil.h>
#pragma  comment(lib, "bthutil.lib")

第二步

获取蓝牙设备状态

DWORD bthState;
if (ERROR_SUCCESS == BthGetMode(&bthState))
{
    if (bthState == BTH_POWER_OFF)
    {
        if (ERROR_SUCCESS == BthSetMode(BTH_DISCOVERABLE))
        {
            MessageBox(NULL, _T("success"), _T("Note"), MB_OK);
        }
        else
        {
            MessageBox(NULL, _T("failed"), _T("Note"), MB_OK);
        }
    }
}

设置蓝牙状态是在模拟器上进行的,没有设置成功,这是由于模拟器上没有安装蓝牙设备造成的。


还需要继续学习。
posted on 2008-07-24 17:29 Sandy 阅读(969) 评论(0)  编辑 收藏 引用 所属分类: Window Mobile

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理