git-svn-id: https://svn.code.sf.net/p/freetel/code@1116 01035d8c-6547-0410-b346-abe4f...
authorwittend99 <wittend99@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 4 Dec 2012 03:41:59 +0000 (03:41 +0000)
committerwittend99 <wittend99@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 4 Dec 2012 03:41:59 +0000 (03:41 +0000)
fdmdv2/tests/serial_enum/Debug/.gitignore [new file with mode: 0644]
fdmdv2/tests/serial_enum/enumSerial.mk [new file with mode: 0644]
fdmdv2/tests/serial_enum/enumSerial.project [new file with mode: 0644]
fdmdv2/tests/serial_enum/enumSerial.txt [new file with mode: 0644]
fdmdv2/tests/serial_enum/enumser.h [new file with mode: 0644]
fdmdv2/tests/serial_enum/main.cpp [new file with mode: 0644]

diff --git a/fdmdv2/tests/serial_enum/Debug/.gitignore b/fdmdv2/tests/serial_enum/Debug/.gitignore
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/fdmdv2/tests/serial_enum/enumSerial.mk b/fdmdv2/tests/serial_enum/enumSerial.mk
new file mode 100644 (file)
index 0000000..48d5b15
--- /dev/null
@@ -0,0 +1,111 @@
+##\r
+## Auto Generated makefile by CodeLite IDE\r
+## any manual changes will be erased      \r
+##\r
+## Debug\r
+ProjectName            :=enumSerial\r
+ConfigurationName      :=Debug\r
+WorkspacePath          := "D:\Projects\Radio\fdmdv2\build"\r
+ProjectPath            := "D:\Projects\Radio\fdmdv2\tests\serial_enum"\r
+IntermediateDirectory  :=./Debug\r
+OutDir                 := $(IntermediateDirectory)\r
+CurrentFileName        :=\r
+CurrentFilePath        :=\r
+CurrentFileFullPath    :=\r
+User                   :=wittend\r
+Date                   :=12/3/2012\r
+CodeLitePath           :="D:\bin\CodeLite"\r
+LinkerName             :=g++\r
+SharedObjectLinkerName :=g++ -shared -fPIC\r
+ObjectSuffix           :=.o\r
+DependSuffix           :=.o.d\r
+PreprocessSuffix       :=.o.i\r
+DebugSwitch            :=-gstab\r
+IncludeSwitch          :=-I\r
+LibrarySwitch          :=-l\r
+OutputSwitch           :=-o \r
+LibraryPathSwitch      :=-L\r
+PreprocessorSwitch     :=-D\r
+SourceSwitch           :=-c \r
+OutputFile             :=$(IntermediateDirectory)/$(ProjectName)\r
+Preprocessors          :=$(PreprocessorSwitch)_WX_ \r
+ObjectSwitch           :=-o \r
+ArchiveOutputSwitch    := \r
+PreprocessOnlySwitch   :=-E \r
+ObjectsFileList        :="D:\Projects\Radio\fdmdv2\tests\serial_enum\enumSerial.txt"\r
+PCHCompileFlags        :=\r
+MakeDirCommand         :=makedir\r
+RcCmpOptions           := $(shell wx-config --rcflags)\r
+RcCompilerName         :=windres\r
+LinkOptions            :=  $(shell wx-config --debug=yes --libs --unicode=yes)\r
+IncludePath            :=  $(IncludeSwitch). $(IncludeSwitch)/bin/MinGW-4.6.1/msys/1.0/local/include \r
+IncludePCH             := \r
+RcIncludePath          := \r
+Libs                   := \r
+ArLibs                 :=  \r
+LibPath                := $(LibraryPathSwitch). \r
+\r
+##\r
+## Common variables\r
+## AR, CXX, CC, CXXFLAGS and CFLAGS can be overriden using an environment variables\r
+##\r
+AR       := ar rcus\r
+CXX      := g++\r
+CC       := gcc\r
+CXXFLAGS :=  -g -O0 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=yes)  -DSVN_REVISION=\"1111\"  $(Preprocessors)\r
+CFLAGS   :=  -g -O0 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=yes)  -DSVN_REVISION=\"1111\"  $(Preprocessors)\r
+\r
+\r
+##\r
+## User defined environment variables\r
+##\r
+CodeLiteDir:=D:\bin\CodeLite\r
+WXWIN:=D:\bin\wxWidgets-2.9.4\r
+PATH:=$(WXWIN)\lib\gcc_dll;$(PATH)\r
+WXCFG:=gcc_dll\mswu\r
+UNIT_TEST_PP_SRC_DIR:=D:\bin\UnitTest++-1.3\r
+Objects=$(IntermediateDirectory)/main$(ObjectSuffix) \r
+\r
+##\r
+## Main Build Targets \r
+##\r
+.PHONY: all clean PreBuild PrePreBuild PostBuild\r
+all: $(OutputFile)\r
+\r
+$(OutputFile): $(IntermediateDirectory)/.d $(Objects) \r
+       @$(MakeDirCommand) $(@D)\r
+       @echo "" > $(IntermediateDirectory)/.d\r
+       @echo $(Objects) > $(ObjectsFileList)\r
+       $(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions)\r
+\r
+$(IntermediateDirectory)/.d:\r
+       @$(MakeDirCommand) "./Debug"\r
+\r
+PreBuild:\r
+\r
+\r
+##\r
+## Objects\r
+##\r
+$(IntermediateDirectory)/main$(ObjectSuffix): main.cpp $(IntermediateDirectory)/main$(DependSuffix)\r
+       $(CXX) $(IncludePCH) $(SourceSwitch) "D:/Projects/Radio/fdmdv2/tests/serial_enum/main.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/main$(ObjectSuffix) $(IncludePath)\r
+$(IntermediateDirectory)/main$(DependSuffix): main.cpp\r
+       @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/main$(ObjectSuffix) -MF$(IntermediateDirectory)/main$(DependSuffix) -MM "D:/Projects/Radio/fdmdv2/tests/serial_enum/main.cpp"\r
+\r
+$(IntermediateDirectory)/main$(PreprocessSuffix): main.cpp\r
+       @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/main$(PreprocessSuffix) "D:/Projects/Radio/fdmdv2/tests/serial_enum/main.cpp"\r
+\r
+\r
+-include $(IntermediateDirectory)/*$(DependSuffix)\r
+##\r
+## Clean\r
+##\r
+clean:\r
+       $(RM) $(IntermediateDirectory)/main$(ObjectSuffix)\r
+       $(RM) $(IntermediateDirectory)/main$(DependSuffix)\r
+       $(RM) $(IntermediateDirectory)/main$(PreprocessSuffix)\r
+       $(RM) $(OutputFile)\r
+       $(RM) $(OutputFile).exe\r
+       $(RM) "D:\Projects\Radio\fdmdv2\build\.build-debug\enumSerial"\r
+\r
+\r
diff --git a/fdmdv2/tests/serial_enum/enumSerial.project b/fdmdv2/tests/serial_enum/enumSerial.project
new file mode 100644 (file)
index 0000000..99160d9
--- /dev/null
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CodeLite_Project Name="enumSerial" InternalType="Console">
+  <Plugins>
+    <Plugin Name="qmake">
+      <![CDATA[00020001N0005Debug0000000000000001N0007Release000000000000]]>
+    </Plugin>
+  </Plugins>
+  <Description/>
+  <Dependencies/>
+  <VirtualDirectory Name="src">
+    <File Name="main.cpp"/>
+    <File Name="../../../../code/libCTB-0.16/include/ctb-0.16/ctb.h"/>
+    <File Name="../../../../code/libCTB-0.16/include/ctb-0.16/serport.h"/>
+    <File Name="../../../../code/libCTB-0.16/include/ctb-0.16/serportx.h"/>
+  </VirtualDirectory>
+  <Settings Type="Executable">
+    <GlobalSettings>
+      <Compiler Options="" C_Options="">
+        <IncludePath Value="."/>
+      </Compiler>
+      <Linker Options="">
+        <LibraryPath Value="."/>
+      </Linker>
+      <ResourceCompiler Options=""/>
+    </GlobalSettings>
+    <Configuration Name="Debug" CompilerType="gnu g++" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
+      <Compiler Options="-g;-O0;-Wall;$(shell wx-config --cxxflags --unicode=yes --debug=yes)" C_Options="-g;-O0;-Wall;$(shell wx-config --cxxflags --unicode=yes --debug=yes)" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" UseDifferentPCHFlags="no" PCHFlags="">
+        <IncludePath Value="/bin/MinGW-4.6.1/msys/1.0/local/include"/>
+        <Preprocessor Value="_WX_"/>
+      </Compiler>
+      <Linker Options="$(shell wx-config --debug=yes --libs --unicode=yes)" Required="yes"/>
+      <ResourceCompiler Options="$(shell wx-config --rcflags)" Required="no"/>
+      <General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes"/>
+      <Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
+        <![CDATA[]]>
+      </Environment>
+      <Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="">
+        <PostConnectCommands/>
+        <StartupCommands/>
+      </Debugger>
+      <PreBuild/>
+      <PostBuild/>
+      <CustomBuild Enabled="no">
+        <RebuildCommand/>
+        <CleanCommand/>
+        <BuildCommand/>
+        <PreprocessFileCommand/>
+        <SingleFileCommand/>
+        <MakefileGenerationCommand/>
+        <ThirdPartyToolName>None</ThirdPartyToolName>
+        <WorkingDirectory/>
+      </CustomBuild>
+      <AdditionalRules>
+        <CustomPostBuild/>
+        <CustomPreBuild/>
+      </AdditionalRules>
+      <Completion EnableCpp11="no">
+        <ClangCmpFlagsC/>
+        <ClangCmpFlags/>
+        <ClangPP/>
+        <SearchPaths/>
+      </Completion>
+    </Configuration>
+    <Configuration Name="Release" CompilerType="gnu g++" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
+      <Compiler Options="-O2;-Wall;$(shell wx-config --cxxflags --unicode=yes --debug=no)" C_Options="-O2;-Wall;$(shell wx-config --cxxflags --unicode=yes --debug=no)" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" UseDifferentPCHFlags="no" PCHFlags="">
+        <IncludePath Value="/bin/MinGW-4.6.1/msys/1.0/local/include"/>
+        <Preprocessor Value="_WX_"/>
+      </Compiler>
+      <Linker Options="-s;$(shell wx-config --debug=no --libs --unicode=yes)" Required="yes"/>
+      <ResourceCompiler Options="$(shell wx-config --rcflags)" Required="no"/>
+      <General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Release" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes"/>
+      <Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
+        <![CDATA[]]>
+      </Environment>
+      <Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="">
+        <PostConnectCommands/>
+        <StartupCommands/>
+      </Debugger>
+      <PreBuild/>
+      <PostBuild/>
+      <CustomBuild Enabled="no">
+        <RebuildCommand/>
+        <CleanCommand/>
+        <BuildCommand/>
+        <PreprocessFileCommand/>
+        <SingleFileCommand/>
+        <MakefileGenerationCommand/>
+        <ThirdPartyToolName>None</ThirdPartyToolName>
+        <WorkingDirectory/>
+      </CustomBuild>
+      <AdditionalRules>
+        <CustomPostBuild/>
+        <CustomPreBuild/>
+      </AdditionalRules>
+      <Completion EnableCpp11="no">
+        <ClangCmpFlagsC/>
+        <ClangCmpFlags/>
+        <ClangPP/>
+        <SearchPaths/>
+      </Completion>
+    </Configuration>
+  </Settings>
+</CodeLite_Project>
diff --git a/fdmdv2/tests/serial_enum/enumSerial.txt b/fdmdv2/tests/serial_enum/enumSerial.txt
new file mode 100644 (file)
index 0000000..e9f35e3
--- /dev/null
@@ -0,0 +1 @@
+./Debug/main.o  \r
diff --git a/fdmdv2/tests/serial_enum/enumser.h b/fdmdv2/tests/serial_enum/enumser.h
new file mode 100644 (file)
index 0000000..92b4ad9
--- /dev/null
@@ -0,0 +1,257 @@
+/*\r
+Module : enumser.h\r
+Purpose: Defines the interface for a class to enumerate the serial ports installed on a PC\r
+         using a number of different approaches\r
+Created: PJN / 03-11-1998\r
+\r
+Copyright (c) 1998 - 2012 by PJ Naughter (Web: www.naughter.com, Email: pjna@naughter.com)\r
+\r
+All rights reserved.\r
+\r
+Copyright / Usage Details:\r
+\r
+You are allowed to include the source code in any product (commercial, shareware, freeware or otherwise) \r
+when your product is released in binary form. You are allowed to modify the source code in any way you want \r
+except you cannot modify the copyright details at the top of each module. If you want to distribute source \r
+code with your application, then you are only allowed to distribute versions released by the author. This is \r
+to maintain a single distribution point for the source code. \r
+\r
+*/\r
+\r
+\r
+///////////////////////// Macros / Structs etc ////////////////////////////////\r
+\r
+#pragma once\r
+\r
+#ifndef __ENUMSER_H__\r
+#define __ENUMSER_H__\r
+\r
+#ifndef CENUMERATESERIAL_EXT_CLASS\r
+#define CENUMERATESERIAL_EXT_CLASS\r
+#endif\r
+\r
+\r
+///////////////////////// Includes ////////////////////////////////////////////                      \r
+\r
+#if defined CENUMERATESERIAL_USE_STL\r
+#ifndef _VECTOR_\r
+  #include <vector>\r
+  #pragma message("To avoid this message, please put vector in your pre compiled header (normally stdafx.h)")\r
+#endif  \r
+#ifndef _STRING_\r
+  #include <string>\r
+  #pragma message("To avoid this message, please put string in your pre compiled header (normally stdafx.h)")\r
+#endif  \r
+#endif\r
+\r
+#if defined _AFX\r
+  #ifndef __AFXTEMPL_H__\r
+    #include <afxtempl.h> \r
+    #pragma message("To avoid this message, please put afxtempl.h in your pre compiled header (normally stdafx.h)")\r
+  #endif\r
+#else\r
+  #ifndef __ATLSTR_H__\r
+    #include <atlstr.h>\r
+    #pragma message("To avoid this message, please put atlstr.h in your pre compiled header (normally stdafx.h)")\r
+  #endif  \r
+#endif\r
+\r
+\r
+///////////////////////// Classes /////////////////////////////////////////////\r
+\r
+class CENUMERATESERIAL_EXT_CLASS CEnumerateSerial\r
+{\r
+public:\r
+//Methods\r
+#ifndef NO_ENUMSERIAL_USING_CREATEFILE\r
+  #if defined CENUMERATESERIAL_USE_STL\r
+       static BOOL UsingCreateFile(std::vector<UINT>& ports);\r
+  #elif defined _AFX\r
+       static BOOL UsingCreateFile(CUIntArray& ports);\r
+  #else\r
+      static BOOL UsingCreateFile(CSimpleArray<UINT>& ports);\r
+  #endif\r
+#endif\r
+\r
+#ifndef NO_ENUMSERIAL_USING_QUERYDOSDEVICE\r
+  #if defined CENUMERATESERIAL_USE_STL\r
+    static BOOL UsingQueryDosDevice(std::vector<UINT>& ports);\r
+  #elif defined _AFX\r
+    static BOOL UsingQueryDosDevice(CUIntArray& ports);\r
+  #else\r
+    static BOOL UsingQueryDosDevice(CSimpleArray<UINT>& ports);\r
+  #endif\r
+#endif\r
+\r
+#ifndef NO_ENUMSERIAL_USING_GETDEFAULTCOMMCONFIG\r
+  #if defined CENUMERATESERIAL_USE_STL\r
+       static BOOL UsingGetDefaultCommConfig(std::vector<UINT>& ports);\r
+  #elif defined _AFX\r
+    static BOOL UsingGetDefaultCommConfig(CUIntArray& ports);\r
+  #else\r
+    static BOOL UsingGetDefaultCommConfig(CSimpleArray<UINT>& ports);\r
+  #endif\r
+#endif\r
+\r
+#ifndef NO_ENUMSERIAL_USING_SETUPAPI1\r
+  #if defined CENUMERATESERIAL_USE_STL\r
+    #if defined _UNICODE\r
+      static BOOL UsingSetupAPI1(std::vector<UINT>& ports, std::vector<std::wstring>& friendlyNames);\r
+    #else\r
+      static BOOL UsingSetupAPI1(std::vector<UINT>& ports, std::vector<std::string>& friendlyNames);\r
+    #endif\r
+  #elif defined _AFX\r
+    static BOOL UsingSetupAPI1(CUIntArray& ports, CStringArray& friendlyNames);\r
+  #else\r
+    static BOOL UsingSetupAPI1(CSimpleArray<UINT>& ports, CSimpleArray<CString>& friendlyNames);\r
+  #endif\r
+#endif\r
+\r
+#ifndef NO_ENUMSERIAL_USING_SETUPAPI2\r
+  #if defined CENUMERATESERIAL_USE_STL\r
+    #if defined _UNICODE\r
+      static BOOL UsingSetupAPI2(std::vector<UINT>& ports, std::vector<std::wstring>& friendlyNames);\r
+    #else\r
+      static BOOL UsingSetupAPI2(std::vector<UINT>& ports, std::vector<std::string>& friendlyNames);\r
+    #endif\r
+  #elif defined _AFX\r
+    static BOOL UsingSetupAPI2(CUIntArray& ports, CStringArray& friendlyNames);\r
+  #else\r
+    static BOOL UsingSetupAPI2(CSimpleArray<UINT>& ports, CSimpleArray<CString>& friendlyNames);\r
+  #endif\r
+#endif\r
+\r
+#ifndef NO_ENUMSERIAL_USING_ENUMPORTS\r
+  #if defined CENUMERATESERIAL_USE_STL\r
+    static BOOL UsingEnumPorts(std::vector<UINT>& ports);\r
+  #elif defined _AFX\r
+    static BOOL UsingEnumPorts(CUIntArray& ports);\r
+  #else\r
+    static BOOL UsingEnumPorts(CSimpleArray<UINT>& ports);\r
+  #endif\r
+#endif\r
+\r
+#ifndef NO_ENUMSERIAL_USING_WMI\r
+  #if defined CENUMERATESERIAL_USE_STL\r
+    #if defined _UNICODE\r
+      static BOOL UsingWMI(std::vector<UINT>& ports, std::vector<std::wstring>& friendlyNames);\r
+    #else\r
+      static BOOL UsingWMI(std::vector<UINT>& ports, std::vector<std::string>& friendlyNames);\r
+    #endif\r
+  #elif defined _AFX\r
+    static BOOL UsingWMI(CUIntArray& ports, CStringArray& friendlyNames);\r
+  #else\r
+    static BOOL UsingWMI(CSimpleArray<UINT>& ports, CSimpleArray<CString>& friendlyNames);\r
+  #endif\r
+#endif\r
+\r
+#ifndef NO_ENUMSERIAL_USING_COMDB\r
+  #if defined CENUMERATESERIAL_USE_STL\r
+    static BOOL UsingComDB(std::vector<UINT>& ports);\r
+  #elif defined _AFX\r
+    static BOOL UsingComDB(CUIntArray& ports);\r
+  #else\r
+    static BOOL UsingComDB(CSimpleArray<UINT>& ports);\r
+  #endif\r
+#endif\r
+\r
+#ifndef NO_ENUMSERIAL_USING_REGISTRY\r
+  #if defined CENUMERATESERIAL_USE_STL\r
+    #if defined _UNICODE\r
+      static BOOL UsingRegistry(std::vector<std::wstring>& ports);\r
+    #else\r
+      static BOOL UsingRegistry(std::vector<std::string>& ports);\r
+    #endif\r
+  #elif defined _AFX\r
+    static BOOL UsingRegistry(CStringArray& ports);\r
+  #else\r
+    static BOOL UsingRegistry(CSimpleArray<CString>& ports);\r
+  #endif\r
+#endif\r
+\r
+protected:\r
+\r
+//Helper class which supports auto closing of a handle via CloseHandle\r
+  class CAutoHandle\r
+  {\r
+  public:\r
+  //Constructors / Destructors\r
+    CAutoHandle() : m_hHandle(INVALID_HANDLE_VALUE)\r
+    {\r
+    }\r
+\r
+    explicit CAutoHandle(HANDLE hHandle) : m_hHandle(hHandle)\r
+    {\r
+    }\r
+\r
+    ~CAutoHandle()\r
+    {\r
+      if (m_hHandle != INVALID_HANDLE_VALUE)\r
+      {\r
+        CloseHandle(m_hHandle);\r
+        m_hHandle = INVALID_HANDLE_VALUE;\r
+      }\r
+    }\r
+\r
+  //Methods\r
+    operator HANDLE() \r
+    {\r
+      return m_hHandle;\r
+    }\r
+\r
+  //Member variables\r
+    HANDLE m_hHandle;\r
+  };\r
+\r
+\r
+//Helper class which supports auto closing of a HMODULE via FreeLibrary and setting of the last Win32 error via SetLastError\r
+  class CAutoHModule\r
+  {\r
+  public:\r
+  //Constructors / Destructors\r
+    CAutoHModule() : m_hModule(NULL), \r
+                     m_dwError(ERROR_SUCCESS)\r
+    {\r
+    }\r
+\r
+    explicit CAutoHModule(HMODULE hModule) : m_hModule(hModule), \r
+                                             m_dwError(GetLastError())\r
+    {\r
+    }\r
+\r
+    explicit CAutoHModule(HMODULE hModule, DWORD dwError) : m_hModule(hModule), \r
+                                                            m_dwError(dwError)\r
+    {\r
+    }\r
+\r
+    ~CAutoHModule()\r
+    {\r
+      if (m_hModule != NULL)\r
+      {\r
+        FreeLibrary(m_hModule);\r
+        m_hModule = NULL;\r
+      }\r
+      SetLastError(m_dwError);\r
+    }\r
+\r
+    operator HMODULE() \r
+    {\r
+      return m_hModule;\r
+    }\r
+\r
+  //Member variables\r
+    HMODULE m_hModule;\r
+    DWORD m_dwError;\r
+  };\r
+\r
+\r
+\r
+//Methods\r
+  static BOOL RegQueryValueString(HKEY kKey, LPCTSTR lpValueName, LPTSTR& pszValue);\r
+  static BOOL QueryRegistryPortName(HKEY hDeviceKey, int& nPort);\r
+  static HMODULE LoadLibraryFromSystem32(LPCTSTR lpFileName);\r
+  static BOOL IsNumeric(LPCSTR pszString, BOOL bIgnoreColon);\r
+  static BOOL IsNumeric(LPCWSTR pszString, BOOL bIgnoreColon);\r
+};\r
+\r
+#endif //__ENUMSER_H__\r
diff --git a/fdmdv2/tests/serial_enum/main.cpp b/fdmdv2/tests/serial_enum/main.cpp
new file mode 100644 (file)
index 0000000..b45d5ed
--- /dev/null
@@ -0,0 +1,206 @@
+#include <wx/wx.h>\r
+#include <wx/init.h>\r
+#include <wx/string.h>\r
+#include <wx/msw/registry.h>\r
+//#include <wx/stream.h>\r
+//#include <wx/sstream.h>\r
+#include <ctb-0.16/ctb.h>\r
+\r
+\r
+static bool getReg();\r
+//static bool UsingRegistryWxArrayString(wxArrayString ports);\r
+//static bool UsingRegistry(std::vector<std::wstring>& ports);\r
+//static bool RegQueryValueString(HKEY kKey, LPCTSTR lpValueName, LPTSTR& pszValue);\r
+//static bool QueryRegistryPortName(HKEY hDeviceKey, int& nPort);\r
+//static HMODULE LoadLibraryFromSystem32(LPCTSTR lpFileName);\r
+//static bool IsNumeric(LPCSTR pszString, bool bIgnoreColon);\r
+//static bool IsNumeric(LPCWSTR pszString, bool bIgnoreColon);\r
+\r
+//std::vector<std::wstring> friendlyNames;\r
+int main( int argc, char** argv )\r
+{\r
+    // initialize wxWidgets\r
+    wxInitializer init;\r
+    wxPrintf(wxT("Enumerating Serial Comm Ports\n\n"));\r
+    //std::vector<std::wstring> sPorts;\r
+    wxArrayString   sPorts;\r
+    if(getReg())\r
+    {\r
+        wxPrintf("\nOk\n");\r
+    }\r
+/*\r
+    if(UsingRegistryWxArrayString(sPorts))\r
+    {\r
+        for(int i = 0; i < sPorts.size(); i++)\r
+        {\r
+            wxPrintf("%s\n", sPorts[i].c_str());\r
+        }\r
+    }\r
+*/\r
+    return 0;\r
+}\r
+\r
+#ifdef __WXMSW__\r
+\r
+bool getReg()\r
+{\r
+    //wxRegKey *key = new wxRegKey("HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOMM");\r
+    wxRegKey key(wxRegKey::HKLM, _T("HARDWARE\\DEVICEMAP\\SERIALCOMM"));\r
+    if(!key.Exists())\r
+    {\r
+        wxPrintf("Key doesn't exist: %s\n", key.GetName());\r
+        return false;\r
+    }\r
+    else\r
+    {\r
+        // Get the number of subkeys and enumerate them.\r
+        if(!key.Open(wxRegKey::Read))\r
+        {\r
+            wxPrintf("Unable to open key: %s\n", key.GetName());\r
+            return false;\r
+        }    \r
+        size_t subkeys;\r
+        size_t values;\r
+        if(!key.GetKeyInfo(&subkeys, NULL, &values, NULL))\r
+        {\r
+            wxPrintf("Unable get subkey info: %s\n", key.GetName());\r
+            return false;\r
+        }\r
+        if(!key.HasValues())\r
+        {\r
+            wxPrintf("Key does have values: %s\n", key.GetName());\r
+            return false;\r
+        }\r
+        wxString key_name;\r
+        long el = 1;\r
+        key.GetFirstValue(key_name, el);\r
+        wxString valType;\r
+        wxString key_data;\r
+        for(unsigned int i = 0; i < values; i++)\r
+        {\r
+            key.QueryValue(key_name, key_data);\r
+            wxPrintf("Value:  %s Data: %s\n", key_name, key_data);\r
+            //wxPrintf("Data:  %s\n", key_data);\r
+            key.GetNextValue(key_name, el);\r
+        }\r
+    }\r
+    return true;\r
+}\r
\r
+bool UsingRegistry(std::vector<std::wstring>& ports)\r
+{\r
+    //Make sure we clear out any elements which may already be in the array(s)\r
+    ports.clear();\r
+    //What will be the return value from this function (assume the worst)\r
+    BOOL bSuccess = FALSE;\r
+\r
+    HKEY hSERIALCOMM;\r
+    if(::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("HARDWARE\\DEVICEMAP\\SERIALCOMM"), 0, KEY_QUERY_VALUE, &hSERIALCOMM) == ERROR_SUCCESS)\r
+    {\r
+        //Get the max value name and max value lengths\r
+        DWORD dwMaxValueNameLen;\r
+        DWORD dwMaxValueLen;\r
+        DWORD dwQueryInfo = ::RegQueryInfoKey(hSERIALCOMM, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &dwMaxValueNameLen, &dwMaxValueLen, NULL, NULL);\r
+        if(dwQueryInfo == ERROR_SUCCESS)\r
+        {\r
+            DWORD dwMaxValueNameSizeInChars = dwMaxValueNameLen + 1;            //Include space for the NULL terminator\r
+            DWORD dwMaxValueNameSizeInBytes = dwMaxValueNameSizeInChars * sizeof(TCHAR);\r
+            DWORD dwMaxValueDataSizeInChars = dwMaxValueLen/sizeof(TCHAR) + 1;  //Include space for the NULL terminator\r
+            DWORD dwMaxValueDataSizeInBytes = dwMaxValueDataSizeInChars * sizeof(TCHAR);\r
+            wxWCharBuffer *szValueName   = new wxWCharBuffer(dwMaxValueNameSizeInBytes);\r
+            wxWCharBuffer *byValue       = new wxWCharBuffer(dwMaxValueDataSizeInBytes);\r
+            bSuccess = TRUE;\r
+\r
+            //Enumerate all the values underneath HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM\r
+            DWORD dwIndex = 0;\r
+            DWORD dwType;\r
+            DWORD dwValueNameSize   = dwMaxValueNameSizeInChars;\r
+            DWORD dwDataSize        = dwMaxValueDataSizeInBytes;\r
+            LONG nEnum = ::RegEnumValue(hSERIALCOMM, dwIndex,  (wchar_t *) szValueName, &dwValueNameSize, NULL, &dwType, (LPBYTE) byValue, &dwDataSize);\r
+            \r
+            while(nEnum == ERROR_SUCCESS)\r
+            {\r
+                //If the value is of the correct type, then add it to the array\r
+                if(dwType == REG_SZ)\r
+                {\r
+                    //TCHAR* szPort = reinterpret_cast<TCHAR*>(byValue.m_pData);\r
+                    TCHAR *szPort;\r
+                    szPort = (TCHAR *)byValue;\r
+                    ports.push_back(szPort);\r
+                }\r
+                //Prepare for the next time around\r
+                dwValueNameSize = dwMaxValueNameSizeInChars;\r
+                dwDataSize      = dwMaxValueDataSizeInBytes;\r
+                ++dwIndex;\r
+                nEnum = ::RegEnumValue(hSERIALCOMM, dwIndex, (wchar_t *) szValueName, &dwValueNameSize, NULL, &dwType, (LPBYTE) byValue, &dwDataSize);\r
+            }\r
+        }\r
+        //Close the registry key now that we are finished with it    \r
+        ::RegCloseKey(hSERIALCOMM);\r
+        if(dwQueryInfo != ERROR_SUCCESS)\r
+        {\r
+            ::SetLastError(dwQueryInfo);\r
+        }\r
+    }\r
+    return bSuccess;\r
+}\r
+\r
+bool UsingRegistryWxArrayString(wxArrayString ports)\r
+{\r
+    //Make sure we clear out any elements which may already be in the array(s)\r
+    ports.clear();\r
+    //What will be the return value from this function (assume the worst)\r
+    BOOL bSuccess = FALSE;\r
+\r
+    HKEY hSERIALCOMM;\r
+    if(::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("HARDWARE\\DEVICEMAP\\SERIALCOMM"), 0, KEY_QUERY_VALUE, &hSERIALCOMM) == ERROR_SUCCESS)\r
+    {\r
+        //Get the max value name and max value lengths\r
+        DWORD dwMaxValueNameLen;\r
+        DWORD dwMaxValueLen;\r
+        DWORD dwQueryInfo = ::RegQueryInfoKey(hSERIALCOMM, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &dwMaxValueNameLen, &dwMaxValueLen, NULL, NULL);\r
+        if(dwQueryInfo == ERROR_SUCCESS)\r
+        {\r
+            DWORD dwMaxNameSizeInChars = dwMaxValueNameLen + 1;            //Include space for the NULL terminator\r
+            DWORD dwMaxNameSizeInBytes = dwMaxNameSizeInChars * sizeof(TCHAR);\r
+            DWORD dwMaxDataSizeInChars = dwMaxValueLen/sizeof(TCHAR) + 1;  //Include space for the NULL terminator\r
+            DWORD dwMaxDataSizeInBytes = dwMaxDataSizeInChars * sizeof(TCHAR);\r
+            wxWCharBuffer *szValueName   = new wxWCharBuffer(dwMaxNameSizeInBytes);\r
+            wxWCharBuffer *byValue       = new wxWCharBuffer(dwMaxDataSizeInBytes);\r
+\r
+            bSuccess = TRUE;\r
+\r
+            //Enumerate all the values underneath HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM\r
+            DWORD dwIndex = 0;\r
+            DWORD dwType;\r
+            DWORD dwValueNameSize = dwMaxNameSizeInChars;\r
+            DWORD dwDataSize      = dwMaxDataSizeInBytes;\r
+            LONG nEnum = ::RegEnumValue(hSERIALCOMM, dwIndex,  (wchar_t *)&szValueName, &dwValueNameSize, NULL, &dwType, (LPBYTE) byValue, &dwDataSize);\r
+            wxString szPort;\r
+            \r
+            while(nEnum == ERROR_SUCCESS)\r
+            {\r
+                //If the value is of the correct type, then add it to the array\r
+                if(dwType == REG_SZ)\r
+                {\r
+                    szPort = wxString((LPBYTE)byValue);\r
+                    ports.push_back(szPort);\r
+                }\r
+                //Prepare for the next time around\r
+                dwValueNameSize = dwMaxNameSizeInChars;\r
+                dwDataSize      = dwMaxDataSizeInBytes;\r
+                ++dwIndex;\r
+                nEnum = ::RegEnumValue(hSERIALCOMM, dwIndex, (wchar_t *) &szValueName, &dwValueNameSize, NULL, &dwType, (LPBYTE) byValue, &dwDataSize);\r
+            }\r
+        }\r
+        //Close the registry key now that we are finished with it    \r
+        ::RegCloseKey(hSERIALCOMM);\r
+        if (dwQueryInfo != ERROR_SUCCESS)\r
+        {\r
+            ::SetLastError(dwQueryInfo);\r
+        }\r
+    }\r
+    return bSuccess;\r
+}\r
+\r
+#endif //__WXMSW__\r