开发者

Visual C++ err: RegGetValueA could not be located

Attempting to write a simple registry-check script in Visual Studio 2010, running on XP SP3 x86.

No errs are thrown on build, but on debug the program exits with the following error:

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

Here is the entire code of the program.

// #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;
}

The comments in the code above where added based on an answer by wmeyer.

When uncommented, the code does not exit with that error, but throws a different error:

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?

If I continue, the MessageBox pops up with "Error Opening Registry Key".

I have tried replacing the RegQueryValueEx function with the following three other methods, one at a time.

I KNOW THAT TWO OF THEM ARE VISTA ONLY, but I wanted to see if the error would be different.

It wasn't.

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

// Vis开发者_如何学Pythonta+ 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);

I've already lost hours trying to work out several other errors, such as "cannot convert parameter 1 from 'char' to 'LPCWSTR'" - which was solved by changing the configuration and "Cannot find or open the PDB file", solved by changing the configuration.

So again, the question to be clear:

  1. How do I deal with the error?
  2. How did wmeyer's suggestion of adding a header to filter out Vista-only methods help, when the prog has no Vista methods to begin with? And why does the program still not work?

My computer definitely does have a advapi.dll file in Windows/syatem32.

EDIT: Completely rewrote the question when the answers pointed out how unclear it was.

Originally I had assumed that Visual Studio 2010 is not backwards compatible with XP.

I've been forcefully told that is incorrect, but still can't get VS to work.


If you want your code to run in XP or an earlier system use RegQueryValueEx.

In any case, you should check the documentation first and then search Google. The Win32 API is very well documented, with details on retrieving data from the registry and supported OS information in every function's page, e.g. RegGetValue is supported in XP 64bit and later.


You should set _WIN32_WINNT to the Windows version you are targeting.

See here: http://msdn.microsoft.com/en-us/library/aa383745(v=vs.85).aspx#setting_winver_or__win32_winnt

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜