Reading REG_BINARY from Windows Registry

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
Dee
Experienced Solver
Experienced Solver
Posts: 94
Joined: Sun Mar 27, 2005 7:56 pm

Reading REG_BINARY from Windows Registry

Post by Dee »

Hello!

I have the following problem: Suppose there's the key "HKLM\SYSTEM\CurrentControlSet\Services\test" in the registry with the value "LastApp" as REG_BINARY with content "xiii.exe". As binary it isn't shown as plain text but as hex-code "58004900490049002E006500780065000000".

Code: Select all

wxString regData;
wxRegKey* regKey=new wxRegKey("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\test");
regKey->QueryValue("LastApp", regData)
message(regData);                  // only shows a message box with the string
The output in the message box is "x" and not "xiii.exe" as you could suppose. That's the problem because the "00" in the binary code is the end-flag for a string in C++ and wxWindows.

I've got to workaround but there must be a simpler way:
a) I can export the value with regedit into a file and open the file afterwards.
b) I can set a pointer to regData, read every second letter and write this to a new string pointer. (So I hope that there is a end at some time...)

Could someone help?

Thanks, Dee
Ubuntu 6.06 with wxWindows 2.8.6
Dee
Experienced Solver
Experienced Solver
Posts: 94
Joined: Sun Mar 27, 2005 7:56 pm

Post by Dee »

Hm, does nobody use the windows registry? :(

Dee
Ubuntu 6.06 with wxWindows 2.8.6
mjs
Experienced Solver
Experienced Solver
Posts: 93
Joined: Wed Feb 09, 2005 3:53 am
Contact:

Post by mjs »

It seems that you're using wxWidgets in ANSI mode. The class member you're searching for has the following prototype:

Code: Select all

  bool  QueryValue(const wxChar *szValue, wxMemoryBuffer& buf) const;

You must use this member because you cannot know if the string stored in the binary key is ANSI or UNICODE - if it's a string at all.

Regards,
Mark
Dee
Experienced Solver
Experienced Solver
Posts: 94
Joined: Sun Mar 27, 2005 7:56 pm

Post by Dee »

Ah, thanks... That sounds possible. I have solved it now with a little workaround (like I said in posting 1):

Code: Select all

      const char* tstr=regData.c_str();
      for (int i=0; i<30 && tstr[i]!='\0'; i+=2) lastApp+=tstr[i];
I think with wxMemoryBuffer I could do nothing else as read one lyte by one and copy what I need.

Greetings,
Dee
Ubuntu 6.06 with wxWindows 2.8.6
Post Reply