Solved

CRegKey class

Posted on 2001-07-19
7
1,181 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 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

929 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now