-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenumser.h
185 lines (159 loc) · 6.05 KB
/
enumser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
Module : enumser.h
Purpose: Defines the interface for a class to enumerate the serial ports installed on a PC
using a number of different approaches
Created: PJN / 03-11-1998
Copyright (c) 1998 - 2013 by PJ Naughter (Web: www.naughter.com, Email: [email protected])
All rights reserved.
Copyright / Usage Details:
You are allowed to include the source code in any product (commercial, shareware, freeware or otherwise)
when your product is released in binary form. You are allowed to modify the source code in any way you want
except you cannot modify the copyright details at the top of each module. If you want to distribute source
code with your application, then you are only allowed to distribute versions released by the author. This is
to maintain a single distribution point for the source code.
*/
///////////////////////// Macros / Structs etc ////////////////////////////////
#pragma once
#ifndef __ENUMSER_H__
#define __ENUMSER_H__
#ifndef CENUMERATESERIAL_EXT_CLASS
#define CENUMERATESERIAL_EXT_CLASS
#endif
///////////////////////// Includes ////////////////////////////////////////////
#if defined CENUMERATESERIAL_USE_STL
#ifndef _VECTOR_
#include <vector>
#pragma message("To avoid this message, please put vector in your pre compiled header (normally stdafx.h)")
#endif
#ifndef _STRING_
#include <string>
#pragma message("To avoid this message, please put string in your pre compiled header (normally stdafx.h)")
#endif
#else
#if defined _AFX
#ifndef __AFXTEMPL_H__
#include <afxtempl.h>
#pragma message("To avoid this message, please put afxtempl.h in your pre compiled header (normally stdafx.h)")
#endif
#else
#ifndef __ATLSTR_H__
#include <atlstr.h>
#pragma message("To avoid this message, please put atlstr.h in your pre compiled header (normally stdafx.h)")
#endif
#endif
#endif
///////////////////////// Classes /////////////////////////////////////////////
class CENUMERATESERIAL_EXT_CLASS CEnumerateSerial
{
public:
//Methods
#ifndef NO_ENUMSERIAL_USING_CREATEFILE
#if defined CENUMERATESERIAL_USE_STL
static BOOL UsingCreateFile(std::vector<UINT>& ports);
#elif defined _AFX
static BOOL UsingCreateFile(CUIntArray& ports);
#else
static BOOL UsingCreateFile(CSimpleArray<UINT>& ports);
#endif
#endif
#ifndef NO_ENUMSERIAL_USING_QUERYDOSDEVICE
#if defined CENUMERATESERIAL_USE_STL
static BOOL UsingQueryDosDevice(std::vector<UINT>& ports);
#elif defined _AFX
static BOOL UsingQueryDosDevice(CUIntArray& ports);
#else
static BOOL UsingQueryDosDevice(CSimpleArray<UINT>& ports);
#endif
#endif
#ifndef NO_ENUMSERIAL_USING_GETDEFAULTCOMMCONFIG
#if defined CENUMERATESERIAL_USE_STL
static BOOL UsingGetDefaultCommConfig(std::vector<UINT>& ports);
#elif defined _AFX
static BOOL UsingGetDefaultCommConfig(CUIntArray& ports);
#else
static BOOL UsingGetDefaultCommConfig(CSimpleArray<UINT>& ports);
#endif
#endif
#ifndef NO_ENUMSERIAL_USING_SETUPAPI1
#if defined CENUMERATESERIAL_USE_STL
#if defined _UNICODE
static BOOL UsingSetupAPI1(std::vector<UINT>& ports, std::vector<std::wstring>& friendlyNames);
#else
static BOOL UsingSetupAPI1(std::vector<UINT>& ports, std::vector<std::string>& friendlyNames);
#endif
#elif defined _AFX
static BOOL UsingSetupAPI1(CUIntArray& ports, CStringArray& friendlyNames);
#else
static BOOL UsingSetupAPI1(CSimpleArray<UINT>& ports, CSimpleArray<CString>& friendlyNames);
#endif
#endif
#ifndef NO_ENUMSERIAL_USING_SETUPAPI2
#if defined CENUMERATESERIAL_USE_STL
#if defined _UNICODE
static BOOL UsingSetupAPI2(std::vector<UINT>& ports, std::vector<std::wstring>& friendlyNames);
#else
static BOOL UsingSetupAPI2(std::vector<UINT>& ports, std::vector<std::string>& friendlyNames);
#endif
#elif defined _AFX
static BOOL UsingSetupAPI2(CUIntArray& ports, CStringArray& friendlyNames);
#else
static BOOL UsingSetupAPI2(CSimpleArray<UINT>& ports, CSimpleArray<CString>& friendlyNames);
#endif
#endif
#ifndef NO_ENUMSERIAL_USING_ENUMPORTS
#if defined CENUMERATESERIAL_USE_STL
static BOOL UsingEnumPorts(std::vector<UINT>& ports);
#elif defined _AFX
static BOOL UsingEnumPorts(CUIntArray& ports);
#else
static BOOL UsingEnumPorts(CSimpleArray<UINT>& ports);
#endif
#endif
#ifndef NO_ENUMSERIAL_USING_WMI
#if defined CENUMERATESERIAL_USE_STL
#if defined _UNICODE
static BOOL UsingWMI(std::vector<UINT>& ports, std::vector<std::wstring>& friendlyNames);
#else
static BOOL UsingWMI(std::vector<UINT>& ports, std::vector<std::string>& friendlyNames);
#endif
#elif defined _AFX
static BOOL UsingWMI(CUIntArray& ports, CStringArray& friendlyNames);
#else
static BOOL UsingWMI(CSimpleArray<UINT>& ports, CSimpleArray<CString>& friendlyNames);
#endif
#endif
#ifndef NO_ENUMSERIAL_USING_COMDB
#if defined CENUMERATESERIAL_USE_STL
static BOOL UsingComDB(std::vector<UINT>& ports);
#elif defined _AFX
static BOOL UsingComDB(CUIntArray& ports);
#else
static BOOL UsingComDB(CSimpleArray<UINT>& ports);
#endif
#endif
#ifndef NO_ENUMSERIAL_USING_REGISTRY
#if defined CENUMERATESERIAL_USE_STL
#if defined _UNICODE
static BOOL UsingRegistry(std::vector<std::wstring>& ports);
#else
static BOOL UsingRegistry(std::vector<std::string>& ports);
#endif
#elif defined _AFX
static BOOL UsingRegistry(CStringArray& ports);
#else
static BOOL UsingRegistry(CSimpleArray<CString>& ports);
#endif
#endif
protected:
//Methods
#if !defined(NO_ENUMSERIAL_USING_SETUPAPI1) || !defined(NO_ENUMSERIAL_USING_SETUPAPI2)
static BOOL RegQueryValueString(HKEY kKey, LPCTSTR lpValueName, LPTSTR& pszValue);
static BOOL QueryRegistryPortName(HKEY hDeviceKey, int& nPort);
#endif
#if !defined(NO_ENUMSERIAL_USING_SETUPAPI1) || !defined(NO_ENUMSERIAL_USING_SETUPAPI2) || !defined(NO_ENUMSERIAL_USING_COMDB)
static HMODULE LoadLibraryFromSystem32(LPCTSTR lpFileName);
#endif
static BOOL IsNumeric(LPCSTR pszString, BOOL bIgnoreColon);
static BOOL IsNumeric(LPCWSTR pszString, BOOL bIgnoreColon);
};
#endif //__ENUMSER_H__