Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

RegQueryValueEx( ) fails on NT, works on Win95?

Posted on 1997-05-16
3
Medium Priority
?
561 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
  • 2
3 Comments
 

Author Comment

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

Accepted Solution

by:
ete earned 100 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

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 …
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…
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…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

916 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