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
Solved

RegQueryValue() weirdness

Posted on 1997-10-12
11
345 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
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 40 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 …
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

790 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