?
Solved

problem with binary registry value

Posted on 2003-03-25
12
Medium Priority
?
451 Views
Last Modified: 2013-11-15
Hi 2 all,

I wrote a function to get a STRING value out of my registry.The interessting part is this one...

RegOpenKeyEx(hMainKey, szSubKey, 0, KEY_QUERY_VALUE , &hOpenedKey)
DWORD cbData = (DWORD)20;
char r_value[20];
RegQueryValueEx(hOpenedKey,szValueName,NULL,NULL,(LPBYTE)r_value, &cbData);
cout << r_value << endl;;
....
It worked fine, but now I have a BINARY value with exactly the same content as the string value.
But in the "cout-line" it only shows me a stupid smily.
How can I manage it to get the value as a string?I also tryed to set the "lpType"-property to "REG_BINARY", but no difference at all....

Please help me...
0
Comment
Question by:Scotchman
  • 5
  • 5
11 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 8202355
I think RegQueryValueEx doesn't add NULL in the end when it reads binary key, You need to do this yourself before showing it on the screen.
0
 

Author Comment

by:Scotchman
ID: 8202378
I tried this, but I only get an access violation error

strcat(str,'\0');
0
 

Author Comment

by:Scotchman
ID: 8202424
After the "RegQueryValueEx" command, I tryed strlen(r_value) and recieved "1"!!!!So its not filled right anyway.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Expert Comment

by:AlexFM
ID: 8202743
Try to see str buffer in debugger (memory window). Other possible reason that registry key contains UNICODE string. It is converted to ANSI when key is STRING and not converted when key is BINARY.
0
 

Author Comment

by:Scotchman
ID: 8202783
The Reg Values content is 02 00 00 00 02 00 00 00 10
but the debugger tells me that str is "\x02"

0
 
LVL 48

Expert Comment

by:AlexFM
ID: 8202922
You try to work with binary data as with string. First 0 is treated as end of string. If binary data doesn't contain 0, you can get unpredictable results.
If you want to read a string from registry, read only REG_SZ value. Check output parameter pType, if it doesn't contain REG_SZ, consider function call to RegQueryValueEx as failed.
0
 

Author Comment

by:Scotchman
ID: 8202988
I already tried REG_SZ, but still no success, the value still only contains rubish in the debugger, ...
Any alternatives?There must be a way to access this string because I now other apps, which are doing this, but of course without open source code....
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 8203108
If Registry key contains data:
02 00 00 00 02 00 00 00 10
and you want to read it to string, the string will be:
0x2 \0

Maybe this is encripted information?
0
 

Author Comment

by:Scotchman
ID: 8203121
I know, but what I wan´t is the hole content as a string, like this:
"02 00 00 00 02 00 00 00 10"
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 80 total points
ID: 8203243
OK, after reading BINARY key you have char array:
r_value[0] = 2
r_value[1] = 0
...
r_value[8] = 10          (or 16 ?)

Convert it to string using any C data conversion functions, or sprintf, or print directly on the screen, but don't apply string functions to r_value - this is not string, just array! For example:

for ( i = 0; i < cbData; i++ )
    cout << r_value[i] << " ";
0
 
LVL 11

Expert Comment

by:bcladd
ID: 9558780
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered: Points to AlexFM

Please leave any comments here within the next seven days. Experts: Silence
means you don't care.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

-bcl (bcladd)
EE Cleanup Volunteer
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today as you open your Outlook, you witness an error message: “Outlook is using an old copy of your Outlook Data File…”. Probably, Outlook is accessing an old OST file.
This tutorial is intended to teach the basics of 3-D Modeling using TinkerCad.com as the Computer Aided Drafting software. Once complete this model can be 3D printed.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question