?
Solved

CRegKey class

Posted on 2001-07-19
7
Medium Priority
?
1,264 Views
Last Modified: 2012-08-13
Hi Folks,

trying to work out how to use CRegKey - i don;t understand the process for the Open() function...

here's what i can figure out so far:

HKEY m_hKey; // create a HKEY
CRegKey key; // create a CRegKey
char *szValue; // pointer to receive the
DWORD *pdwCount; // to get the buffer length

CString keyVal = "defaultvalue";

if( key.Open(m_hKey, "HKEY_LOCAL_MACHINE\\Software\\GSAT\\QuotaMan", KEY_READ) == ERROR_SUCCESS) // open the key
{
  if(key.QueryValue( szValue, "keyVal", pdwCount )) // see if there is a value
  {
    keyVal=szValue; // if there is, set the variable
    Log( "Got keyVal = " + szValue ); // just a function to write output to a text file
  }
  key.Close();
}

this all compiles ok, but i get a link error error LNK2001 (unresolved external symboL) on all three member functions of CRegKey - i assume that i have the arguments mucked up..?

thanks for any suggestion,

cheers, Mike.
0
Comment
Question by:meverest
7 Comments
 
LVL 37

Author Comment

by:meverest
ID: 6301228
incidentally, this is the exact linker error:

QuotaMan.obj : error LNK2001: unresolved external symbol "public: long __thiscall ATL::CRegKey::Close(void)" (?Close@CRegKey@ATL@@QAEJXZ)

(my project, obviously, is called 'QuotaMan' ;-)

regards.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6302033
Do you have '_ATL_DLL' defined in your project settings? If not, either doing so will help (#define _ATL_DLL), or use

#pragma comment(lib, "atl.lib")

This should remedy your problem...
0
 
LVL 9

Accepted Solution

by:
ShaunWilde earned 400 total points
ID: 6302042
there are all inline so you shouldn't have linker problems

I'd write your code like this

char szValue[1024]; // pointer to receive the
DWORD dwCount; // to get the buffer length

dwCount=1024;

if( key.Open(HKEY_LOCAL_MACHINE, "Software\\GSAT\\QuotaMan", KEY_READ) == ERROR_SUCCESS) //
open the key
{
 if(key.QueryValue( szValue, "keyVal", &dwCount )) // see if there is a value
 {
   keyVal=szValue; // if there is, set the variable
   Log( "Got keyVal = " + szValue ); // just a function to write output to a text file
 }
 key.Close();
}

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Author Comment

by:meverest
ID: 6302053
thanks guys,

i've actually gotten around it by using standard C runtime library functions.

i will go back later and fix it up when i get closer to completion, and come back to this then.

(feel free to add a reminder if i seem to have forgotten!)

thanks for your patience.

regards.
0
 
LVL 1

Expert Comment

by:xutao
ID: 6302054
Yes, you've mucked up the arguments.
You should use CRegKey like this:
CRegKey RegKey;
RegKey.Open(HKEY_LOCAL_MACHINE, TEXT("Software\\GSAT\\QuotaMan"), KEY_READ);
That's all. Good Luck.
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6302062
> That's all

it isn't he also didn't supply a valid buffer to hold his data
0
 
LVL 37

Author Comment

by:meverest
ID: 6329271
thanks - that works for me.

cheers.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question