Jessica
Jessica

Reputation: 2035

Dynamically loading registry function on Windows 7?

I am dynamically loading several registry API's from the library Advapi32.dll. Under Windows XP and Vista everything is OK. Under Windows 7 I keep getting the error The parameter is incorrect and in some cases (like RegCloseKey) my application crashes.

The code I am using is the usual:

// RegCreateKeyEx
typedef LONG (WINAPI *MyRegCreateKeyEx)(HKEY, LPCTSTR, DWORD, LPTSTR, DWORD, REGSAM, LPSECURITY_ATTRIBUTES, PHKEY, LPDWORD);
MyRegCreateKeyEx LoadedRegCreateKeyEx;

then I use LoadLibrary to load Advapi.dll and GetProcAddress to find the address to RegCreateKeyEx. Like:

LoadedRegCreateKeyEx = (MyRegCreateKeyEx)GetProcAddress(LibHandle, "RegCreateKeyEx");

Everything returns OK, there are no errors and the pointers seem to be correct, yet it doesn't work under Windows 7. Any ideas? Did anything change? Is there a different way to do this for Windows 7?

Thank you jess.

EDIT: It seems that this problem extends to all kind of API's on windows 7. Any idea?

Upvotes: 0

Views: 309

Answers (2)

Jessica
Jessica

Reputation: 2035

The problem was getting the right offset from the library. Once I got it everything worked correctly

Upvotes: 1

MSN
MSN

Reputation: 54604

You might want to specify the correct version when you call GetProcAddress, i.e., A for ANSI and W for UNICODE.

Upvotes: 2

Related Questions