Solved

RegQueryValueEx( ) fails on NT, works on Win95?

Posted on 1997-05-16
3
544 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
Comment Utility
Edited text of question
0
 
LVL 1

Accepted Solution

by:
ete earned 50 total points
Comment Utility
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
Comment Utility
Well, duh!!  Thanks (grinning sheepishly)...
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now