What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Registry Class

Registry Class
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
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! :O

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. :P
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
08-04-2007 11:27 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Registry Class - by LifelesS on 08-03-2007 at 07:01 PM
RE: Registry Class - by Ezra on 08-03-2007 at 07:17 PM
RE: Registry Class - by LifelesS on 08-03-2007 at 07:19 PM
RE: Registry Class - by Ezra on 08-03-2007 at 07:21 PM
RE: Registry Class - by LifelesS on 08-03-2007 at 07:23 PM
RE: Registry Class - by Ezra on 08-03-2007 at 07:28 PM
RE: RE: Registry Class - by LifelesS on 08-03-2007 at 07:34 PM
RE: Registry Class - by matty on 08-03-2007 at 08:16 PM
RE: RE: Registry Class - by LifelesS on 08-03-2007 at 08:19 PM
RE: Registry Class - by matty on 08-03-2007 at 08:23 PM
RE: Registry Class - by LifelesS on 08-03-2007 at 08:53 PM
RE: Registry Class - by Ezra on 08-03-2007 at 10:41 PM
RE: RE: Registry Class - by LifelesS on 08-03-2007 at 10:47 PM
RE: Registry Class - by matty on 08-04-2007 at 12:19 AM
RE: RE: Registry Class - by LifelesS on 08-04-2007 at 12:36 AM
RE: Registry Class - by matty on 08-04-2007 at 12:42 AM
RE: Registry Class - by Matti on 08-04-2007 at 11:27 AM
RE: Registry Class - by matty on 08-04-2007 at 12:02 PM
RE: Registry Class - by -dt- on 08-04-2007 at 12:16 PM
RE: Registry Class - by ShawnZ on 08-04-2007 at 12:18 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On