Solved

RegQueryValueEx( ) fails on NT, works on Win95?

Posted on 1997-05-16
3
556 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 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Issue when running a SSIS package (.dts) from an SQL job 21 83
Need to impress with my knowledge of .NET 5 90
Authentication of Web Services 3 74
Problem to open text file 11 113
This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
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 Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

832 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