From: Vadim Zeitlin Date: Thu, 12 Oct 2000 23:40:26 +0000 (+0000) Subject: added QueryRawValue() to wxRegKey and test code for it in the sample X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/6dfec4b8d901b13f11745a1371083a0b8c1c6980 added QueryRawValue() to wxRegKey and test code for it in the sample git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8543 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/msw/registry.h b/include/wx/msw/registry.h index 134267eef0..1a6bf68fcf 100644 --- a/include/wx/msw/registry.h +++ b/include/wx/msw/registry.h @@ -182,8 +182,14 @@ public: // set the string value bool SetValue(const wxChar *szValue, const wxString& strValue); - // return the string value - bool QueryValue(const wxChar *szValue, wxString& strValue) const; + // retrieve the string value + bool QueryValue(const wxChar *szValue, wxString& strValue) const + { return QueryValue(szValue, strValue, FALSE); } + // retrieve raw string value + bool QueryRawValue(const wxChar *szValue, wxString& strValue) const + { return QueryValue(szValue, strValue, TRUE); } + // retrieve either raw or expanded string value + bool QueryValue(const wxChar *szValue, wxString& strValue, bool raw) const; #ifdef __WIN32__ // set the numeric value diff --git a/samples/console/console.cpp b/samples/console/console.cpp index e33f32e87c..7b1313c567 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -49,8 +49,9 @@ //#define TEST_LONGLONG //#define TEST_MIME //#define TEST_INFO_FUNCTIONS +#define TEST_REGISTRY //#define TEST_SOCKETS -#define TEST_STREAMS +//#define TEST_STREAMS //#define TEST_STRINGS //#define TEST_THREADS //#define TEST_TIMER @@ -1054,6 +1055,87 @@ static void TestLongLongComparison() #endif // TEST_LONGLONG +// ---------------------------------------------------------------------------- +// registry +// ---------------------------------------------------------------------------- + +// this is for MSW only +#ifndef __WXMSW__ + #undef TEST_REGISTRY +#endif + +#ifdef TEST_REGISTRY + +#include + +// I chose this one because I liked its name, but it probably only exists under +// NT +static const wxChar *TESTKEY = + _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl"); + +static void TestRegistryRead() +{ + puts("*** testing registry reading ***"); + + wxRegKey key(TESTKEY); + printf("The test key name is '%s'.\n", key.GetName().c_str()); + if ( !key.Open() ) + { + puts("ERROR: test key can't be opened, aborting test."); + + return; + } + + size_t nSubKeys, nValues; + if ( key.GetKeyInfo(&nSubKeys, NULL, &nValues, NULL) ) + { + printf("It has %u subkeys and %u values.\n", nSubKeys, nValues); + } + + printf("Enumerating values:\n"); + + long dummy; + wxString value; + bool cont = key.GetFirstValue(value, dummy); + while ( cont ) + { + printf("Value '%s': type ", value.c_str()); + switch ( key.GetValueType(value) ) + { + case wxRegKey::Type_None: printf("ERROR (none)"); break; + case wxRegKey::Type_String: printf("SZ"); break; + case wxRegKey::Type_Expand_String: printf("EXPAND_SZ"); break; + case wxRegKey::Type_Binary: printf("BINARY"); break; + case wxRegKey::Type_Dword: printf("DWORD"); break; + case wxRegKey::Type_Multi_String: printf("MULTI_SZ"); break; + default: printf("other (unknown)"); break; + } + + printf(", value = "); + if ( key.IsNumericValue(value) ) + { + long val; + key.QueryValue(value, &val); + printf("%ld", val); + } + else // string + { + wxString val; + key.QueryValue(value, val); + printf("'%s'", val.c_str()); + + key.QueryRawValue(value, val); + printf(" (raw value '%s')", val.c_str()); + } + + putchar('\n'); + + cont = key.GetNextValue(value, dummy); + } +} + +#endif // TEST_REGISTRY + // ---------------------------------------------------------------------------- // sockets // ---------------------------------------------------------------------------- @@ -3612,6 +3694,10 @@ int main(int argc, char **argv) TestUserInfo(); #endif // TEST_INFO_FUNCTIONS +#ifdef TEST_REGISTRY + TestRegistryRead(); +#endif // TEST_REGISTRY + #ifdef TEST_SOCKETS if ( 0 ) { diff --git a/src/msw/registry.cpp b/src/msw/registry.cpp index a761867e7d..c67b5ba3d5 100644 --- a/src/msw/registry.cpp +++ b/src/msw/registry.cpp @@ -27,7 +27,6 @@ #include "wx/string.h" #include "wx/intl.h" #include "wx/log.h" -#include "wx/config.h" // for wxExpandEnvVars #ifndef __WIN16__ @@ -316,6 +315,9 @@ bool wxRegKey::GetKeyInfo(size_t *pnSubKeys, #define REG_PARAM (LPDWORD) #endif + // it might be unexpected to some that this function doesn't open the key + wxASSERT_MSG( IsOpened(), _T("key should be opened in GetKeyInfo") ); + m_dwLastError = ::RegQueryInfoKey ( (HKEY) m_hKey, @@ -343,8 +345,8 @@ bool wxRegKey::GetKeyInfo(size_t *pnSubKeys, GetName().c_str()); return FALSE; } - else - return TRUE; + + return TRUE; #else // Win16 wxFAIL_MSG("GetKeyInfo() not implemented"); @@ -823,7 +825,9 @@ bool wxRegKey::QueryValue(const wxChar *szValue, long *plValue) const #endif //Win32 -bool wxRegKey::QueryValue(const wxChar *szValue, wxString& strValue) const +bool wxRegKey::QueryValue(const wxChar *szValue, + wxString& strValue, + bool raw) const { if ( CONST_CAST Open() ) { #ifdef __WIN32__ @@ -846,6 +850,30 @@ bool wxRegKey::QueryValue(const wxChar *szValue, wxString& strValue) const pBuf, &dwSize); strValue.UngetWriteBuf(); + + // expand the var expansions in the string unless disabled + if ( (dwType == REG_EXPAND_SZ) && !raw ) + { + DWORD dwExpSize = ::ExpandEnvironmentStrings(strValue, NULL, 0); + bool ok = dwExpSize != 0; + if ( ok ) + { + wxString strExpValue; + ok = ::ExpandEnvironmentStrings + ( + strValue, + strExpValue.GetWriteBuf(dwExpSize), + dwExpSize + ) != 0; + strExpValue.UngetWriteBuf(); + strValue = strExpValue; + } + + if ( !ok ) + { + wxLogLastError(_T("ExpandEnvironmentStrings")); + } + } } if ( m_dwLastError == ERROR_SUCCESS ) { diff --git a/wxBase.dsp b/wxBase.dsp index 9cea60da62..d1819fe8f0 100644 --- a/wxBase.dsp +++ b/wxBase.dsp @@ -41,7 +41,7 @@ RSC=rc.exe # PROP Intermediate_Dir "BaseRelease" # PROP Target_Dir "" # ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MT" /YX /FD /c -# ADD CPP /nologo /MD /W4 /Zi /O2 /I "$(wx)\include" /I "$(wx)\src\zlib" /D "NDEBUG" /D wxUSE_GUI=0 /D WIN95=1 /D "__WIN95__" /D "WIN32" /D "_WIN32" /D WINVER=0x400 /D "__WINDOWS__" /D "__WXMSW__" /D "__WIN32__" /D "_MT" /Yu"wx/wxprec.h" /FD /c +# ADD CPP /nologo /MD /W4 /Zi /O2 /I "include" /I "src\zlib" /D "NDEBUG" /D wxUSE_GUI=0 /D WIN95=1 /D "__WIN95__" /D "WIN32" /D "_WIN32" /D WINVER=0x400 /D "__WINDOWS__" /D "__WXMSW__" /D "__WIN32__" /D "_MT" /Yu"wx/wxprec.h" /FD /c # ADD BASE RSC /l 0x409 # ADD RSC /l 0x409 BSC32=bscmake.exe @@ -64,7 +64,7 @@ LIB32=link.exe -lib # PROP Intermediate_Dir "BaseDebug" # PROP Target_Dir "" # ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MT" /YX /FD /c -# ADD CPP /nologo /MDd /W4 /Zi /Od /I "$(wx)\include" /I "$(wx)\src\zlib" /D "_DEBUG" /D DEBUG=1 /D WXDEBUG=1 /D "__WXDEBUG__" /D wxUSE_GUI=0 /D "__WIN95__" /D "WIN32" /D "_WIN32" /D WINVER=0x400 /D "__WINDOWS__" /D "__WIN32__" /D "__WXMSW__" /D "_MT" /Fr /Yu"wx/wxprec.h" /FD /c +# ADD CPP /nologo /MDd /W4 /Zi /Od /I "include" /I "src\zlib" /D "_DEBUG" /D DEBUG=1 /D WXDEBUG=1 /D "__WXDEBUG__" /D wxUSE_GUI=0 /D "__WIN95__" /D "WIN32" /D "_WIN32" /D WINVER=0x400 /D "__WINDOWS__" /D "__WIN32__" /D "__WXMSW__" /D "_MT" /Fr /Yu"wx/wxprec.h" /FD /c # ADD BASE RSC /l 0x409 # ADD RSC /l 0x409 BSC32=bscmake.exe @@ -80,13 +80,6 @@ LIB32=link.exe -lib # Name "wxBase - Win32 Release" # Name "wxBase - Win32 Debug" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=.\src\msw\dummy.cpp -# ADD CPP /Yc"wx/wxprec.h" -# End Source File # Begin Source File SOURCE=.\src\common\appcmn.cpp @@ -109,6 +102,19 @@ SOURCE=.\src\common\datstrm.cpp # End Source File # Begin Source File +SOURCE=.\src\msw\dde.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\msw\dir.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\msw\dummy.cpp +# ADD CPP /Yc"wx/wxprec.h" +# End Source File +# Begin Source File + SOURCE=.\src\common\dynarray.cpp # End Source File # Begin Source File @@ -125,6 +131,11 @@ SOURCE=.\src\common\event.cpp # End Source File # Begin Source File +SOURCE=.\src\common\extended.c +# SUBTRACT CPP /YX /Yc /Yu +# End Source File +# Begin Source File + SOURCE=.\src\common\ffile.cpp # End Source File # Begin Source File @@ -165,6 +176,16 @@ SOURCE=.\src\common\ftp.cpp # End Source File # Begin Source File +SOURCE=.\src\msw\gsocket.c +# SUBTRACT CPP /YX /Yc /Yu +# End Source File +# Begin Source File + +SOURCE=.\src\msw\gsockmsw.c +# SUBTRACT CPP /YX /Yc /Yu +# End Source File +# Begin Source File + SOURCE=.\src\common\hash.cpp # End Source File # Begin Source File @@ -173,6 +194,10 @@ SOURCE=.\src\common\http.cpp # End Source File # Begin Source File +SOURCE=.\src\common\init.cpp +# End Source File +# Begin Source File + SOURCE=.\src\common\intl.cpp # End Source File # Begin Source File @@ -193,10 +218,18 @@ SOURCE=.\src\common\longlong.cpp # End Source File # Begin Source File +SOURCE=.\src\msw\main.cpp +# End Source File +# Begin Source File + SOURCE=.\src\common\mimecmn.cpp # End Source File # Begin Source File +SOURCE=.\src\msw\mimetype.cpp +# End Source File +# Begin Source File + SOURCE=.\src\common\module.cpp # End Source File # Begin Source File @@ -221,6 +254,14 @@ SOURCE=.\src\common\protocol.cpp # End Source File # Begin Source File +SOURCE=.\src\msw\regconf.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\msw\registry.cpp +# End Source File +# Begin Source File + SOURCE=.\src\common\sckaddr.cpp # End Source File # Begin Source File @@ -261,124 +302,65 @@ SOURCE=.\src\common\textfile.cpp # End Source File # Begin Source File -SOURCE=.\src\common\timercmn.cpp -# End Source File -# Begin Source File - -SOURCE=.\src\common\tokenzr.cpp -# End Source File -# Begin Source File - -SOURCE=.\src\common\txtstrm.cpp -# End Source File -# Begin Source File - -SOURCE=.\src\common\url.cpp -# End Source File -# Begin Source File - -SOURCE=.\src\common\utilscmn.cpp -# End Source File -# Begin Source File - -SOURCE=.\src\common\variant.cpp -# End Source File -# Begin Source File - -SOURCE=.\src\common\wfstream.cpp -# End Source File -# Begin Source File - -SOURCE=.\src\common\wxchar.cpp -# End Source File -# Begin Source File - -SOURCE=.\src\common\zipstrm.cpp -# End Source File -# Begin Source File - -SOURCE=.\src\common\zstream.cpp +SOURCE=.\src\msw\thread.cpp # End Source File # Begin Source File -SOURCE=.\src\common\init.cpp -# End Source File - -# Begin Source File - -SOURCE=.\src\msw\dde.cpp +SOURCE=.\src\common\timercmn.cpp # End Source File # Begin Source File -SOURCE=.\src\msw\dir.cpp +SOURCE=.\src\common\tokenzr.cpp # End Source File # Begin Source File -SOURCE=.\src\msw\main.cpp +SOURCE=.\src\common\txtstrm.cpp # End Source File # Begin Source File -SOURCE=.\src\msw\mimetype.cpp +SOURCE=.\src\common\unzip.c +# SUBTRACT CPP /YX /Yc /Yu # End Source File # Begin Source File -SOURCE=.\src\msw\regconf.cpp +SOURCE=.\src\common\url.cpp # End Source File # Begin Source File -SOURCE=.\src\msw\registry.cpp +SOURCE=.\src\msw\utils.cpp # End Source File # Begin Source File -SOURCE=.\src\msw\thread.cpp +SOURCE=.\src\common\utilscmn.cpp # End Source File # Begin Source File -SOURCE=.\src\msw\utils.cpp +SOURCE=.\src\msw\utilsexc.cpp # End Source File # Begin Source File -SOURCE=.\src\msw\utilsexc.cpp +SOURCE=.\src\common\variant.cpp # End Source File - # Begin Source File -SOURCE=.\src\common\extended.c -# SUBTRACT CPP /YX /Yc /Yu +SOURCE=.\src\common\wfstream.cpp # End Source File # Begin Source File -SOURCE=.\src\common\unzip.c -# SUBTRACT CPP /YX /Yc /Yu +SOURCE=.\src\common\wxchar.cpp # End Source File - # Begin Source File -SOURCE=.\src\msw\gsocket.c -# SUBTRACT CPP /YX /Yc /Yu +SOURCE=.\src\common\y_tab.c +# PROP Exclude_From_Build 1 # End Source File # Begin Source File -SOURCE=.\src\msw\gsockmsw.c -# SUBTRACT CPP /YX /Yc /Yu +SOURCE=.\src\common\zipstrm.cpp # End Source File - - # Begin Source File -SOURCE=.\src\common\y_tab.c - -!IF "$(CFG)" == "wxBase - Win32 Release" - -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "wxBase - Win32 Debug" - -# ADD CPP /W1 -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - +SOURCE=.\src\common\zstream.cpp # End Source File # End Target # End Project