MFC 掃描COM連接埠程式

來源:互聯網
上載者:User

                                             MFC 掃描COM連接埠程式

 

 

 

 

MFC 掃描COM連接埠程式原始碼

 

主要功能簡介:

 

核心函數就是Scan。不僅可以掃描出實際的藍芽,印表機等COM連接埠,而且還可以掃描出虛擬機器來的COM連接埠。

不僅可以顯示名稱,還可以顯示生產廠商的具體參數

 

 

/*<br />func name: Scan<br />description: Scan and display the COM port information<br />This is the main function of the app. It detect your port, as well as the virtual port.<br />*/</p><p>HRESULT CSmartScanerDlg::Scan(void)<br />{</p><p>HDEVINFO hDevInfo;<br />SP_DEVINFO_DATA DeviceInfoData;<br />DWORD i;</p><p>// Create a HDEVINFO with all present devices.<br />hDevInfo = SetupDiGetClassDevs((LPGUID)&GUID_DEVCLASS_PORTS,<br />0, // Enumerator<br />0,<br />DIGCF_PRESENT);</p><p>if (hDevInfo == INVALID_HANDLE_VALUE)<br />{<br />// Insert error handling here.<br />return 1;<br />}</p><p>// Enumerate through all devices in Set.</p><p>DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);<br />for (i=0;SetupDiEnumDeviceInfo(hDevInfo,i,<br />&DeviceInfoData);i++)<br />{<br />DWORD DataT;<br />LPTSTR buffer = NULL;<br />DWORD buffersize = 0;</p><p>//<br />// Call function with null to begin with,<br />// then use the returned buffer size<br />// to Alloc the buffer. Keep calling until<br />// success or an unknown failure.<br />//<br />while (!SetupDiGetDeviceRegistryProperty(<br />hDevInfo,<br />&DeviceInfoData,<br />SPDRP_FRIENDLYNAME,<br />&DataT,<br />(PBYTE)buffer,<br />buffersize,<br />&buffersize))<br />{<br />if (GetLastError() ==<br />ERROR_INSUFFICIENT_BUFFER)<br />{<br />// Change the buffer size.<br />if (buffer) LocalFree(buffer);<br />buffer = (LPTSTR)LocalAlloc(LPTR,buffersize);<br />}<br />else<br />{<br />// Insert error handling here.<br />break;<br />}<br />}</p><p>//printf("Result:[%s]/n",buffer);</p><p>/**<br />disp is MFC Edit Control CString variable.<br />here, I just use it display the scan results.<br />the buffer just contains the result.<br />and if you want to get other information ,just change<br />SPDRP_FRIENDLYNAME(please look up in MSDN)<br />*/<br />disp.Append(buffer);<br />disp.Append(_T("/r/n"));<br />conEdit.SetWindowTextW(disp.GetString());</p><p>} </p><p>SetupDiDestroyDeviceInfoList(hDevInfo); </p><p>if (!wcscmp(disp.GetString(), _T("/r/n"))){<br />MessageBox(_T("no device find"), _T("prompt"));<br />}</p><p>return S_OK;<br />}

 

 

MFC 掃描COM連接埠程式原始碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.