Error reading default value with wxRegKey Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Laurent22300
Knows some wx things
Knows some wx things
Posts: 30
Joined: Sun Sep 07, 2008 9:38 am
Contact:

Error reading default value with wxRegKey

Post by Laurent22300 » Thu Nov 13, 2008 5:59 pm

Hello,

I'm using wxRegKey to read some value in the registry. This is what I'm doing:

Code: Select all

wxRegKey* regKey = new wxRegKey(_T("HKEY_CLASSES_ROOT\\.test"));

if (regKey->Exists()) {
  wxString defaultValue = regKey->QueryDefaultValue();    

  if (defaultValue != wxEmptyString) {
    // etc.
  } 
}
It works well in most case, except when the default value is undefined (it appears as "Value not set" in regedit). In that case, wxWidgets outputs a system error, which says "Can't read value of HKCR\\.test Value not set".

So is there any way to prevent this error? For example, is there any way to check if the default value exists before querying it? I've searched the help file but couldn't find anything. Any ideas?

Thanks,

Laurent

Laurent22300
Knows some wx things
Knows some wx things
Posts: 30
Joined: Sun Sep 07, 2008 9:38 am
Contact:

Post by Laurent22300 » Thu Nov 13, 2008 9:24 pm

I guess a solution would be to simply disable the error message. Is it possible to do that?

For information, the message is generated by wxLogSysError.

User avatar
doublemax
Moderator
Moderator
Posts: 15282
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax » Thu Nov 13, 2008 10:03 pm

temporarily create an instance of wxLogNull
http://docs.wxwidgets.org/stable/wx_wxl ... #wxlognull
Use the source, Luke!

Laurent22300
Knows some wx things
Knows some wx things
Posts: 30
Joined: Sun Sep 07, 2008 9:38 am
Contact:

Post by Laurent22300 » Thu Nov 13, 2008 10:14 pm

Thanks, that's exactly what I needed :D

Post Reply