Solved

CRegKey class

Posted on 2001-07-19
7
1,163 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 37

Author Comment

by:meverest
Comment Utility
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
Comment Utility
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
Comment Utility
> 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
Comment Utility
thanks - that works for me.

cheers.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

743 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

17 Experts available now in Live!

Get 1:1 Help Now