Solved

CRegKey class

Posted on 2001-07-19
7
1,214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 100 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
Independent Software Vendors: 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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  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 concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

732 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