Solved

RegQueryValueEx( ) fails on NT, works on Win95?

Posted on 1997-05-16
3
559 Views
Last Modified: 2013-12-03
I have Registry-reading code that works fine on Win95, and fails on NT4; here's a snippet:HKEY hKey(NULL);DWORD dwDisp(0L);// First open the key (if it's there).if (ERROR_SUCCESS == ::RegOpenKeyEx(  HKEY_CURRENT_USER,  "Software\\MyCompany\\MyApp\\CustomerColWidths",  0L,  KEY_READ,  &hKey)) {   // If key there, open columns until you run out.   LONG lnReturn(ERROR_SUCCESS);   for (int nCol = 0; ERROR_SUCCESS == lnReturn; nCol++) {      CString sValueName;      sValueName.Format("Column%d", nCol);      DWORD dwReserved(0L);      DWORD dwType(0L);      DWORD dwData(0L);      DWORD dwDataSize(sizeof(DWORD));      BYTE* pData = reinterpret_cast<BYTE*> (&dwData);                              if (ERROR_SUCCESS == (lnReturn = ::RegQueryValueEx(        hKey,        sValueName,        &dwReserved,        &dwType,        pData,        &dwDataSize))) {                                       VERIFY(SetColumnWidth(nCol, dwData));      }      else {         // Be sure it failed because this column wasn't found in Registry.         ASSERT(ERROR_FILE_NOT_FOUND == lnReturn);      }   }   VERIFY(ERROR_SUCCESS == ::RegCloseKey(hKey));   hKey = NULL;}  On NT4, RegQueryValueEx( ) returns 87L (an illegal parameter) every time it executes.  The identical code runs fine on Win95.  The funny part is that this is *reading* a key, and it fails - *writing* a key, using ::RegSetValueEx( ), works fine on both systems.Any ideas?
0
Comment
Question by:laleonard
[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
3 Comments
 

Author Comment

by:laleonard
ID: 1397390
Edited text of question
0
 
LVL 1

Accepted Solution

by:
ete earned 50 total points
ID: 1397391
The LPDWORD lpReserved parameter must explicitly be NULL.

if (ERROR_SUCCESS == (lnReturn =
::RegQueryValueEx(
hKey,
sValueName,
NULL,
&dwType,
pData,
&dwDataSize)))

This should solve your problem

Best regards
ETE
0
 

Author Comment

by:laleonard
ID: 1397392
Well, duh!!  Thanks (grinning sheepishly)...
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

690 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