Retrieve registry key value compile error

Hi,

I am trying to retrieve a specific key(i.e. I know the key name) from registry. Firstly I want to see if I can open the key successfully, but I am stuck at compiling.

----1st attempt----
1
2
3
4
5
6
#include<winreg.h>
HKEY key;
if (RegOpenKey(HKEY_LOCAL_MACHINE, TEXT("Software\\foo\\"), &key) != ERROR_SUCCESS)
  textbox->Text = L"FAIL";
else
  textbox->Text = L"YEAH";


This piece of code gives error:
1
2
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winnt.h(19787): error C3861: '__readfsdword': identifier not found
1>d:\foo\foo.h(1283): error C2065: 'ERROR_SUCCESS' : undeclared identifier


----2nd attempt----
So I put another header file in.
1
2
3
#include<winreg.h>
#include<winerror.h>
//other code unchanged 


The C2065 error was gone, but the other error was still there.

----3rd attempt----
Then I did some googling about this error, some people said including windows.h would help, so I tried:
1
2
3
4
#include<Windows.h>
#include<winreg.h>
#include<winerror.h>
//other code unchanged 


And got even more errors.
1
2
3
4
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winnt.h(19787): error C3861: '__readfsdword': identifier not found
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winbase.h(8819): error C3861: '_InterlockedIncrement': identifier not found
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winbase.h(8828): error C3861: '_InterlockedIncrement': identifier not found
//and more of them... 


----4th attempt----
Then I googled with key word "__readfsdword", seems it only works under x86 architecture. So I put it in:
1
2
3
4
5
#define _X86_
#include<Windows.h>
#include<winreg.h>
#include<winerror.h>
//other code unchanged 


So...
1
2
3
4
5
6
7
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\kernelspecs.h(58): warning C4005: 'HIGH_LEVEL' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\shared\kernelspecs.h(55) : see previous definition of 'HIGH_LEVEL'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winnt.h(5875): warning C4005: 'CONTEXT_CONTROL' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winnt.h(3483) : see previous definition of 'CONTEXT_CONTROL'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winnt.h(5876): warning C4005: 'CONTEXT_INTEGER' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winnt.h(3484) : see previous definition of 'CONTEXT_INTEGER'
//and some more of them... 


And now I am completely stuck, got no idea how to continue. Could anyone help? I am running 64bit Windows 7 and Visual Studio 2013.

And by the way, I have _AMD64_ defined in my compiler command line during those attempts.
Last edited on
Don't play around with that Macro ( _X86_ ). It was a solid attempt on your part and I applaud your trouble shooting skills but you're going in the wrong direction with this.

The #include Macro is functionally a copy paste operation. So in order for everything to be visible where it should be you need to have all of your #include statements at the "highest" point possible which would be the first few lines of your earliest custom header file.
The #include Macro is functionally a copy paste operation. So in order for everything to be visible where it should be you need to have all of your #include statements at the "highest" point possible which would be the first few lines of your earliest custom header file.

Basically I am trying to make a small program with GUI, that reads some game save files to analyse them. The first step is to get the saved game directory from registry, and now I am still designing the GUI. So at this moment I have only #include<Windows.h> . winreg.h and winerror.h are redundant after including Windows.h.

What do you suggest me to do now?
OK I got this now...

Simply get rid of all those #defines, keep only #include<Windwos.h> and add advapi32.lib to dependency. All good now.

Actually I tried the code in a console project and it worked...I am new to GUI programming, it is so hard :(
Topic archived. No new replies allowed.