列举本机串口(含虚拟串口)
来源:互联网 发布:激战2马乔丽捏脸数据 编辑:程序博客网 时间:2024/04/30 22:10
第一种 枚举注册表
void GetPortList(char **lpPortlist,int& count){ HKEY hKey; LONG lRes = RegOpenKey( HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\SERIALCOMM", &hKey ); assert( lRes == ERROR_SUCCESS ); bool bGetCount=false; if(count==0) bGetCount=true; else count=0; for( int i = 0; 1; ++i ) { char szName[MAX_PATH]=""; unsigned char szValue[MAX_PATH]=""; DWORD sizeName=100, sizeValue=100, type=0; lRes = RegEnumValue( hKey, i, szName, &sizeName, NULL, &type, szValue, &sizeValue ); if( lRes != ERROR_SUCCESS ) break; if(!bGetCount) { memset(lpPortlist[i],0,MAX_PATH); memcpy(lpPortlist[i],szValue,MAX_PATH); } ++count; } RegCloseKey( hKey );}调用示例:char *pszPorts[MAX_PATH]={0}; int count=0; GetPortList(NULL,count); for(int i=0;i<count;++i) { pszPorts[i]=new char[MAX_PATH]; assert(pszPorts[i]!=NULL); } GetPortList(pszPorts,count); for(int i=0;i<count;++i) MessageBox(NULL,pszPorts[i],NULL,MB_OK); for(int i=0;i<count;++i) { if(pszPorts[i]) { delete [] pszPorts[i]; pszPorts[i]=NULL; } }
第二种 使用GetDefaultCommConfig
void __fastcall GetPortList(TStrings *strPortlist){ String strPortname; COMMCONFIG cc={0}; DWORD dwCCSize=sizeof(cc); for(int i=1;i<64;i++) { strPortname=String().sprintf("COM%d",i); if(GetDefaultCommConfig(strPortname.c_str(),&cc,&dwCCSize)) { strPortlist->Add(strPortname); } strPortname=""; } }
- 列举本机串口(含虚拟串口)
- 列举串口
- 列举串口
- Linux 虚拟串口(可用于在本机上模拟串口进行调试)
- Linux下的虚拟终端(可用于在本机上模拟串口进行调试)
- 检测本机串口
- 枚举本机串口
- 枚举本机串口
- MATLAB 串口通信,发现本机串口
- 虚拟串口
- 虚拟串口
- python 列举所有串口模块
- 列出本机所有串口
- Java串口通信列出本机所有串口
- USB虚拟串口
- 虚拟串口实现
- 开发虚拟串口驱动程序
- 关于虚拟串口
- 定义物料组(Material Group)
- 机器学习中的数学(5)-强大的矩阵奇异值分解(SVD)及其应用 【zz】
- 浅谈MTK平台下Android开发比较学习笔记
- 超链接
- Source Navigato rNG-4.4在ubuntu的简单的安装
- 列举本机串口(含虚拟串口)
- 验证码
- gsoap写一个c++ webservice
- 终于找到了,我想要的
- 自动添加/删除
- 实时渲染(第三版):第二章 图形渲染管道 2.1 体系结构
- 巧妙利用VS 的分栏功能,提高开发效率
- 我在北京工作这几年 – 一个软件工程师的反省
- Silverlight使用HttpWebRequest和HttpWebResponse时发生System.Security.SecurityException: 安全性错误