I am trying to implement recursive deletion of Registry Keys for both 32-bit and 64-bit OS. As RegDeleteKeyEx is not defined for OSes lesser than XP x64 Professional, I am trying to use the function indirectly.
Problem:: Even on x64, the GetProcAddress() is returning NULL.
//Global Declarations
typedef LONG (WINAPI * PFN_RegDeleteKeyEx)(HKEY hKey , LPCTSTR lpSubKey , REGSAM samDesired , DWORD Reserved );
PFN_RegDeleteKeyEx _RegDeleteKeyEx ;
//The code inside function
hAdvAPI32 = LoadLibrary(TEXT("Advapi32.dll"));
_RegDeleteKeyEx = (PFN_RegDeleteKeyEx)GetProcAddress( hAdvAPI32, "RegDeleteKeyEx" );
if( _RegDeleteKeyEx == NULL )
printf("NULL\n") ;
RegDeleteKeyExisn’t actually a function – it’s a macro. Depending on whether you haveUNICODEdefined, the macro expands to the actual function name which is given at the bottom of the MSDN page:So in your case, you probably want something like
This will use the appropriate symbol name depending on how your own code is compiled (with or without
UNICODEdefined).