?
Solved

problem with binary registry value

Posted on 2003-03-25
12
Medium Priority
?
446 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
12 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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

All of the resources available today make learning a new digital media easier than ever-- if you know where to begin. This is a clear, simple guide to a few of the basic digital art mediums and how to begin learning them on your own.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

752 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