Void __fastcall TForm1: : Button1Click (TObject * Sender)
{
TRegistry * reg=new TRegistry;
Reg - & gt; RootKey=HKEY_LOCAL_MACHINE;
Reg - & gt; OpenKey (" HARDWARE \ \ DEVICEMAP \ \ SERIALCOMM ", true);
CbxComlist - & gt; Sorted=false;
Reg - & gt; GetValueNames (cbxComlist - & gt; The Items);
CbxComlist - & gt; The Items - & gt; BeginUpdate ();
for (int i=0; IItems - & gt; The Count. I++)
CbxComlist - & gt; The Items - & gt; Strings [I]=
Reg - & gt; ReadString (cbxComlist - & gt; The Items - & gt; Strings [I]);
CbxComlist - & gt; The Items - & gt; EndUpdate ();
The delete reg.
CbxComlist - & gt; Sorted=true;
}
Do not spray me, this is the COPY of demon elder brother a piece of code, my environment is XE8 c + + Builder, but after GetValueNames cbxComlist - & gt; IItems - & gt; Count
0, a great god to reassure? PS, don't, please understand
CodePudding user response:
# include & lt; Registry. Hpp>
Void __fastcall TForm1: : Button1Click (TObject * Sender)
{
TRegistry * reg=new TRegistry;
Reg - & gt; RootKey=HKEY_LOCAL_MACHINE;
Reg - & gt; OpenKey (" HARDWARE \ \ DEVICEMAP \ \ SERIALCOMM ", true);
CbxComlist - & gt; Sorted=false;
Reg - & gt; GetValueNames (cbxComlist - & gt; The Items);
CbxComlist - & gt; The Items - & gt; BeginUpdate ();
for (int i=0; iCbxComlist - & gt; The Items - & gt; Strings [I]=
Reg - & gt; ReadString (cbxComlist - & gt; The Items - & gt; Strings [I]);
CbxComlist - & gt; The Items - & gt; EndUpdate ();
The delete reg.
CbxComlist - & gt; Sorted=true;
}
Code test no problem, you check ~ ~
CodePudding user response:
... Do not spray me, this is COPY a piece of code of demon elder brother...Black beauty! A,
With API: EnumPorts to make right, look, from the view of now before enumeration registry way is a bit LOW,
CodePudding user response:
Key point of this problem is not a c + + Buidler version problem, is the registry permissions, after doing the system of "the HARDWARE \ \ DEVICEMAP \ \ SERIALCOMM" for the average user is read-only, if OpenKey the second parameter is the true need for write access, it will cause the failure of OpenKey execution, the back of the code is invalid, only need to change OpenKey second parameter to false will succeed, so don't need to get write access,Reg - & gt; OpenKey (_T (" HARDWARE \ \ DEVICEMAP \ \ SERIALCOMM "), false);
CodePudding user response: