Solved

RegQueryValue() weirdness

Posted on 1997-10-12
11
354 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

696 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