Browse Subversion Repository
Contents of /connection/FindComPorts.cpp
Parent Directory
| Revision Log
Revision 292 -
( show annotations)
( download)
( as text)
Tue Mar 18 10:53:27 2008 UTC
(16 years ago)
by satofumi
File MIME type: text/x-c++src
File size: 1035 byte(s)
Visual Sutdio 2005 のエラーに対応
| 1 |
/*! |
| 2 |
\file |
| 3 |
\brief COM ポート一覧の取得 |
| 4 |
|
| 5 |
\author Satofumi KAMIMURA |
| 6 |
|
| 7 |
$Id$ |
| 8 |
*/ |
| 9 |
|
| 10 |
#include "FindComPorts.h" |
| 11 |
#include "DetectOS.h" |
| 12 |
#ifdef WINDOWS_OS |
| 13 |
#include <windows.h> |
| 14 |
#endif |
| 15 |
|
| 16 |
#ifdef WINDOWS_OS |
| 17 |
// Windows の場合 |
| 18 |
std::vector<std::string> beego::findComPorts(void) { |
| 19 |
|
| 20 |
std::vector<std::string> ports; |
| 21 |
HKEY hkey; |
| 22 |
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\SERIALCOMM", |
| 23 |
0, KEY_READ, &hkey) != ERROR_SUCCESS) { |
| 24 |
return ports; |
| 25 |
} |
| 26 |
enum { MaxLength = 255 }; |
| 27 |
CHAR device[MaxLength]; |
| 28 |
char name[MaxLength]; |
| 29 |
|
| 30 |
DWORD ret = ERROR_SUCCESS; |
| 31 |
for (int i = 0; ret == ERROR_SUCCESS; ++i) { |
| 32 |
DWORD dl = MaxLength, nl = MaxLength; |
| 33 |
ret = RegEnumValueA(hkey, i, device, &dl, NULL, NULL, (BYTE*)name, &nl); |
| 34 |
if (ret == ERROR_SUCCESS) { |
| 35 |
ports.push_back(std::string(name)); |
| 36 |
} |
| 37 |
} |
| 38 |
RegCloseKey(hkey); |
| 39 |
|
| 40 |
return ports; |
| 41 |
} |
| 42 |
|
| 43 |
#else |
| 44 |
// Linux, Mac の場合 |
| 45 |
std::vector<std::string> beego::findComPorts(void) { |
| 46 |
std::vector<std::string> ports; |
| 47 |
|
| 48 |
// !!! 実装方法未定... |
| 49 |
return ports; |
| 50 |
} |
| 51 |
#endif |
| |