CHKLM v1.0
Welcome to CHKLM 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 6 workspace file is included which builds a simple demo console application which calls the class methods.
Contents |
History |
API |
Contacting the Author |
V1.0 (27 July 1998)
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
void SetRegistryKey( LPCTSTR lpszRegistryKey );
void SetRegistryKey( UINT nIDRegistryKey );
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 of CHKLM. 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>.
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 applications 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.
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 into which the 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 applications HKLM part of the registry.
CString GetProfileString( LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszDefault = NULL );
Return Value
The return value is the string from the applications 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 is NULL, 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 applications HKLM part of the registry.
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 applications HKLM part of the registry.
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 applications HKLM part of the registry. The user is responsible for deleting the ppData memory
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 applications HKLM part of the registry.
PJ Naughter
Email: pjn@indigo..ie
Web: http://indigo.ie/~pjn
27th July
1998