tags:

views:

92

answers:

2

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?

+2  A: 

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

MSN
Thank you. I am importing RegCreateKeyExA. but that one returns an error "invalid parameter" if I statically call RegCreateKeyExA with the same parameters then it works ok
Jessica
Just for the same of trying I imported the Unicode version and I got a completely different error: error 18 (ERROR_NO_MORE_FILES). I am puzzled.
Jessica
It seems that if you import the unicode version it works when you run a 32 bit binary on x86 and a 64 bit binary on x64, but not with WOW64 (when you run a 32 bit binary on an x64 Windows). Ideas?
Jessica
At this point I don't know why that's happening. I run Vista on x64 and I can't repro it with a 32-bit console app. (Which doesn't match your environment anyways.)
MSN
on vista is fine. can it be that I need to run the program in "XP mode"?
Jessica
I have no idea. Googling the error with GetProcAddress came up with nothing. Although it's also possible that the call to LoadLibrary failed instead of GetProcAddress.
MSN
so, I tested this and setting the program to run under the windows xp compatibility mode solved everything. Now I need to understand what to change since I can't use the xp compatibility mode
Jessica
+1  A: 

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

Jessica