16 HRESULT RegRead(HKEY hRootKey,
const wchar_t* subKey,
const wchar_t* valName,
wchar_t* valData,
size_t cchData)
19 LSTATUS iRetVal = RegCreateKeyExW(
24 REG_OPTION_NON_VOLATILE,
29 if (iRetVal != ERROR_SUCCESS)
30 return HRESULT_FROM_WIN32(iRetVal);
32 DWORD cbData = cchData *
sizeof(valData[0]);
34 iRetVal = RegQueryValueExW(hKey, valName,
nullptr, &dwType,
reinterpret_cast<LPBYTE
>(valData), &cbData);
36 if ((iRetVal == ERROR_SUCCESS) && (dwType != REG_SZ))
40 return HRESULT_FROM_WIN32(iRetVal);
43 HRESULT RegWrite(HKEY hRootKey,
const wchar_t* subKey,
const wchar_t* valName,
const wchar_t* valData, HKEY *hKeyResult =
nullptr)
46 LSTATUS iRetVal = RegCreateKeyExW(
51 REG_OPTION_NON_VOLATILE,
56 if (iRetVal != ERROR_SUCCESS)
57 return HRESULT_FROM_WIN32(iRetVal);
61 DWORD cbData =
static_cast<DWORD
>(wcslen(valData)*
sizeof(valData[0]));
62 iRetVal = RegSetValueExW(hKey, valName, 0, REG_SZ,
reinterpret_cast<const BYTE *
>(valData), cbData);
65 if (hKeyResult && (iRetVal == ERROR_SUCCESS))
70 return HRESULT_FROM_WIN32(iRetVal);
73 HRESULT RegDel(HKEY hRootKey,
const wchar_t* subKey)
75 LSTATUS iRetVal = RegDeleteKeyW(hRootKey, subKey);
76 return HRESULT_FROM_WIN32(iRetVal);
92 const wchar_t* sComponent, std::initializer_list<int> aVersions,
95 if (!wcslen(sComponent) || !wcslen(sProgram))
119 swprintf(sBufVal,
MAX_PATH, L
"%s %s Class", sProgram, sComponent);
121 HRESULT
hr = RegWrite(HKEY_CLASSES_ROOT, sBufKey, L
"", sBufVal, &hKeyCLSID);
127 HKeyGuard(HKEY aKey) : m_hKey(aKey) {}
128 ~HKeyGuard() { RegCloseKey(m_hKey); }
133 HKeyGuard hKeyCLSIDGuard(hKeyCLSID);
136 HKEY hKeyInprocServer32;
137 hr = RegWrite(hKeyCLSID, L
"InprocServer32", L
"",
Path, &hKeyInprocServer32);
141 HKeyGuard hKeyInProcServer32Guard(hKeyInprocServer32);
142 hr = RegWrite(hKeyInprocServer32, L
"", L
"ThreadingModel", L
"Apartment");
148 swprintf(sBufVal,
MAX_PATH, L
"%s.%s", sProgram, sComponent);
149 hr = RegWrite(hKeyCLSID, L
"ProgID", L
"", sBufVal);
154 hr = RegWrite(hKeyCLSID, L
"Programmable",
nullptr,
nullptr);
159 if (::StringFromGUID2(riidTypeLib, sBufVal,
nGUIDlen) == 0)
161 hr = RegWrite(hKeyCLSID, L
"TypeLib", L
"", sBufVal);
171 std::initializer_list<int> aVersions)
180 RegDel(HKEY_CLASSES_ROOT, sBuf);
182 RegDel(HKEY_CLASSES_ROOT, sBuf);
184 RegDel(HKEY_CLASSES_ROOT, sBuf);
186 RegDel(HKEY_CLASSES_ROOT, sBuf);
188 RegDel(HKEY_CLASSES_ROOT, sBuf);
208 swprintf(sBufVal,
MAX_PATH, L
"%s %s Class", sProgram, sComponent);
209 RegWrite(HKEY_CLASSES_ROOT, sBufKey, L
"", sBufVal);
210 swprintf(sBufKey,
MAX_PATH, L
"%s.%s.%d\\CLSID", sProgram, sComponent,
nVersion);
211 HRESULT
hr = RegWrite(HKEY_CLASSES_ROOT, sBufKey, L
"",
m_sCLSID);
212 if (SUCCEEDED(
hr) && bSetDefault)
214 swprintf(sBufKey,
MAX_PATH, L
"%s.%s", sProgram, sComponent);
215 swprintf(sBufVal,
MAX_PATH, L
"%s %s Class", sProgram, sComponent);
216 hr = RegWrite(HKEY_CLASSES_ROOT, sBufKey, L
"", sBufVal);
217 swprintf(sBufKey,
MAX_PATH, L
"%s.%s\\CurVer", sProgram, sComponent);
219 hr = RegWrite(HKEY_CLASSES_ROOT, sBufKey, L
"", sBufVal);
225 std::initializer_list<int> aVersions)
228 bool bDefaultRegistered =
false;
234 bDefaultRegistered =
true;
245 swprintf(sBuf,
MAX_PATH, L
"%s.%s.%d\\CLSID", sProgram, sComponent,
nVersion);
247 HRESULT
hr = RegRead(HKEY_CLASSES_ROOT, sBuf, L
"", sCurCLSID,
nGUIDlen);
256 RegDel(HKEY_CLASSES_ROOT, sBuf);
258 hr = RegDel(HKEY_CLASSES_ROOT, sBuf);
261 swprintf(sBufKey,
MAX_PATH, L
"%s.%s\\CurVer", sProgram, sComponent);
263 if (SUCCEEDED(RegRead(HKEY_CLASSES_ROOT, sBufKey, L
"", sBufVal,
MAX_PATH)) && (wcsncmp(sBufVal, sBuf,
MAX_PATH) == 0))
266 RegDel(HKEY_CLASSES_ROOT, sBufKey);
267 swprintf(sBuf,
MAX_PATH, L
"%s.%s", sProgram, sComponent);
268 HRESULT hr1 = RegDel(HKEY_CLASSES_ROOT, sBuf);
277 std::initializer_list<int> aVersions)
HRESULT RegisterProgIDs(const wchar_t *sProgram, const wchar_t *sComponent, std::initializer_list< int > aVersions)
static const size_t nGUIDlen
HRESULT m_ConstructionResult
HRESULT RegisterProgID(const wchar_t *sProgram, const wchar_t *sComponent, int nVersion, bool bSetDefault)
HRESULT UnRegisterProgID(const wchar_t *sProgram, const wchar_t *sComponent, int nVersion)
HRESULT RegisterObject(REFIID riidTypeLib, const wchar_t *sProgram, const wchar_t *sComponent, std::initializer_list< int > aVersions, const wchar_t *Path)
HRESULT UnRegisterObject(const wchar_t *sProgram, const wchar_t *sComponent, std::initializer_list< int > aVersions)
Registrar(REFIID riidCLSID)
HRESULT UnRegisterProgIDs(const wchar_t *sProgram, const wchar_t *sComponent, std::initializer_list< int > aVersions)
wchar_t m_sCLSID[nGUIDlen]