Looking for C++ help

I'm not a C++ coder. So in my effort trying to reintroduce getRegistryEntry into Mozilla Firefox I could need some help. It should be pretty simple.

I need some help in adding a function to the nsWindowsShellService.cpp file.

I think I need something like this:

NS_IMETHODIMP
nsWindowsShellService::GetRegistryEntry(const char *aKeyName, const char *aValueName)
{
char buf[MAX_BUF];
DWORD len = sizeof buf;

DWORD result = ::RegQueryValueEx(aKeyName, aValueName, NULL, NULL, (LPBYTE)buf, &len);
return result;
}

But I'm not a C++ coder and this wont compile and I dont think it's doing what it's supposed to do.

You can see how it's implemented in Mozilla 1.x here. But we dont want it that way. Here's what ben said in his review of my first patch:

There's no need for a new file, nor a need to add back any of the old excessively complex code. No structs, no classes, no byzantine object structure, just some good ol' fashioned Windows C code. Simply add a method to nsIWindowsShellService called getRegistryEntry that takes a string key name and a value name, so you can call: var val = wss.getRegistryEntry("HKEY_CURRENT_USER\\blah\\blah\\blah\\", "val");

If you're up to it you can attach a patch to bug 237754 or contact me so we can work together on a patch.


April 15, 2004 08:29 AM | Posted in Mozilla

Ads:

Back Next

4 Comments

It looks like you need to pull out the registry reading code from nsWindowsShellServiceUtil.cpp and put it into the body of getRegistryEntry().

Something like replacing the lines:
+ // Get requested registry entry.
+ nsCAutoString entry( RegistryEntry( hKey, aSubKeyName, aValueName, 0 ).currentSetting() );
+
+ // Copy to result.
+ *aResult = PL_strdup( entry.get() );

With this:

HKEY hSubkey;
LONG rc = ::RegOpenKey( hKey, aSubKeyName, &hSubkey );
if ( rc == ERROR_SUCCESS ) {
char buffer[4096] = { 0 };
DWORD len = sizeof buffer;
rc = ::RegQueryValueEx( hSubkey, aValueName, NULL, NULL, (LPBYTE)buffer, &len );
if ( rc == ERROR_SUCCESS ) {
*aResult = PL_strdup(buffer);
}
else {
*aResult = NULL;
}
}
::RegCloseKey( hSubkey );

(indentation is totally messed up here thanks to HTML, but just copy the code/indentation from nsWindowsShellServiceUtil.cpp and adjust some variable names)

Note that this doesn't address Ben's comment that the parameters to the function should take a string for the key name; rather it keeps the current interface, which is already pretty close to what he wants. Maybe he can live with that, but if not, then you'll need to do some string manipulation to pull the starting key name off from the beginning of the key name parameter and strcmp() it to some string constants so you can convert them into enums like HKEY_LOCAL_MACHINE, etc. to use as the first param to RegOpenKey.

Comment by Tom Downey at April 15, 2004 03:49 PM | Permalink

Someone now has submitted a patch to the bug, and Ben says he'll look at it tomorrow!

Site icon Comment by Henrik Gemal at April 15, 2004 10:25 PM | Permalink

I need to reuse lineOfText and write a for loop to convert integers in the
array and put their hex values in lineOfText then display the string using
the label m_hexLineLabel.
//Display address heading
CString lineOfText;
for(int i=0; i<16; ++i)
{
lineOfText += " " + convert8(i);
}
m_addressHeadingLabel.put_caption(lineOfText);

Comment by Mike Dheel at April 25, 2004 05:06 PM | Permalink

you could also use cin and cout state ments like cout>DATA;
but you need int's for the cin that you want them to put in there for you.

Comment by mike at March 9, 2006 11:24 PM | Permalink

Post a comment




Remember Me?




Please enter the security code you see here

.
You're here: Home - Looking for C++ help
Get the Mozilla Firefox browser