blob: 75dcdbb6ab467a3a45544ee473d931fd3a0d8dac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
//////////////////////////////////////////////////////////////////
// CComponentData
//
// Exposes the IPropertyBag interface for the components to store
// their data in.
//
// Also supports other host specific settings.
//
// Current implementation saves the data in the registry and only
// saves when requested to by host.
//
// Component can pass a Variant NULL to delete the specified
// property
//
// Only the following types are supported for now:
// VT_UI1
// VT_I2
// VT_I4
// VT_R4
// VT_R8
// VT_CY
// VT_BSTR
//////////////////////////////////////////////////////////////////
#if !defined(COMPONENTDATA_H__2AA70045_1988_11D2_B2D4_0020182B97FC__INCLUDED_)
#define COMPONENTDATA_H__2AA70045_1988_11D2_B2D4_0020182B97FC__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// ComponentData.h : header file
//
#define DATA_KEY _T("Data")
#include "../common/interfaces.h"
#include <map>
#include <utility>
using std::map;
using std::make_pair;
#include <mystring.h>
typedef map<string, CComVariant> string_variant_map;
/////////////////////////////////////////////////////////////////////////////
// CComponentData command target
class ATL_NO_VTABLE CComponentData :
public CComObjectRootEx<CComMultiThreadModel>,
public IPropertyBag
{
// Attributes
public:
CComponentData();
virtual ~CComponentData();
public:
// Host specific functions
// Add String support later when needed.
bool WriteInt(const string& sKey, int nValue);
int GetInt(const string& sKey, int nDefault);
bool Delete(const string& sKey);
// Can be used by Host and also called from the
// IPropertyBag Implementation below
HRESULT Write(const string& sValName, const VARIANT& varVal);
HRESULT Read(const string& sValName, VARIANT& varVal);
// Initializes Key
HRESULT Initialize(const string& sKey);
// Saves All Setting to Registry Key
// If sKey = NULL then saves to key given in Initialize
HRESULT Save(string sKey = _T(""));
// Returns an IUnknown to IPropertyBag
// IUnknown* GetIUnknown(bool bAddRef = false);
protected:
// Arrays of Settings to be written to Registry
// Supports Integers and Strings Only
string_variant_map m_mapValues;
// Registry Key
string m_sKey;
public:
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CComponentData)
COM_INTERFACE_ENTRY(IPropertyBag)
END_COM_MAP()
// IPropertyBag Interface
STDMETHOD(Read)(LPCOLESTR pszPropName, VARIANT* pVar, IErrorLog* pErrorLog);
STDMETHOD(Write)(LPCOLESTR pszPropName, VARIANT* pVar);
};
/////////////////////////////////////////////////////////////////////////////
#endif // !defined(COMPONENTDATA_H__2AA70045_1988_11D2_B2D4_0020182B97FC__INCLUDED_)
|