Using the Registry

Split from Tutorial thread

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »

53 Replies - 4876 Views - Last Post: 05 July 2012 - 02:18 PM Rate Topic: -----

#1 Jimbo7136  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 01-July 12

Using the Registry

Posted 01 July 2012 - 09:10 PM

MOD EDIT: Snippet refers to this tutorial.

Hi, I'm trying to run the first code snippet above, I changed it to an actual registry key instead of "mykey"

HKEY key;
	if (RegOpenKey(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion"), &key) != ERROR_SUCCESS)
	{
	   cout << "Unable to open registry key”;
	}


I'd love to use these examples to write some code for reading and editing the registry, but I can't seem to get them working under visual studio 2010. This is the output I'm getting when I try to build:

1>------ Build started: Project: regops, Configuration: Debug Win32 ------
1>Build started 7/1/2012 10:06:16 PM.
1>InitializeBuildStatus:
1> Touching "Debug\regops.unsuccessfulbuild".
1>ClCompile:
1> regops.cpp
1>c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp(1): error C2146: syntax error : missing ';' before identifier 'key'
1>c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp(1): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp(1): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp(2): error C2059: syntax error : 'if'
1>c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp(3): error C2143: syntax error : missing ';' before '{'
1>c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp(3): error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp(4): error C2001: newline in constant
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.57
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This post has been edited by JackOfAllTrades: 02 July 2012 - 07:20 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Using the Registry

#2 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5233
  • View blog
  • Posts: 27,024
  • Joined: 10-May 07

Re: Using the Registry

Posted 01 July 2012 - 09:12 PM

Look at your quotes in cout. You've copy & pasted into a ritch text editor like word pad & they are not the same as standard quotes.

** Edit **

Actually it looks like this was in the tutorial. I fixed the quotes. Please try his code again.
Was This Post Helpful? 1
  • +
  • -

#3 Jimbo7136  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 01-July 12

Re: Using the Registry

Posted 01 July 2012 - 09:25 PM

Thanks, I hadn't noticed that.

This is what I tried after fixing the quotes:

int main()
{
HKEY key;
	    if (RegOpenKey(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion"), &key) != ERROR_SUCCESS)
	    {
	       cout << "Unable to open registry key”;
	    }
}


This is the output I got from Visual Studio 2010:

1>------ Rebuild All started: Project: regops, Configuration: Debug Win32 ------
1>Build started 7/1/2012 10:23:17 PM.
1>_PrepareForClean:
1> Deleting file "Debug\regops.lastbuildstate".
1>InitializeBuildStatus:
1> Touching "Debug\regops.unsuccessfulbuild".
1>ClCompile:
1> regops.cpp
1>c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp(3): error C2065: 'HKEY' : undeclared identifier
1>c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp(3): error C2146: syntax error : missing ';' before identifier 'key'
1>c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp(3): error C2065: 'key' : undeclared identifier
1>c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp(4): error C2065: 'HKEY_LOCAL_MACHINE' : undeclared identifier
1>c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp(4): error C2065: 'key' : undeclared identifier
1>c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp(4): error C2065: 'ERROR_SUCCESS' : undeclared identifier
1>c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp(4): error C3861: 'RegOpenKey': identifier not found
1>c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp(4): error C3861: 'TEXT': identifier not found
1>c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp(6): error C2065: 'cout' : undeclared identifier
1>c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp(6): error C2001: newline in constant
1>c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp(7): error C2143: syntax error : missing ';' before '}'
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.66
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========


And yes, I forgot to add a main() in my first post. How embarassing!
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5233
  • View blog
  • Posts: 27,024
  • Joined: 10-May 07

Re: Using the Registry

Posted 01 July 2012 - 11:15 PM

You can't just throw that little bit of code into int main & expect it to work.
Was This Post Helpful? 1
  • +
  • -

#5 Jimbo7136  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 01-July 12

Re: Using the Registry

Posted 02 July 2012 - 04:31 AM

View Postno2pencil, on 02 July 2012 - 12:15 AM, said:

You can't just throw that little bit of code into int main & expect it to work.


Okay. What's missing?
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6052
  • View blog
  • Posts: 23,487
  • Joined: 23-August 08

Re: Using the Registry

Posted 02 July 2012 - 07:19 AM

Split from tutorial thread.

Post the entire code with which you're having problems.
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3535
  • View blog
  • Posts: 10,943
  • Joined: 05-May 12

Re: Using the Registry

Posted 02 July 2012 - 07:25 AM

Are you even including "windows.h"?
Was This Post Helpful? 0
  • +
  • -

#8 Jimbo7136  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 01-July 12

Re: Using the Registry

Posted 05 July 2012 - 07:07 AM

View PostSkydiver, on 02 July 2012 - 08:25 AM, said:

Are you even including "windows.h"?


No.

It's been a LONG time since I did anything in c/c++. My mistake.
Was This Post Helpful? 0
  • +
  • -

#9 Jimbo7136  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 01-July 12

Re: Using the Registry

Posted 05 July 2012 - 10:17 AM

View PostJackOfAllTrades, on 02 July 2012 - 08:19 AM, said:

Split from tutorial thread.

Post the entire code with which you're having problems.


Okay, here it is:


int main()
{
HKEY key;
	    if (RegOpenKey(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion"), &key) != ERROR_SUCCESS)
	    {
	       cout << "Unable to open registry key”;
	    }
}



Then I was asked if I was including windows.h, I wasn't but adding that didn't fix it.

I just want to get this first little bit of code working, which is to open a registry key, then I'll add the next snippets to manipulate the registry key. This is all the code I have so far.

I'm not sure what headers I should include or if I need to define a namespace.
Was This Post Helpful? 0
  • +
  • -

#10 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • Joined: 08-January 12

Re: Using the Registry

Posted 05 July 2012 - 10:30 AM

On line 6, the second quote is not the standard quote - it is some other kind of quote. Fix it, include windows.h and you are good to go :)
Was This Post Helpful? 0
  • +
  • -

#11 Jimbo7136  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 01-July 12

Re: Using the Registry

Posted 05 July 2012 - 10:33 AM

View Postaresh, on 05 July 2012 - 11:30 AM, said:

On line 6, the second quote is not the standard quote - it is some other kind of quote. Fix it, include windows.h and you are good to go :)


I thought I fixed that, oops.

Okay, much better, but it still says cout is undefined.
Was This Post Helpful? 0
  • +
  • -

#12 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • Joined: 08-January 12

Re: Using the Registry

Posted 05 July 2012 - 10:35 AM

Do you have no experience using C++ ?? Even a beginner knows you write
std::cout
OR
using namespace std;


If that does not solve it, please post your complete code, including headers and all. Also, post the errors you get.

This post has been edited by aresh: 05 July 2012 - 10:36 AM

Was This Post Helpful? 0
  • +
  • -

#13 Jimbo7136  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 01-July 12

Re: Using the Registry

Posted 05 July 2012 - 10:37 AM

View Postaresh, on 05 July 2012 - 11:35 AM, said:

Do you have no experience using C++ ?? Even a beginner knows you write
std::cout
OR
using namespace std;


If that does not solve it, please post your complete code, including headers and all. Also, post the errors you get.


No, I had a little experience with C years ago, and some experience with Java more recently, the namespace is completely new to me.
Was This Post Helpful? 0
  • +
  • -

#14 Jimbo7136  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 01-July 12

Re: Using the Registry

Posted 05 July 2012 - 10:42 AM

View Postaresh, on 05 July 2012 - 11:35 AM, said:

Do you have no experience using C++ ?? Even a beginner knows you write
std::cout
OR
using namespace std;


If that does not solve it, please post your complete code, including headers and all. Also, post the errors you get.


Sorry for the double post.

Here is my updated code:

#include <windows.h>

using namespace std;

int main()
{
HKEY key;
	    if (RegOpenKey(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion"), &key) != ERROR_SUCCESS)
	    {
	       cout << "Unable to open registry key";
	    }
}




And the errors from Visual Studio 2010:

Error 1 error C2065: 'cout' : undeclared identifier c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp 10

2 IntelliSense: name must be a namespace name c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp 3

3 IntelliSense: identifier "cout" is undefined c:\users\marcus\documents\visual studio 2010\projects\regops\regops\regops.cpp 10
Was This Post Helpful? 0
  • +
  • -

#15 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • Joined: 08-January 12

Re: Using the Registry

Posted 05 July 2012 - 10:44 AM

This will help you understand about namespaces.. And as far as the error is concerned, where have you included iostream ?? Add that line. cin, cout and all are defined in iostream, so it is should be a part of nearly every one of your programs..
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »