CHKLM v1.1 - Registry Access





4.00/5 (2 votes)
Mar 4, 2000

91053

947
A Freeware MFC class to write to HKEY_LOCAL_MACHINE.
Introduction
Welcome toCHKLM
v1.0, a simple MFC class to allow you to write values to the
HKEY_LOCAL_MACHINE
registry key. The functions provided with MFC only allow values
to be written to HKEY_CURRENT_USER
.
Full source code is provided for those interested. A VC 5 workspace file is included which builds a simple demo console application which calls the class methods.
Features |
History |
API |
Contacting the Author |
- Simple and clean C++ interface based upon the MFC functions.
- The classes are fully Unicode compliant and include Unicode built options in the workspace file.
- Full documentation is provided in the form of a HTML file.
History
V1.0 (27th June 1998)
- Initial public release.
V1.01 (14 July 1999)
- Now ships with a VC 5 workspace instead of VC 6.
- Tidied up the documentation file.
- Unicode Build configurations now actually compile and work <g>.
V1.1 (3 October 1999)
- Addition of
GetProfileStringArray()
andWriteProfileStringArray()
methods.
API
The API consists of the public methods of the CHKLM
class. They consist of:
CHKLM::SetRegistryKey
CHKLM::WriteProfileString
CHKLM::GetProfileString
CHKLM::WriteProfileInt
CHKLM::GetProfileInt
CHKLM::GetProfileBinary
CHKLM::WriteProfileBinary
CHKLM::GetProfileStringArray
CHKLM::WriteProfileStringArray
- CHKLM::SetRegistryKey
- void SetRegistryKey(LPCTSTR lpszRegistryKey);
Parameters:
- lpszRegistryKey -- Pointer to a string containing the name of the key.
- nIDRegistryKey -- ID/index of a key in the registry.
Remarks:
This function sets m_sRegistryKey, which is then used by the member functions ofCHKLM
. The registry key is usually the name of a company. It is stored in a key of the following form:HKEY_LOCAL_MACHINE\Software\<company name>\<application name>\<section name>\<value name>
. - CHKLM::GetProfileInt
- UINT GetProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nDefault);
Return Value:
The integer value of the string that follows the specified entry if the function is successful. The return value is the value of the nDefault parameter if the function does not find the entry. The return value is 0 if the value that corresponds to the specified entry is not an integer.When you retrieve a signed integer, you should cast the value into an
int
.Parameters:
- lpszSection -- Points to a null-terminated string that specifies the section containing the entry.
- lpszEntry -- Points to a null-terminated string that contains the entry whose value is to be retrieved.
- nDefault -- Specifies the default value to return if the framework cannot find the entry. This value can be an unsigned value in the range 0 through 65,535 or a signed value in the range -32,768 through 32,767.
Remarks:
Call this member function to retrieve the value of an integer from an entry within a specified section of the application's HKLM part of the registry.This member function is not case sensitive, so the strings in the lpszSection and lpszEntry parameters may differ in case.
- CHKLM::WriteProfileInt
- BOOL WriteProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nValue);
Return Value:
Nonzero if successful; otherwise 0.Parameters:
- lpszSection -- Points to a null-terminated string that specifies the section containing the entry. If the section does not exist, it is created. The name of the section is case independent; the string may be any combination of uppercase and lowercase letters.
- lpszEntry -- Points to a null-terminated string that contains the entry whose value is to be written. If the entry does not exist in the specified section, it is created.
- nValue -- Contains the value to be written.
Remarks:
Call this member function to write the specified value into the specified section of the application's HKLM part of the registry. - CHKLM::GetProfileString
- CString GetProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszDefault = NULL);
Return Value:
The return value is the string from the application's HKLM part of the registry or lpszDefault if the string cannot be found. The maximum string length supported by the framework is _MAX_PATH. If lpszDefault isNULL
, the return value is an empty string.Parameters:
- lpszSection -- Points to a null-terminated string that specifies the section containing the entry.
- lpszEntry -- Points to a null-terminated string that contains the entry whose string is to
be retrieved. This value must not be
NULL
. - lpszDefault -- Points to the default string value for the given entry if the entry cannot be found in the initialization file.
Remarks:
Call this member function to retrieve the string associated with an entry within the specified section in the application's HKLM part of the registry. - CHKLM::WriteProfileString
- BOOL WriteProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszValue);
Return Value:
Nonzero if successful; otherwise 0.Parameters:
- lpszSection -- Points to a null-terminated string that specifies the section containing the entry. If the section does not exist, it is created. The name of the section is case independent; the string may be any combination of uppercase and lowercase letters.
- lpszEntry -- Points to a null-terminated string that contains the entry into which the value is to be written. If the entry does not exist in the specified section, it is created.
- lpszValue -- Points to the string to be written. If this parameter is
NULL
, the entry specified by the lpszEntry parameter is deleted.
Remarks:
Call this member function to write the specified string into the specified section of the application's HKLM part of the registry. - CHKLM::GetProfileBinary
- BOOL GetProfileBinary(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPBYTE* ppData, UINT* pBytes);
Return Value:
Nonzero if successful; otherwise 0.Parameters:
- lpszSection -- Points to a null-terminated string that specifies the section containing the entry.
- lpszEntry -- Points to a null-terminated string that contains the entry whose binary entry
is to be retrieved. This value must not be
NULL
. - ppData -- Upon successful return this will contain the binary entry.
- pBytes -- Upon successful return this will contain the size of the binary entry.
Remarks:
Call this member function to retrieve a binary entry associated with an entry within the specified section in the application's HKLM part of the registry. The user is responsible for deleting the ppData memory. - CHKLM::WriteProfileBinary
- BOOL WriteProfileBinary(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPBYTE pData, UINT nBytes);
Return Value:
Nonzero if successful; otherwise 0.Parameters:
- lpszSection -- Points to a null-terminated string that specifies the section containing the entry. If the section does not exist, it is created. The name of the section is case independent; the string may be any combination of uppercase and lowercase letters.
- lpszEntry -- Points to a null-terminated string that contains the entry into which the value is to be written. If the entry does not exist in the specified section, it is created.
- pData -- Points to the binary data to be written.
- nBytes -- The size of the binary data pointed to by pData.
Remarks:
Call this member function to write the specified binary value into the specified section of the application's HKLM part of the registry. - CHKLM::GetProfileStringArray
- BOOL GetProfileStringArray(LPCTSTR lpszSection, LPCTSTR lpszEntry, CStringArray& array);
Return Value:
Nonzero if successful; otherwise 0.Parameters:
- lpszSection -- Points to a null-terminated string that specifies the section containing the entry.
- lpszEntry -- Points to a null-terminated string that contains the entry whose string array
is to be retrieved. This value must not be
NULL
. - array -- Upon successful return this will contain the CStringArray.
Remarks:
Call this member function to retrieve a string array associated with an entry within the specified section in the registry. The value is stored as aMULTI_SZ
string in the registry. - CHKLM::WriteProfileStringArray
- BOOL WriteProfileStringArray(LPCTSTR lpszSection, LPCTSTR lpszEntry, const CStringArray& array);
Return Value:
Nonzero if successful; otherwise FALSE.Parameters:
- lpszSection -- Points to a null-terminated string that specifies the section containing the entry. If the section does not exist, it is created. The name of the section is case independent; the string may be any combination of uppercase and lowercase letters.
- lpszEntry -- Points to a null-terminated string that contains the entry into which the value is to be written. If the entry does not exist in the specified section, it is created.
- array -- The CStringArray to be written.
Remarks:
Call this member function to write the specified string array into the registry. The value will be stored as aMULTI_SZ
string in the registry.
Contacting the Author
PJ Naughter
Email: pjn@indigo.ie
Web: http://www.naughter.com
3 October 1999