c++ /WIN32 (XP)蓝牙设备名称更改
C++/WIN32 (XP) Bluetooth device name change
有人知道如何以编程方式更改蓝牙设备名称吗?或者设备名称存储在哪里?
已解决
这是封装在类方法中的现成解决方案。
bool CBluetooth::ChangeLocalRadioName(LPTSTR newName)
{
LPTSTR instanceID = GetGenericBluetoothAdapterInstanceID();
if (instanceID == NULL)
{
//_tprintf(_TEXT("Failed to get Generic Bluetooth Adapter InstanceIDn"));
return false;
}
LPTSTR instanceIDModified = new TCHAR[_tcslen(instanceID)];
_tcscpy(instanceIDModified, instanceID);
find_and_replace(instanceIDModified, _TEXT("\"), _TEXT("#"));
HANDLE hDevice;
TCHAR fileName[1024] = { 0 };
_tcscpy(fileName, _TEXT("\\.\"));
_tcscat(fileName, instanceIDModified);
_tcscat(fileName, _TEXT("#{a5dcbf10-6530-11d2-901f-00c04fb951ed}"));
hDevice = CreateFile(fileName, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == INVALID_HANDLE_VALUE)
{
//_tprintf(_TEXT("Failed to open device. Error code: %dn"), GetLastError());
return false;
}
//Change radio module local name in registry
LPTSTR RMLocalName = newName;
CHAR bufRMLocalName[256];
HKEY hKey;
TCHAR rmLocalNameKey[1024] = { 0 };
LSTATUS ret;
_tcscpy(rmLocalNameKey, _TEXT("SYSTEM\ControlSet001\Enum\"));
_tcscat(rmLocalNameKey, instanceID);
_tcscat(rmLocalNameKey, _TEXT("\Device Parameters"));
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, rmLocalNameKey,
0L, KEY_SET_VALUE , &hKey);
if(ret != ERROR_SUCCESS)
{
//_tprintf(TEXT("Failed to open registry key. Error code: %dn"), ret);
return false;
}
ret = RegSetValueEx(hKey, _TEXT("Local Name"), 0, REG_BINARY,
(LPBYTE)RMLocalName,strlen(RMLocalName));
if (ret != ERROR_SUCCESS)
{
//_tprintf(TEXT("Failed to set registry key. Error code: %dn"), ret);
return false;
}
RegCloseKey(hKey);
// This check decides what IO control code to use based on if we're in XP or Vista (and later).
OSVERSIONINFO osver;
osver.dwOSVersionInfoSize = sizeof(osver);
GetVersionEx(&osver);
UINT ctlCode = (UINT)(6 > osver.dwMajorVersion ? 0x220fd4 : 0x411008);
long reload = 4; // tells the control function to reset or reload or similar...
DWORD bytes = 0; // merely a placeholder
// Send radio module driver command to update device information
if (!DeviceIoControl(hDevice, ctlCode, &reload, 4, NULL, 0, &bytes, NULL))
{
//_tprintf(TEXT("Failed to update radio module local name. Error code: %dn"), GetLastError());
return false;
}
return true;
}
Thanks to: clusterter
相关文章:
- 正在查找文档以获得PS4平台的C++中的设备信息
- 你能重载对象变量名本身返回的内容吗
- Win32编译器选项和内存分配
- 指向设备对象成员的指针
- VSOMEIP-2个设备之间的通信(TCP/UDP)不工作
- 有没有一种方法可以在编译时获得作用域类名
- Cuda C++:设备上的Malloc类,并用来自主机的数据填充它
- 是否可以使用winusb同时与多个相同的usb设备进行通信
- 将依赖名称显式标记为类型名和模板的奇怪之处
- 在C/C++中将变量名定义为__00000001有什么好处吗
- 函数名是c中该函数的第一条指令的地址吗
- 为什么cudaMemGetInfo报告设备内存总量的变化
- C++win32 API创建多个类似视口的窗口
- Win32设备事件:在DBT_DEVICEARIVAL事件上未接收到DBT_DEVTYP_VOLUME
- 从 FlasCC(又名 Crossbridge)访问 Win32 API
- Win32从设备上下文到文件和/或BLOB创建位图
- 列出Win32设备命名空间的内容
- 使用libusb win32列出USB设备
- 从USB设备的设备路径获取卷名
- c++ /WIN32 (XP)蓝牙设备名称更改