c++ - Visual C++ 错误 : RegGetValueA could not be located

标签 c++ visual-studio-2010 windows-xp backwards-compatibility

尝试在 Visual Studio 2010 中编写一个简单的注册表检查脚本,在 XP SP3 x86 上运行。

构建时不会抛出任何错误,但在调试时程序会退出并出现以下错误:

The procedure entry point RegGetValueA could not be located in the dynamic link library ADVAPI32.dll

这是程序的全部代码。

// #define _WIN32_WINNT 0x0501

#include <stdlib.h>
#include <stdio.h>
#include <windows.h>

int main(int argc, char *argv[])
{
long reg = RegQueryValueEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", NULL,NULL,NULL,NULL);
// if (reg!=ERROR_SUCCESS) MessageBox(0, "Error Opening Registry Key", "Error", 0);
return 0;
}

上面代码中的注释是根据 wmeyer 的回答添加的。
取消注释时,代码不会因该错误而退出,而是会抛出一个不同的错误:

Debugging information for Test5.exe cannot be found or does not match. Binary was not built with debug information. Do you want to continue debugging?

如果我继续,MessageBox 会弹出“打开注册表项时出错”。

我尝试用以下三种其他方法替换 RegQueryValueEx 函数,一次一个。
我知道其中两个仅适用于 VISTA,但我想看看错误是否会有所不同。
它不是。

long reg = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_ALL_ACCESS, hKey);

// Vista+ PHKEY hKey;
long reg = RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", hKey);
long reg = RegGetValue(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", "", RRF_RT_ANY, NULL, NULL,NULL);

我已经花了好几个小时试图解决其他几个错误,例如“无法将参数 1 从‘char’转换为‘LPCWSTR’”——这已由 changing the configuration 解决 和“无法找到或打开 PDB 文件”,由 changing the configuration 解决.

所以再说一遍,问题要明确:

  1. 如何处理错误?
  2. 当 prog 没有 Vista 方法开始时,wmeyer 关于添加标题以过滤掉 Vista-only 方法的建议有何帮助?为什么程序仍然无法运行?

我的电脑在Windows/syatem32下确实有一个advapi.dll文件。

编辑: 当答案指出问题有多不清楚时,完全重写了问题。
最初我假设 Visual Studio 2010 不向后兼容 XP。
我被强行告知这是不正确的,但仍然无法让 VS 工作。

最佳答案

如果您希望您的代码在 XP 或更早的系统中运行,请使用 RegQueryValueEx .

无论如何,您应该先查看文档,然后再谷歌搜索。 Win32 API 有很好的文档记录,详细信息请参见 retrieving data from the registry以及每个功能页面中支持的操作系统信息,例如RegGetValue在 XP 64 位及更高版本中受支持。

关于c++ - Visual C++ 错误 : RegGetValueA could not be located,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5140374/

相关文章:

c++ - 在没有 Windows.h 的情况下制作 OpenGL 应用程序

C++ 内联函数抛出异常 : Run-Time Check Failure #0 - The value of ESP was not properly

windows - 在 Windows 上运行控制台应用程序时抑制命令窗口

XP 上的 WPF 内存泄漏(CMilChannel、HWND)

php - PHP 版本 5.2.11(在 Windows 上)的 APC dll 在哪里?

c++ - 尝试使用带参数的构造函数启动类

c++ - 在显示 child 之前,不会考虑父样式表填充

C++ 如何每 10 秒检查一次时间?

c++ - Qt - 检测 QWindow 何时关闭

c# - 我如何从组合框获取值(value),C#