Solved

RegQueryValue() weirdness

Posted on 1997-10-12
11
340 Views
Last Modified: 2013-12-03
Take a look at the following code:

char      buffer[MAX_PATH];
LONG      size = MAX_PATH;

RegQueryValue(HKEY_CLASSES_ROOT,
              "QuickView\\shell\\open\\command",
              buffer, &size);

The call to RegQueryValue() returns an error value of 13.
However, GetLastError() indicates there was no error, and the variables buffer and size get set to the correct values.

Where does this error 13 come from???

(I use RegQueryValue() and not RegQueryValueEx() because I want the default value associated with the key, and it is also simpler.)
0
Comment
Question by:alexo
11 Comments
 
LVL 4

Expert Comment

by:tflai
Comment Utility
Why don't you try to RegOpenKey() first before RegQueryValue():

HKEY hDestKey;
RegOpenKey(HKEY_CLASS_ROOT, "\\wherever...", &hDestKey);
RegQueryValue(.....same as what you did.....);
0
 
LVL 5

Expert Comment

by:y96andha
Comment Utility
What type of data is it that you are trying to read (REG_SZ, REG_DWORD and so on) ?
0
 
LVL 11

Author Comment

by:alexo
Comment Utility
Why should I?

The documentation says: RegQueryValue(key, subkey, ...)
The key I use is HKEY_CLASSES_ROOT, which is open by definition.

0
 
LVL 11

Author Comment

by:alexo
Comment Utility
I try to read the default value.
Regedit says it is a string.

0
 
LVL 7

Expert Comment

by:faster
Comment Utility
Thui is correct, you MUST open the key first.  The document also fooled me when I tried registry at the first time, I think it actually means that if you want to open a key which is the immediate child of HKEY_***, you can do it directly.

Just add this call and you will see the difference.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 11

Author Comment

by:alexo
Comment Utility
So how comes I still get the correct answer?
And GetLastError() returns zero - meaning no error.

0
 
LVL 11

Author Comment

by:alexo
Comment Utility
Time to reopen the question.

0
 
LVL 4

Accepted Solution

by:
tflai earned 40 total points
Comment Utility
The error code of 13 is defined in WINERROR.H as ERROR_INVALID_DATA.  But since you're using 16-bit RegQueryValue(), GetLastError() does not apply.  GetLastError() is only maintained on a per-thread basis.  Even though you get the string okay, it is still not recommended.  You REALLY do need to RegOpenKey/Ex() first and finish with RegCloseKey().
0
 
LVL 11

Author Comment

by:alexo
Comment Utility
Is RegQueryValue() a 16-bit API?  Where does it says so.
Why GetLastError() does not apply to 16-bit APIs?

0
 
LVL 4

Expert Comment

by:tflai
Comment Utility
RegQueryValue() is indeed a 16-bit API.  In face, MSDN strongly suggest that 32-bit application to use the equivalent 32-bit RegQueryValueEx() API.  Even MSVC's help book has that also.  The same document also mentioned that GetLastError() is only maintained on a per-thread basis.  And as you may know, 16-bit has its own one-and-only thread in the system.
0
 
LVL 11

Author Comment

by:alexo
Comment Utility
OK.  That seems to wrap it up.

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now