?
Solved

RegQueryValue() weirdness

Posted on 1997-10-12
11
Medium Priority
?
355 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
[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
11 Comments
 
LVL 4

Expert Comment

by:tflai
ID: 1407307
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
ID: 1407308
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
ID: 1407309
Why should I?

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

0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 11

Author Comment

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

0
 
LVL 7

Expert Comment

by:faster
ID: 1407311
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
 
LVL 11

Author Comment

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

0
 
LVL 11

Author Comment

by:alexo
ID: 1407313
Time to reopen the question.

0
 
LVL 4

Accepted Solution

by:
tflai earned 120 total points
ID: 1407314
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
ID: 1407315
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
ID: 1407316
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
ID: 1407317
OK.  That seems to wrap it up.

0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

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