hidconf.cxx

来自「CE下串口复用程序」· CXX 代码 · 共 86 行

CXX
86
字号
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// This source code is licensed under Microsoft Shared Source License
// Version 1.0 for Windows CE.
// For a copy of the license visit http://go.microsoft.com/fwlink/?LinkId=3223.
//
#include <windows.h>

#include <svsutil.hxx>

#include <bt_debug.h>
#include <bt_os.h>
#include <bt_buffer.h>
#include <bt_ddi.h>
#include <bt_api.h>

#include "../base/hidconf.h"

int GetDeviceConfig (BD_ADDR *pba, DWORD *pdwFlags, unsigned char **ppsdp, unsigned int *pcsdp) {
	*pdwFlags = 0;
	*ppsdp = NULL;
	*pcsdp = 0;

	WCHAR szKeyName[MAX_PATH];
	wsprintf (szKeyName, L"software\\microsoft\\bluetooth\\device\\hid\\%04x%08x", pba->NAP, pba->SAP);

	HKEY hk;
	if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, szKeyName, 0, KEY_READ, &hk) != ERROR_SUCCESS)
		return FALSE;

	DWORD dwType = 0;
	DWORD dw = 0;
	DWORD cb = sizeof(dw);

	DWORD dwRes = ERROR_SUCCESS;
	
	dwRes = RegQueryValueEx (hk, L"active", NULL, &dwType, (LPBYTE)&dw, &cb);
	if ((dwRes == ERROR_SUCCESS) && (dwType == REG_DWORD) && (cb == sizeof(dw)) && dw)
		*pdwFlags |= HIDCONF_FLAGS_ACTIVE;

	dwType = 0;
	dw = 0;
	cb = sizeof(dw);

	dwRes = RegQueryValueEx (hk, L"auth", NULL, &dwType, (LPBYTE)&dw, &cb);
	if ((dwRes == ERROR_SUCCESS) && (dwType == REG_DWORD) && (cb == sizeof(dw)) && dw)
		*pdwFlags |= HIDCONF_FLAGS_AUTH;

	dwType = 0;
	dw = 0;
	cb = sizeof(dw);

	dwRes = RegQueryValueEx (hk, L"encrypt", NULL, &dwType, (LPBYTE)&dw, &cb);
	if ((dwRes == ERROR_SUCCESS) && (dwType == REG_DWORD) && (cb == sizeof(dw)) && dw)
		*pdwFlags |= HIDCONF_FLAGS_ENCRYPT;

	dwType = 0;
	cb = 0;

	dwRes = RegQueryValueEx (hk, L"sdp_record", NULL, &dwType, NULL, &cb);

	if (dwRes == ERROR_SUCCESS) {
		if (*ppsdp = (unsigned char *)g_funcAlloc (cb, g_pvAllocData))
			dwRes = RegQueryValueEx (hk, L"sdp_record", NULL, &dwType, *ppsdp, &cb);
	}

	RegCloseKey (hk);

	if ((dwRes != ERROR_SUCCESS) || (! *ppsdp)) {
		*pdwFlags = 0;

		if (*ppsdp) {
			g_funcFree (*ppsdp, g_pvFreeData);
			*ppsdp = NULL;
		}

		return FALSE;
	}

	*pcsdp = cb;

	return TRUE;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?