Skip to content

Windows注册表查询以及通过注册表查询串口设备

License

Notifications You must be signed in to change notification settings

MisakaMikoto128/WinRegister

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WinRegister

Windows注册表查询以及通过注册表查询串口设备

使用

查找注册表键值对

_T等同于TEXT, _T("")是一个宏,定义于tchar.h下。因为Windows使用两种字符集ANSI和UNICODE,如果你编译一个程序为ANSI方式,_T实际不起任何作用。

而如果编译一个程序为UNICODE方式,则编译器会把_T("Hello")字符串以UNICODE方式保存。_T和_L的区别在于,_L不管你是以什么方式编译,一律以UNICODE方式保存。

L是表示字符串资源为Unicode的。

#include "WinReg.h"
int main()
{
	LPCWSTR keyPath = SERIALPATH;
	LPCWSTR ValueName = _T("\\Device\\Serial2");
	char Value[MAX_PATH];
	int valueLength = MAX_PATH;
	if(QueryRegKey(keyPath, ValueName , Value, valueLength))
		printf("query success : %s!\n", Value);
	return 0;
}

image

得到串口设备列表

对比注册表符合。

#include "WinReg.h"
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int main()
{
	vector<string> COMList = QuerySerialPort();
	for(string& var : COMList)
	{
		cout << var << endl;
	}
	return 0;
}

在这里插入图片描述

注意:

字符集默认只 支持Unicode 在这里插入图片描述

About

Windows注册表查询以及通过注册表查询串口设备

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages