GetProcAddress returning NULL for RegDeleteKeyEx

后端 未结 2 1478
太阳男子
太阳男子 2020-12-12 00:52

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 Pro

2条回答
  •  感动是毒
    2020-12-12 01:06

    RegDeleteKeyEx isn't actually a function - it's a macro. Depending on whether you have UNICODE defined, the macro expands to the actual function name which is given at the bottom of the MSDN page:

    RegDeleteKeyExW (Unicode) and RegDeleteKeyExA (ANSI)
    

    So in your case, you probably want something like

    #ifdef UNICODE
        const char RegDeleteKeyExSymbol[] = "RegDeleteKeyExW";
    #else 
        const char RegDeleteKeyExSymbol[] = "RegDeleteKeyExA";
    #endif
    
    _RegDeleteKeyEx = (PFN_RegDeleteKeyEx)GetProcAddress( hAdvAPI32, RegDeleteKeyExSymbol );
    

    This will use the appropriate symbol name depending on how your own code is compiled (with or without UNICODE defined).

提交回复
热议问题