OSDN Git Service

registory.hpp: 6_値の読み取りまで対応!
authorMyun2 <myun2@nwhite.info>
Sun, 20 Mar 2011 04:27:44 +0000 (13:27 +0900)
committerMyun2 <myun2@nwhite.info>
Sun, 20 Mar 2011 04:27:44 +0000 (13:27 +0900)
roast_ex/include/roast/windows/registory.hpp
roast_ex/test/windows_window_test/registory_test.cpp [new file with mode: 0644]
roast_ex/test/windows_window_test/roast_test_3rd.vcproj

index e42bc98..3d1db54 100644 (file)
@@ -78,6 +78,24 @@ namespace roast
                                ::HKEY m_hKey;
                                ::std::string m_nowKey;
                                bool m_mode_write;
+
+                               bool _get_any_value(const char* szValueName, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData)
+                               {
+                                       ZeroMemory( lpData, *lpcbData );
+                                       LONG r = RegQueryValueEx(
+                                               m_hKey,                 //      hKey            - \83L\81[\82Ì\83n\83\93\83h\83\8b
+                                               szValueName,    //      lpValueName     - \83\8c\83W\83X\83g\83\8a\83G\83\93\83g\83\8a\96¼
+                                               NULL,                   //      lpReserved      - \97\\96ñ\8dÏ\82Ý
+                                               lpType,                 //      lpType          - \83f\81[\83^\8c^\82ª\8ai\94[\82³\82ê\82é\83o\83b\83t\83@
+                                               lpData,                 //      lpData          - \83f\81[\83^\82ª\8ai\94[\82³\82ê\82é\83o\83b\83t\83@
+                                               lpcbData                //      lpcbData        - \83f\81[\83^\83o\83b\83t\83@\82Ì\83T\83C\83Y
+                                       );
+                                       if ( r == ERROR_SUCCESS )
+                                               return true;
+                                       else {
+                                               return false;
+                                       }
+                               }
                        public:
                                key(const key& parent, const char* szSubKey){}
                                key(const key& parent, const char* szSubKey, bool mode_write){}
@@ -121,6 +139,69 @@ namespace roast
                                        }
                                        return true;
                                }
+
+                               /////
+
+                               DWORD get_dword_value(const char* szValueName)
+                               {
+                                       DWORD dwType = REG_NONE;
+                                       DWORD dwBufSize = sizeof(DWORD);
+                                       DWORD dwValue = 0;
+
+                                       //      \92l\82ð\8eæ\93¾
+                                       bool r = _get_any_value(szValueName, &dwType, (BYTE*)&dwValue, &dwBufSize);
+
+                                       //      \83G\83\89\81[\82Ì\83`\83F\83b\83N
+                                       if ( r == false )
+                                               return false;
+
+                                       //      \83^\83C\83v\82Ì\83`\83F\83b\83N
+                                       if ( dwType != REG_DWORD )
+                                       {
+                                               return false;
+                                       }
+                                       return false;
+                               }
+                               const char* get_str_value(const char* szValueName, char* szOutBuffer, int nOutBufferSize)
+                               {
+                                       DWORD dwType = REG_NONE;
+                                       DWORD dwBufSize = nOutBufferSize;
+
+                                       //      \92l\82ð\8eæ\93¾
+                                       bool r = _get_any_value( szValueName, &dwType, (BYTE*)szOutBuffer, &dwBufSize );
+
+                                       //      \83G\83\89\81[\82Ì\83`\83F\83b\83N
+                                       if ( r != true )
+                                               return NULL;
+
+                                       //      \83^\83C\83v\82Ì\83`\83F\83b\83N
+                                       if ( dwType != REG_SZ )
+                                       {
+                                               return NULL;
+                                       }
+                                       return szOutBuffer;
+                               }
+                               ::std::string get_str_value(const char* szValueName)
+                               {
+                                       char szWorkBuffer[1024];
+
+                                       DWORD dwType = REG_NONE;
+                                       DWORD dwBufSize = sizeof(szWorkBuffer);
+
+                                       //      \92l\82ð\8eæ\93¾
+                                       bool r = _get_any_value( szValueName, &dwType, (BYTE*)szWorkBuffer, &dwBufSize );
+
+                                       //      \83G\83\89\81[\82Ì\83`\83F\83b\83N
+                                       if ( r != true )
+                                               return NULL;
+
+                                       //      \83^\83C\83v\82Ì\83`\83F\83b\83N
+                                       if ( dwType != REG_SZ )
+                                       {
+                                               return NULL;
+                                       }
+                                       return szWorkBuffer;
+                               }
                        };
                        const _internal::rootkey_map key::_m_rootkey_map;
 
diff --git a/roast_ex/test/windows_window_test/registory_test.cpp b/roast_ex/test/windows_window_test/registory_test.cpp
new file mode 100644 (file)
index 0000000..985593d
--- /dev/null
@@ -0,0 +1,23 @@
+#include <stdio.h>
+#include "roast/windows/window.hpp"
+#include "roast/windows/registory.hpp"
+
+using namespace ::roast;
+using namespace ::roast::windows;
+
+void main()
+{
+       try
+       {
+               /*for(int i=0; i<100000; i++){
+                       regkey rk("HKEY_LOCAL_MACHINE\\SOFTWARE\\HoeHoe\\Lhaplus");
+                       rk.get_str_value("InstallPath");
+               }*/
+               regkey rk("HKEY_CURRENT_USER\\Software\\TortoiseSVN");
+               printf("%s\n", rk.get_str_value("LogFontName").c_str());
+       }
+       catch(::std::string &s)
+       {
+               printf("%s\n", s.c_str());
+       }
+}
index 6c1ffea..8077c5b 100644 (file)
                        UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
                        >
                        <File
-                               RelativePath=".\window_test.cpp"
+                               RelativePath=".\registory_test.cpp"
                                >
                        </File>
                </Filter>