Jump to content

  • Log In with Google      Sign In   
  • Create Account

RegQueryValueEx


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 crazy_andy   Members   -  Reputation: 100

Like
0Likes
Like

Posted 03 June 2005 - 07:08 AM

I'm trying to get the value of a registry key, but im not sure how to use the function. Also whats the difference between RegQueryValueEx and RegGetValue which do I need to use? I looked at an example on msdn for RegQueryValueEx and it passed a PPREF_DATA_BLOCK, however on trying this I get an error: "PPREF_DATA_BLOCK is undeclared." what do I need to include to use that? basically does anyone have a good example of how to get the value from a registry key?

Sponsor:

#2 pragma Fury   Members   -  Reputation: 343

Like
0Likes
Like

Posted 03 June 2005 - 08:10 AM

Well, the immediate difference I see between the two methods is that RegGetValue has an additional parameter that lets you specify the type of data you are expecting to read (dwFlags). If the actual type of the key data doesn't match this, the call will fail.

Other than that, the methods appear to be identical.

Of course, RegGetValue() is only available on Windows XP Professional 64-bit edition, whereas RegQueryValueEx() will work on Everything from Windows 95 and up.

Unless you're coding specifically for WinXP Pro 64, I would suggest using RegQueryValueEx()

And here's an example that will read the "Version" value from the "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DirectX\" key.

#include <windows.h>
#include <stdio.h>
//...

//set up our variables and buffers.
DWORD dwType;
char szVersion[32];
DWORD dwDataSize=32;
memset(szVersion,0,32);

// open the key for reading.
HKEY hkeyDXVer;
long lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\DirectX\\", 0, KEY_READ, &hkeyDXVer);

if(ERROR_SUCCESS == lResult)
{

// read the version value
lResult = RegQueryValueEx(hkeyDXVer,"Version", NULL, &dwType, (BYTE*)szVersion, &dwDataSize);
if(ERROR_SUCCESS == lResult)
{
std::cout << "DirectX Version = " << szVersion << std::endl;
}
}





Quote:
Original post by crazy_andy:
I looked at an example on msdn for RegQueryValueEx and it passed a PPREF_DATA_BLOCK, however on trying this I get an error: "PPREF_DATA_BLOCK is undeclared." what do I need to include to use that?


Could you provide a link to this example?

[Edited by - pragma Fury on June 3, 2005 2:10:12 PM]

#3 crazy_andy   Members   -  Reputation: 100

Like
0Likes
Like

Posted 03 June 2005 - 11:51 AM

Quote:
Of course, RegGetValue() is only available on Windows XP Professional 64-bit edition, whereas RegQueryValueEx() will work on Everything from Windows 95 and up.

Unless you're coding specifically for WinXP Pro 64, I would suggest using RegQueryValueEx()


that would explain why my program crashed on trying to use it.

link to the example here
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/regqueryvalueex.asp


thanks for the info + code, rating++

#4 pragma Fury   Members   -  Reputation: 343

Like
0Likes
Like

Posted 03 June 2005 - 06:20 PM

PPERF_DATA_BLOCK is defined in WinPerf.h and is a pointer to a PERF_DATA_BLOCK structure, which is defined as:

typedef struct _PERF_DATA_BLOCK {
WCHAR Signature[4]; // Signature: Unicode "PERF"
DWORD LittleEndian; // 0 = Big Endian, 1 = Little Endian
DWORD Version; // Version of these data structures
// starting at 1
DWORD Revision; // Revision of these data structures
// starting at 0 for each Version
DWORD TotalByteLength; // Total length of data block
DWORD HeaderLength; // Length of this structure
DWORD NumObjectTypes; // Number of types of objects
// being reported
LONG DefaultObject; // Object Title Index of default
// object to display when data from
// this system is retrieved (-1 =
// none, but this is not expected to
// be used)
SYSTEMTIME SystemTime; // Time at the system under
// measurement
LARGE_INTEGER PerfTime; // Performance counter value
// at the system under measurement
LARGE_INTEGER PerfFreq; // Performance counter frequency
// at the system under measurement
LARGE_INTEGER PerfTime100nSec; // Performance counter time in 100 nsec
// units at the system under measurement
DWORD SystemNameLength; // Length of the system name
DWORD SystemNameOffset; // Offset, from beginning of this
// structure, to name of system
// being measured
} PERF_DATA_BLOCK, *PPERF_DATA_BLOCK;




Though I was able to cut'n'paste the example from msdn and it compiled without any problems.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS