CSettingsStoreSP Class

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

The CSettingsStoreSP class is a helper class that you can use to create instances of the CSettingsStore Class.

class CSettingsStoreSP  

Public Constructors

NameDescription
CSettingsStoreSP::CSettingsStoreSPConstructs a CSettingsStoreSP object.

Public Methods

NameDescription
CSettingsStoreSP::CreateCreates an instance of a class that is derived from CSettingsStore.
CSettingsStoreSP::SetRuntimeClassSets the runtime class. The Create method uses the runtime class to determine what class of objects to create.

Data Members

NameDescription
m_dwUserDataCustom user data that is stored in the CSettingsStoreSP object. You supply this data in the constructor of the CSettingsStoreSP object.
m_pRegistryThe CSettingsStore-derived object that the Create method creates.

You can use the CSettingsStoreSP class to redirect all MFC registry operations to other locations, such as an XML file or a database. To do this, follow these steps:

  1. Create a class (such as CMyStore) and derive it from CSettingsStore.

  2. Use [DECLARE_DYNCREATE]--brokenlink--(../Topic/not%20found.md#declare_dyncreate) and [IMPLEMENT_DYNCREATE]--brokenlink--(../Topic/not%20found.md#implement_dyncreate) macros with your custom CSettingsStore class to enable dynamic creation.

  3. Override the virtual functions and implement the Read and Write functions in your custom class. Implement any other functionality to read and write data to your desired location.

  4. In your application, call CSettingsStoreSP::SetRuntimeClass and pass in a pointer to the CRuntimeClass Structure obtained from your class.

Whenever the framework would typically access the registry, it will now dynamically instantiate your custom class and use it to read or write data.

CSettingsStoreSP::SetRuntimeClass uses a global static variable. Therefore, only one custom store is available at a time.

Header: afxsettingsstore.h

Creates a new instance of an object that is derived from the CSettingsStore Class.

CSettingsStore& CSettingsStoreSP Create(
    BOOL bAdmin,  
    BOOL bReadOnly);

Parameters

[in] bAdmin
A Boolean parameter that determines whether a CSettingsStore object is created in administrator mode.

[in] bReadOnly
A Boolean parameter that determines whether a CSettingsStore object is created for read-only access.

Return Value

A reference to the newly created CSettingsStore object.

Remarks

You can use the method CSettingsStoreSP::SetRuntimeClass to determine what type of object CSettingsStoreSP::Create will create. By default, this method creates a CSettingsStore object.

If you create a CSettingsStore object in administrator mode, the default location for all registry access is HKEY_LOCAL_MACHINE. Otherwise, the default location for all registry access is HKEY_CURRENT_USER.

If bAdmin is TRUE, the application must have administration rights. Otherwise, it will fail when it tries to access the registry.

Example

The following example demonstrates how to use the Create method of the CSettingsStoreSP class.

	CSettingsStoreSP regSP;
	CSettingsStore& reg = regSP.Create(FALSE, TRUE);

Constructs a CSettingsStoreSP Class object.

CSettingsStoreSP::CSettingsStoreSP(DWORD dwUserData = 0);

Parameters

[in] dwUserData
User-defined data that the CSettingsStoreSP object stores.

Remarks

The CSettingsStoreSP object stores the data from dwUserData in the protected member variable m_dwUserData.

Sets the runtime class. The method CSettingsStoreSP::Create uses the runtime class to determine what type of object to create.

static BOOL __stdcall CSettingsStoreSP::SetRuntimeClass(CRuntimeClass* pRTI);

Parameters

[in] pRTI
A pointer to the runtime class information for a class derived from the CSettingsStore Class.

Return Value

TRUE if successful; FALSE if the class identified by pRTI is not derived from CSettingsStore.

Remarks

You can use the CSettingsStoreSP Class to derive classes from CSettingsStore. Use the method SetRuntimeClass if you want to create objects of a custom class that is derived from CSettingsStore.

Classes
Hierarchy Chart
CSettingsStore Class

Show: