Archive: Registry API plugin/function help


Registry API plugin/function help
This thread started as a result of http://forums.winamp.com/showthread....hreadid=218669

I have an idea that I wanted to try to implement in my own function using API calls to Advapi32.dll based on info from MSDN.

I'd like to use API calls instead of REGEDIT to import/export because of the fact that differnt versions REGEDIT export differently. If I could use API calls, I could keep the process consistant without having to use a lot of OS checks. (I'd also have more registry handling options available to me in case I needed to use them.) Plus since I'm not well-versed in C++, I thought this might offer a simple solution

However, this is where I'm having problems:
I'm trying to call RegOpenKeyEx, but am having some problems. Here's what I got so far. (I'm using Stardock an example just becuase it was something I had in my registry already):

strcpy $3 "SOFTWARE\Stardock"
System::Call 'Advapi32::RegOpenKeyEx(i 0x80000002,t r3,i 0,i 0xF003F,i .r1)i .r2'
DetailPrint 'Result: $2'
DetailPrint 'Handle: $1'

I'm getting an error code 87 returned an no reg key handle.
(FYI: The main hive handle values I found at the bottom of this site.)

I'm hoping that someone will be able to point me in the right direction. (If I can figure out this function then I should be able to figure out the rest.

Thanks!

From MSDN:

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.
Assuming I'm looking at the right place in Winerror.h, this is what it says:

//
// MessageId: ERROR_INVALID_PARAMETER
//
// MessageText:
//
// The parameter is incorrect.
//
#define ERROR_INVALID_PARAMETER 87L // dderror
EDIT: Correct me if I'm wrong, but if I read the System plug-in documentation correctly, you need to prefix a variable with an asterisk to use a pointer to it instead. I think that's your problem - the fifth parameter of the function should be a pointer to your variable.

Hey, thanks for the tip! I'll give that a try.

PS: Where did you find WinError.h? Is that included with the NSIS source code or is it somewhere else?


It's in MSDN. Search for it, it should be the first result you find. The full name of the page is "Winerror.h [Protocol]".

If you have a local copy of MSDN, you'll probably have most luck if you search online, my local installation of MSDN (from the VS2005 beta 2) doesn't find it - though that may be because I don't have the C/C++ of the beta installed, and therefore no C/C++ documentation.


hmm... still no luck on getting the function call to work. I'll try more tomorrow...