Solved

RegQueryValue() weirdness

Posted on 1997-10-12
11
348 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
error email attachment VB2010 5 54
How to update List item Managed Metadata Column with JSOM 2 245
Where does legacy ASP.NET initialize language? 2 58
Graph API & MS Apps 1 53
This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

756 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