Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
Joined: Apr 2004
|
RE: Registry Class
I've downloaded your latest registry library, but there seems to be a bug in the Registry_KeyValueExist function.
The function code says:
code: function Registry_KeyValueExist(lKeyLocation, sKey, sKeyName){
var hKey = Interop.Allocate(4);
var sTmp = Interop.Allocate(4);
var lActualType = Interop.Allocate(4);
var lRetVal = Interop.Call('advapi32.dll', 'RegOpenKeyExW', lKeyLocation, sKey, 0, KEY_READ, hKey);
if (lRetVal === ERROR_SUCCESS){
lRetVal = Interop.Call('advapi32.dll', 'RegQueryValueExW', hKey.ReadDWORD(0), sKeyName, 0, lActualType, sTmp, 0);
Registry_CloseKey(hKey.ReadDWORD(0));
return lRetVal === ERROR_SUCCESS;
}else{ return false; }
}
However, the function always returned false. This caused my script to restore the defaults every time the script started up, and so I simply had to get this fixed. When I debugged this, I found that after the RegQueryValueExW call, lRetVal was equal to 87. After looking up this value, I found that this was the ERROR_INVALID_PARAMETER constant. So, I checked the parameters section of this function's MSDN page and found this:
quote: Originally posted by MSDN: RegQueryValueEx
lpcbData
[in, out] A pointer to a variable that specifies the size of the buffer pointed to by the lpData parameter, in bytes. When the function returns, this variable contains the size of the data copied to lpData.
The lpcbData parameter can be NULL only if lpData is NULL.
...
Now, in the function call lpcbData is 0 but lpData isn't! So, after modifying the call to:
code: lRetVal = Interop.Call('advapi32.dll', 'RegQueryValueExW', hKey.ReadDWORD(0), sKeyName, 0, 0, 0, 0);
it worked!
This means, that you can replace the whole function by just this:
code: function Registry_KeyValueExist(lKeyLocation, sKey, sKeyName){
var hKey = Interop.Allocate(4);
var lRetVal = Interop.Call('advapi32.dll', 'RegOpenKeyExW', lKeyLocation, sKey, 0, KEY_READ, hKey);
if (lRetVal === ERROR_SUCCESS){
lRetVal = Interop.Call('advapi32.dll', 'RegQueryValueExW', hKey.ReadDWORD(0), sKeyName, 0, 0, 0, 0);
Registry_CloseKey(hKey.ReadDWORD(0));
return lRetVal === ERROR_SUCCESS;
}else{ return false; }
}
This leaves with just one (!) instead of three buffers used.
|
|