1

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

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

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.

Community
  • 1
  • 1
SamGoody
  • 13,758
  • 9
  • 81
  • 91
  • 1
    There is certainly an `advapi32.dll` on 32-bit versions of Windows. Applications written in Visual Studio 2010 will most definitely run on Windows XP. What service pack do you have installed to your XP installation? – Cody Gray - on strike Feb 28 '11 at 09:56
  • VS2010 can certainly be used to write Windows 7 programs, and those will not run on XP. Use `/D_WIN32_WINNT=0x0501` to hide Vista-and-later functions from the compiler. – MSalters Feb 28 '11 at 10:19
  • WinXP SP2 or newer is fully supported by VS 2010, only make sure you do not use the API calls not offered by the WinXP. If you need to support WinXP without SP2, or even Win2k, check http://stackoverflow.com/questions/2484511/can-i-use-visual-studio-2010s-c-compiler-with-visual-studio-2008s-c-runtime/3502056#3502056 – Suma Mar 02 '11 at 13:20
  • I think the question needs significant cleanup, or at least title change. Applications are not exported. – Suma Mar 02 '11 at 13:24
  • @Suma I've rewrote the question. Is it clear now? – SamGoody Mar 02 '11 at 19:46

2 Answers2

3

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.

SamGoody
  • 13,758
  • 9
  • 81
  • 91
Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
  • I have tried with functions that are win2000+, including RegQueryValueEx (see snippet). The error is exactly the same for all. – SamGoody Mar 02 '11 at 11:31
2

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

wmeyer
  • 3,426
  • 1
  • 18
  • 26
  • I've added the following header: #define _WIN32_WINNT 0x0501. It now doesn't show the above err, instead showing the following: "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?" When I add the message box (commented out in the snippet above) it pops up a message that "Error Opening Registry Key". – SamGoody Mar 02 '11 at 11:40
  • I'm not sure what is going on there. - You could try to set _WIN32_WINNT 0x0501 in the project settings instead of in the header file, to be sure that it is globally visible. ( http://msdn.microsoft.com/en-us/library/hhzbb5c8.aspx ) Also, make sure to do a complete rebuild. – wmeyer Mar 02 '11 at 14:49