Table of contents
1.
Introduction 
2.
ATL
3.
System Registry
4.
Registry Support Classes
5.
CRegKey Class
5.1.
Example
5.2.
Syntax
6.
Members of CRegKey Class
6.1.
Constructors
6.2.
Operators
6.3.
Data Members
6.4.
Methods
7.
Frequently Asked Questions
7.1.
What is ATL?
7.2.
What is COM?
7.3.
What are the uses of ATL?
7.4.
What is the System Registry?
7.5.
What are Registry Support Classes?
8.
Conclusion
Last Updated: Mar 27, 2024
Medium

Registry Support Classes

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction 

Hello Ninja! Are you learning about the Active Template Library? That’s great! We have an article to magnify your knowledge on the topic. This article will explore the registry support classes of the Active Template Library. These classes have methods that allow you to manipulate the system registry. 

registry support classes

Let us begin by learning about ATL. 

ATL

ATL, or the Active Template Library, is a group of C++ classes built using templates. Microsoft created it to help you easily make Component Object Model (COM) objects. ATL comes with an object wizard that quickly sets up the basic structure of the objects. It requires the least amount of manual coding. 

ATL intends to make the process of developing efficient, flexible, and lightweight controls simpler. Its code can be used to create apartment-model objects, single-threaded objects, and free-threaded model objects.

Now that we are familiar with the ATL, let us move further to learn about the system registry.

System Registry

registry clipart

The system registry is a database of options, settings, information, and other values. This database keeps a record of the information about software and hardware installed on all versions of the Windows operating system. A new subkey is added to the system registry each time you add new software to your system. Settings like a program's location, version, and primary executable are all set in this subkey. The kernel, Security Accounts Manager, device drivers, services, and user interfaces can use the system registry. The registry is the storage of information about users, default system settings, etc.

Windows 3.1 introduced the Windows Registry for the first time. Its primary use was to store configuration data for COM-based components. Windows 95 and Windows NT(New Technology) expanded their use to organize and concentrate the data in the INI files (INItialization files). It included the settings for individual programs and was kept at several locations. Windows apps do not have to access the Windows Registry.

Let us now look at the registry support classes of ATL.

Registry Support Classes

These classes contain methods that allow us to manipulate the data and values in the system registry. The CRegKey class of the Active Template Library includes such methods.

Following are the key points about the registry support classes.

  • Registry support classes are a kind of object safety class.
     
  • These classes provide a collection of standard keys found in the registry on devices operating on Windows.
      
  • Applications use the registry for storing data. If the application gets closed, data is conserved.
     
  • This class allows you to work on reserving color choices, screen locations, or window sizes.
     

The registry class uses a few read-only keys. Some of these keys are listed below:

  • CurrentUser: Data about user preferences is stored using this key.
     
  • LocalMachine: It is used to set data configurations for local machines.
     
  • ClassesRoot: It is used to keep records of types (and classes) and the properties associated with them. 
     
  • Users: It is used for storing information about the default user settings.
     
  • PerformanceData: This key is used to keep a record of the performance data for software parts.
     
  • CurrentConfig: It is used to store hardware data that is not user-specific.
     
  • DynkData: This key is used to store the dynamic data.
     

Let us look at the CRegKey class that we mentioned earlier in detail.

CRegKey Class

It is a registry support class. CRegKey provides tools for adding and removing system registry keys and values. CRegKey offers a programming interface to the system registry for a specific machine.

Apps that run in the Windows runtime cannot access this class and its members. 

Example

You can use CRegKey::Open for opening a particular registry, and CRegKey::QueryValue or CRegKey::SetValue can be used for retrieving and editing data in a registry.

To use this class, you must include the “altbase.h” header file.

Its syntax is as follows:

Syntax

class CRegKey


Let us now look at some of the functions that are included in this class.

Members of CRegKey Class

The members included in the CRegKey class are as follows.

Constructors

Name Details
CRegKey::CRegKey Constructor
CRegKey::~CRegKey Destructor

Operators

Name Details
CRegKey::operator HKEY We use it to convert a CRegKey object to an HKey
CRegKey::operator = This is the assignment operator

Data Members

Name Details
CRegKey::m_hKey It includes the registry key handle associated to the CRegKey object.
CRegKey::m_pTM It is a CAtlTransactionManager object pointer

Methods

The CRegKey class has 28 methods that can be used to make changes to the system registry. All of these are public methods. 

A few important methods with their details and syntax are listed below:

Name Details Syntax with parameters
CRegKey::Create If the specified key does not already exist as a subkey of hKeyParent, you can call this function to create it.

LONG Create(

    HKEY hKeyParent,

    LPCTSTR lpszKeyName,

    LPTSTR lpszClass = REG_NONE,

    DWORD dwOptions = REG_OPTION_NON_VOLATILE,

    REGSAM samDesired = KEY_READ | KEY_WRITE,

    LPSECURITY_ATTRIBUTES lpSecAttr = NULL,

    LPDWORD lpdwDisposition = NULL) throw();

CRegKey::EnumKey You can call the CRegKey::EnumKey method with an index of zero to enumerate the subkeys. Repeat until the function returns ERROR_NO_MO RE_ITEMS, increasing the index value each time.

LONG EnumKey(

    DWORD iIndex,

    LPTSTR pszName,

    LPDWORD pnNameLength,

    FILETIME* pftLastWriteTime = NULL) throw();

CRegKey::Flush You can call this function to add the open registry key's properties to the registry. LONG Flush() throw();
CRegKey::GetKeySecurity To get a copy of the security descriptor securing the open registry key, use this function.

LONG GetKeySecurity(

    SECURITY_INFORMATION si,

    PSECURITY_DESCRIPTOR psd,

    LPDWORD pnBytes) throw();

CRegKey::Open To open the provided key, call this method, and set m_hKey to the key's handle.

LONG Open(

    HKEY hKeyParent,

    LPCTSTR lpszKeyName,

    REGSAM samDesired = KEY_READ | KEY_WRITE) throw();

CRegKey::operator HKEY You can use this function to convert a CRegKey object into a HKey. operator HKEY() const throw();
CRegKey::SetBinaryValue To change the registry key's binary value, you can call this method

LONG SetBinaryValue(

    LPCTSTR pszValueName,

    const void* pValue,

    ULONG nBytes) throw();

CRegKey::SetKeyValue To store data in a specific value field of a specified key, call this method.

LONG SetKeyValue(

    LPCTSTR lpszKeyName,

    LPCTSTR lpszValue,

    LPCTSTR lpszValueName = NULL) throw();

Let us now address some frequently asked questions.

Frequently Asked Questions

What is ATL?

The Active Template Library (ATL) is a collection of C++ classes based on templates. It intends to make the process of developing efficient, flexible, and lightweight controls simpler.

What is COM?

The Component Object Model (COM) specification approach from Microsoft establishes a binary standard for code exchange between two systems.

What are the uses of ATL?

ActiveX controls are frequently created using the Active Template Library (ATL), a wrapper library that makes COM development easier. MFC (Microsoft Foundation Class) or ATL applications may be produced with Visual Studio Community Edition or higher.

What is the System Registry?

The system registry is a database of information, options, settings, and other values for software and hardware installed on all editions of the Microsoft Windows operating system. 

What are Registry Support Classes?

These classes contain methods that allow us to manipulate values in the system registry. 

Conclusion

In this article, we learned about the registry support class of the Active Template Library. We also looked at the members that are included in the CRegKey class.

We hope this article helps you on your journey. You can refer to these articles related to ATL by Coding Ninjas.

Refer to our Guided Paths on Coding Ninjas Studio to upskill yourself in Competitive Programming, Data Structures and Algorithms, JavaScript, System Design, and much more! 

To test your competency in coding, check out our mock test series and participate in the hosted contests in Coding Ninjas Studio! 

If you have just begun your learning process and are looking for quality questions from tech giants like Google, Amazon, Microsoft, Uber, etc., Look at our interview experiences and interview bundle for placement preparations.

Happy Learning!

Live masterclass