GetProcAddress 为 RegDeleteKeyEx 返回 NULL [英] GetProcAddress returning NULL for RegDeleteKeyEx

查看:50
本文介绍了GetProcAddress 为 RegDeleteKeyEx 返回 NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 32 位和 64 位操作系统实现注册表项的递归删除.由于 RegDeleteKeyEx 不是为低于 XP x64 Professional 的操作系统定义的,我试图间接使用该函数.

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.

问题:: 即使在 x64 上,GetProcAddress() 也会返回 NULL.

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") ;

推荐答案

RegDeleteKeyEx 实际上不是一个函数——它是一个宏.根据您是否定义了 UNICODE,宏会扩展为 MSDN 页面底部给出的实际函数名称:

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 );

这将使用适当的符号名称,具体取决于您自己的代码的编译方式(是否定义了 UNICODE).

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

这篇关于GetProcAddress 为 RegDeleteKeyEx 返回 NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆