What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Help - accessing the registry

Help - accessing the registry
Author: Message:
Choli
Elite Member
*****

Avatar
Choli

Posts: 4714
Reputation: 42
43 / Male / Flag
Joined: Jan 2003
O.P. Help - accessing the registry
I don't understand why the following code fails when I execute it in a script (of Plus, of course) and the same code works perfectly in Visual Basic (typing it using VB syntax, of course).

I'm trying to access the registry, so first of all, I have to open it, using RegOpenKeyEx, but it fails....
code:
var HKEY_CURRENT_USER = 0x80000001;
var KEY_ALL_ACCESS = 0xF003F;

var ret;
var key = Interop.Allocate(4);

var x = Interop.Allocate(10000);

ret = Interop.Call("advapi32.dll", "RegOpenKeyExW", HKEY_CURRENT_USER, "Software\\Patchou\\Messenger Plus! Live", 0, KEY_ALL_ACCESS, key);

if (ret != 0) {
    Debug.Trace("" + ret + " " + Interop.GetLastError());
    Interop.Call("kernel32.dll", "FormatMessageW", 0x00001000, 0, ret, 0, x, 1000, 0);
    Debug.Trace(x.ReadString(0));
}

The output in the debug window is
quote:
2 0
El sistema no puede hallar el archivo especificado.

That means, in english: "The system can't find the specified file".

Seeing the "2 0", I understand that the function RegOpenKeyEx fails, but GetLastError returns 0, ie: no error.

So it seems that it can't find the path "Software\Patchou\Messenger Plus! Live" under the HKCU branch of the registry. However, if I put only "Software", it opens it correctly. That, together with the fact that I can open it using VB, makes me think that Plus Live executes its scripts under another Windows account, therefore accessing another HKCU branch where there is no "Patchou" "folder". I know that's weird and stupid, but what else can it be?

Any ideas?

Thanks.
Messenger Plus! en espaņol:
<< http://www.msgpluslive.es/ >>
<< http://foro.msgpluslive.es/ >>
:plus4:
09-23-2006 06:53 PM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Help - accessing the registry
You just experienced a (known) Plus! bug ;) :

1) Plus! can't handle numbers larger than 0x80000000. (this should be fixed in next update). In fact, every interop function of Plus! requires SIGNED numbers instead of UNSIGNED numbers.

eg: ReadWord(), ReadDWord(), WriteDWord(), etc all require signed numbers.

so, instead of:
code:
var HKEY_CURRENT_USER = 0x80000001;
which will return the unsigned number 2147483649, use this:
code:
var HKEY_CURRENT_USER = 0x80000000 | 1;
which will return the equivalent, but signed, number -2147483647...

[edit]
or:
code:
var HKEY_CURRENT_USER = 0x80000001 & 0xFFFFFFFF;
[/edit]


The reason why certain keys do work is because Plus! interprets that provided unsigned number as a signed one (thus wrongly) and thus you actually open the key under a different main hive, namely HKEY_CLASSES_ROOT in this case (which does has a "Software" subkey).




2)
quote:
Return Values
If the function succeeds, the return value is ERROR_SUCCESS.

If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.
Thus those registry APIs don't use GetLastError, they return the error directly as the return value...

However, I must say Interop.GetLastError always returns 0 with me too with certain APIs (APIs which do provide the error in GetLastError).

This post was edited on 09-23-2006 at 07:59 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
09-23-2006 07:12 PM
Profile PM Find Quote Report
Choli
Elite Member
*****

Avatar
Choli

Posts: 4714
Reputation: 42
43 / Male / Flag
Joined: Jan 2003
O.P. RE: Help - accessing the registry
EDIT:
It seems that my Plus still doesn't handle numbers bigger than 0x80000000 correctly. What Cookie sugggested me, works correctly, as well as defining the HKCU constant as -2147483647. Let's hope Patchou definitelly fixes for the next release :)

EDIT END.

Original post:


quote:
Originally posted by CookieRevised
You just experienced a (known) Plus! bug  :

1) Plus! can't handle numbers larger than 0x80000000. (this should be fixed in next update). so, use this instead:
err... well :P I forgot to say that I'm using a beta version which doesn't have that bug ;)

Also, if I open "HKCU\Software", it works correctly... the problem is while trying to open "HKCU\Software\Patchou\Messenger Plus! Live".
quote:
Originally posted by CookieRevised
Thus those registry APIs don't use GetLastError, they return the error directly as the return value
yeah, well, maybe i shouldn't have used GetLastError. Anyway, ERROR_SUCCESS is 0 and my RegOpenKeyEx returns 2, which passed through FormatMessage gives me the error: "The system can't find the specified file".

Maybe I should have reported this in the beta forum... but i don't think it's a problem with the beta

This post was edited on 09-23-2006 at 07:53 PM by Choli.
Messenger Plus! en espaņol:
<< http://www.msgpluslive.es/ >>
<< http://foro.msgpluslive.es/ >>
:plus4:
09-23-2006 07:30 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


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