c++builder 中怎样列出可用的串口号啊(spcomm控件)
能找出当前计算机可用的串口号,并显示再memo中··
[解决办法]
从注册表枚举就可以了:
#include <registry.hpp>void __fastcall CrnGetCommPortList(TStrings *lstComm){ lstComm->Clear(); TRegistry *reg = new TRegistry; TStringList *lst = new TStringList; try { reg->RootKey = HKEY_LOCAL_MACHINE; reg->OpenKey("HARDWARE\\DEVICEMAP\\SERIALCOMM", true); reg->GetValueNames(lst); for (int i = 0; i < lst->Count; i++) lstComm->Add(reg->ReadString(lst->Strings[i])); } __finally { delete reg; delete lst; }}void __fastcall TForm1::Button1Click(TObject *Sender){ CrnGetCommPortList(Memo1->Lines);}