7 #include "unipstoregen.h"
9 #include "wvlinkerhack.h"
15 static const int MAX = 1024;
17 using namespace PSTORECLib;
19 typedef HRESULT (WINAPI *PStoreCreateInstancePtr)(IPStore **, DWORD, DWORD, DWORD);
21 HRESULT UniPStoreGen::create_types(
WvString type_name,
WvString subtype_name)
25 _PST_TYPEINFO myTypeInfo;
26 myTypeInfo.cbSize = strlen(type_name.
cstr()) + 1;
27 myTypeInfo.szDisplayName =
new wchar_t[myTypeInfo.cbSize];
28 mbstowcs(myTypeInfo.szDisplayName, type_name.
cstr(), myTypeInfo.cbSize);
30 _PST_TYPEINFO mySubTypeInfo;
31 mySubTypeInfo.cbSize = strlen(subtype_name.
cstr()) + 1;
32 mySubTypeInfo.szDisplayName =
new wchar_t[mySubTypeInfo.cbSize];
33 mbstowcs(mySubTypeInfo.szDisplayName, subtype_name.
cstr(), mySubTypeInfo.cbSize);
35 _PST_ACCESSRULESET myRuleSet;
36 myRuleSet.cbSize =
sizeof(myRuleSet);
38 myRuleSet.rgRules = 0;
40 hRes = m_spPStore->CreateType( m_key, &m_type, &myTypeInfo, 0);
42 if ((hRes != PST_E_OK) && (hRes != PST_E_TYPE_EXISTS))
44 m_log(
"CreateSubtype() returned: %s\n", hRes);
48 hRes = m_spPStore->CreateSubtype( m_key, &m_type, &m_subtype, &mySubTypeInfo, &myRuleSet, 0);
49 if ((hRes != PST_E_OK) && (hRes != PST_E_TYPE_EXISTS))
51 m_log(
"CreateSubtype() returned: %s\n", hRes);
56 delete[] myTypeInfo.szDisplayName;
57 delete[] mySubTypeInfo.szDisplayName;
63 UniPStoreGen::UniPStoreGen(
WvString _moniker) :
64 m_log(_moniker), m_key(-1)
67 m_hPstoreDLL = LoadLibrary(
"pstorec.dll");
70 PStoreCreateInstancePtr pPStoreCreateInstance =
71 (PStoreCreateInstancePtr) GetProcAddress(m_hPstoreDLL,
"PStoreCreateInstance");
72 assert(pPStoreCreateInstance);
74 HRESULT hr = pPStoreCreateInstance(&m_spPStore, 0, 0, 0);
75 assert(SUCCEEDED(hr));
78 char *moniker = _moniker.
edit();
79 const char *seps =
":";
80 WvString _key = strtok(moniker, seps);
81 WvString type_name = strtok(NULL, seps);
82 WvString _type_guid = strtok(NULL, seps);
83 WvString subtype_name = strtok(NULL, seps);
84 WvString _subtype_guid = strtok(NULL, seps);
86 if (!!_key && strcmp(_key,
"PST_KEY_CURRENT_USER") == 0)
88 m_key = PST_KEY_CURRENT_USER;
90 else if (!!_key && strcmp(_key,
"PST_KEY_LOCAL_MACHINE") == 0)
92 m_key = PST_KEY_LOCAL_MACHINE;
95 if ((m_key >= 0) && !!type_name && !!_type_guid && !!subtype_name && !!_subtype_guid)
98 hr = UuidFromString((
unsigned char*)_type_guid.
edit(), &m_type);
99 hr = UuidFromString((
unsigned char*)_subtype_guid.
edit(), &m_subtype);
100 int result = create_types(type_name, subtype_name);
101 assert(SUCCEEDED( result ) || (result == PST_E_TYPE_EXISTS));
105 UniPStoreGen::~UniPStoreGen()
110 FreeLibrary(m_hPstoreDLL);
127 unsigned long cbdata;
131 mbstowcs(name, _name.
cstr(), MAX);
133 hRes = m_spPStore->ReadItem(
144 if (hRes == PST_E_OK)
147 wcstombs(value.
edit(), (
wchar_t*)data, MAX);
156 WCHAR name[MAX], data[MAX];
158 mbstowcs(data, value.cstr(), MAX);
160 DWORD cbdata = DWORD((wcslen(data) + 1) *
sizeof(WCHAR));
162 HRESULT hRes = m_spPStore->WriteItem(
168 (
unsigned char *)data,
174 if (hRes == PST_E_OK)
207 #pragma warning(disable : 4073)
208 #pragma init_seg(lib)