Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem with RegQueryValueEx

Posted on 1997-06-08
2
Medium Priority
?
775 Views
Last Modified: 2013-11-20
I'm having a problem with the RegQueryValueEx function - it's returning error code 87 (Invalid Parameter), and it's due to the 5th parameter.  I know this, because it returns ERROR_SUCCESS if I make this parameter NULL.

      CString sPwd;
      HKEY      phk;
      char      sPwdReg[10];
      DWORD      dwType;
      DWORD      dwcbData;

//#ifdef WIN32_EXTRA_LEAN
//      this_statement_will_generate_compile_error;
//#endif
      if (::RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\a\\b",
                  0, KEY_ALL_ACCESS, &phk) != ERROR_SUCCESS)
            return;
      AfxMessageBox("OpenKey worked");

      long lRet = ::RegQueryValueEx(phk, (LPTSTR) "Password", NULL, NULL,
                  (LPBYTE) sPwdReg, &dwcbData);

      AfxMessageBox("QueryValue worked");

      CString msg;
      msg.Format("lRet = %ld", lRet);
      AfxMessageBox(msg);

The "Password" registry value is a string, by the way.  Does anybody know what I'm doing wrong here?  I've looked through all the examples in the Visual C++ documentation, and found no clues.  I've seen this argument typecast to LPCTSTR or LPTSTR, but this won't compile.  I've also tried using a char* argument, and allocating memory to it with malloc, but this shouldn't make a difference, and it didn't.

A possibly related problem is that in my Project Settings/C/C++ Tab/Preprocessor Category, I have undefined WIN32_EXTRA_LEAN in order for the compiler to include "winreg.h", which is needed for the registry API.  However, if I uncomment the #ifdef WIN32_EXTRA_LEAN directive, I find that WIN32_EXTRA_LEAN *is* defined.  I cannot figure this out - I'm working around it by just explicitly including "winreg.h".
0
Comment
Question by:nbranitsky
[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
2 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 400 total points
ID: 1302032
You should initialize dwcbData to the size of the buffer in bytes before passing it to ::RegQueryValueEx().

DWORD dwcbData = sizeof(sPwdReg);

0
 

Author Comment

by:nbranitsky
ID: 1302033
Thanks.  That should teach me to read the documentation more closely!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

688 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