Solved

CRegKey class

Posted on 2001-07-19
7
1,221 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

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!

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

691 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