Reading Windows Registry data in 64 bit operating system
-
Hi friends, here is my query... I am working on win32. I am writing an application to read some data from registry. It is working on 32 bit machines. But it is not working on 64 bit machines. I am using the below API to read the data. RegQueryValueEx(hKey, pszEntry, NULL, NULL, (LPBYTE)pData, 200) Is there any problem with the last parameter size (200). What size to be passed as parameter. Thanks in advance. Regards Sairam M.
-
Hi friends, here is my query... I am working on win32. I am writing an application to read some data from registry. It is working on 32 bit machines. But it is not working on 64 bit machines. I am using the below API to read the data. RegQueryValueEx(hKey, pszEntry, NULL, NULL, (LPBYTE)pData, 200) Is there any problem with the last parameter size (200). What size to be passed as parameter. Thanks in advance. Regards Sairam M.
msr_codeproject wrote:
Is there any problem with the last parameter size (200). What size to be passed as parameter.
This parameter should be the address of (pointer to) a variable that contains the length of the buffer, as described here[^]. If this size is not large enough for the result then the call will fail and the required size will be entered into the variable. Thus if you make a call with the variable set to zero you can find out how big the buffer needs to be and allocate as appropriate. BTW I'm not sure why your question got downvoted so I have upped it to compensate.
It's time for a new signature.
-
msr_codeproject wrote:
Is there any problem with the last parameter size (200). What size to be passed as parameter.
This parameter should be the address of (pointer to) a variable that contains the length of the buffer, as described here[^]. If this size is not large enough for the result then the call will fail and the required size will be entered into the variable. Thus if you make a call with the variable set to zero you can find out how big the buffer needs to be and allocate as appropriate. BTW I'm not sure why your question got downvoted so I have upped it to compensate.
It's time for a new signature.
-
The strange thing is that your code actually worked in the 32 bit edition. Any call to
RegQueryValueEx
using your parameters would result in an attempt to write something at memory address 200. Not good. -
Mattias G wrote:
The strange thing is that your code actually worked
Firstly, that was the OP's code, not mine. Secondly, I don't think it did work correctly.
It's time for a new signature.
-
msr_codeproject wrote:
Is there any problem with the last parameter size (200). What size to be passed as parameter.
This parameter should be the address of (pointer to) a variable that contains the length of the buffer, as described here[^]. If this size is not large enough for the result then the call will fail and the required size will be entered into the variable. Thus if you make a call with the variable set to zero you can find out how big the buffer needs to be and allocate as appropriate. BTW I'm not sure why your question got downvoted so I have upped it to compensate.
It's time for a new signature.
Hi Guys, my trails are not working. I am giving you the path of the key. Please write small code to read it. Key Path: HKEY_CURRENT_USER\Software\ABCD\ABCD UD PCL6_00-00-00-00-00-00\printer_ui\icc_profile\0 Name of the filed: szResId Type of the field: REG_DWORD Data at the field: 0x000084d6(34006) Now I want to read 0x000084d6. I tried in so many ways. But it wasn't worked. Help me. Regards msr_codeproject
-
Hi Guys, my trails are not working. I am giving you the path of the key. Please write small code to read it. Key Path: HKEY_CURRENT_USER\Software\ABCD\ABCD UD PCL6_00-00-00-00-00-00\printer_ui\icc_profile\0 Name of the filed: szResId Type of the field: REG_DWORD Data at the field: 0x000084d6(34006) Now I want to read 0x000084d6. I tried in so many ways. But it wasn't worked. Help me. Regards msr_codeproject
msr_codeproject wrote:
I tried in so many ways. But it wasn't worked. Help me.
Show the code you've tried so far.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
Hi friends, here is my query... I am working on win32. I am writing an application to read some data from registry. It is working on 32 bit machines. But it is not working on 64 bit machines. I am using the below API to read the data. RegQueryValueEx(hKey, pszEntry, NULL, NULL, (LPBYTE)pData, 200) Is there any problem with the last parameter size (200). What size to be passed as parameter. Thanks in advance. Regards Sairam M.
The last parameter is wrong. It needs to be a pointer to a DWORD that gives the size of the buffer, not the size of the buffer itself. Currently, your code is using the value of the memory at address 200 as the buffer size, and that could be anything... Try:
DWORD cbSize = 200;
RegQueryValueEx(hKey, pszEntry, NULL, NULL, (LPBYTE)pData, &cbSize);
-
Hi Guys, my trails are not working. I am giving you the path of the key. Please write small code to read it. Key Path: HKEY_CURRENT_USER\Software\ABCD\ABCD UD PCL6_00-00-00-00-00-00\printer_ui\icc_profile\0 Name of the filed: szResId Type of the field: REG_DWORD Data at the field: 0x000084d6(34006) Now I want to read 0x000084d6. I tried in so many ways. But it wasn't worked. Help me. Regards msr_codeproject
Try the following:
static PWSTR pszKeyName = L"Software\\ABCD\\ABCD UD PCL6_00-00-00-00-00-00\\printer_ui\\icc_profile";
LONG lResult;
HKEY hkMyKey;
DWORD dwDisposition;
DWORD dwType;
DWORD dwData;
DWORD dwSize;lResult = RegCreateKeyEx(HKEY_CURRENT_USER,
pszKeyName,
0,
NULL,
0,
KEY_READ,
NULL,
&hkMyKey,
&dwDisposition
);
if (ERROR_SUCCESS == lResult)
{
dwSize = sizeof dwData;
lResult = RegGetValue(hkMyKey,
L"0",
L"szResId",
RRF_RT_ANY,
&dwType,
&dwData,
&dwSize
);
}Note: this is a Win32 solution, I don't have access to a 64-bit system.
It's time for a new signature.
-
Try the following:
static PWSTR pszKeyName = L"Software\\ABCD\\ABCD UD PCL6_00-00-00-00-00-00\\printer_ui\\icc_profile";
LONG lResult;
HKEY hkMyKey;
DWORD dwDisposition;
DWORD dwType;
DWORD dwData;
DWORD dwSize;lResult = RegCreateKeyEx(HKEY_CURRENT_USER,
pszKeyName,
0,
NULL,
0,
KEY_READ,
NULL,
&hkMyKey,
&dwDisposition
);
if (ERROR_SUCCESS == lResult)
{
dwSize = sizeof dwData;
lResult = RegGetValue(hkMyKey,
L"0",
L"szResId",
RRF_RT_ANY,
&dwType,
&dwData,
&dwSize
);
}Note: this is a Win32 solution, I don't have access to a 64-bit system.
It's time for a new signature.
Richard MacCutchan wrote:
static PWSTR pszKeyName = L"Software\\ABCD\\ABCD UD PCL6_00-00-00-00-00-00\\printer_ui\\icc_profile";
I think you should make pszKeyName constant (i.e. static LPCWSTR), considering you're referencing it to memory (the string literal) that could be read-only.
-
Richard MacCutchan wrote:
static PWSTR pszKeyName = L"Software\\ABCD\\ABCD UD PCL6_00-00-00-00-00-00\\printer_ui\\icc_profile";
I think you should make pszKeyName constant (i.e. static LPCWSTR), considering you're referencing it to memory (the string literal) that could be read-only.
MicroVirus wrote:
I think you should make pszKeyName constant (i.e. static LPCWSTR), considering you're referencing it to memory (the string literal) that could be read-only.
This is a simple example of how to get a value from a registry key; making the keyname
const
will have no effect on the code I provided.It's time for a new signature.
-
MicroVirus wrote:
I think you should make pszKeyName constant (i.e. static LPCWSTR), considering you're referencing it to memory (the string literal) that could be read-only.
This is a simple example of how to get a value from a registry key; making the keyname
const
will have no effect on the code I provided.It's time for a new signature.
Richard MacCutchan wrote:
This is a simple example of how to get a value from a registry key; making the keyname const will have no effect on the code I provided.
True, but it's still good to realise that it should be const. If someone reads your post and decides to adapt it, having it to const to begin with could be useful. I know, I'm whining... :sigh: It's just that I feel it's an overlooked detail; I forget it myself, so that's why I find it important