ole32: Convert the remaining RegCreateKey and RegOpenKey calls to the wrappers.

This commit is contained in:
Hans Leidekker 2012-11-26 15:20:48 +01:00 committed by Alexandre Julliard
parent a82c49028d
commit 7895eae15b
5 changed files with 59 additions and 51 deletions

View File

@ -31,6 +31,8 @@
#include "ole2.h"
#include "comcat.h"
#include "compobj_private.h"
#include "wine/unicode.h"
#include "wine/debug.h"
@ -93,17 +95,14 @@ static HRESULT COMCAT_RegisterClassCategories(
if (FAILED(res)) return res;
/* Create (or open) the CLSID key. */
res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
res = create_classes_key(HKEY_CLASSES_ROOT, clsid_keyname, KEY_READ|KEY_WRITE, &clsid_key);
if (res != ERROR_SUCCESS) return E_FAIL;
/* Create (or open) the class key. */
res = RegCreateKeyExW(clsid_key, keyname, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &class_key, NULL);
res = create_classes_key(clsid_key, keyname, KEY_READ|KEY_WRITE, &class_key);
if (res == ERROR_SUCCESS) {
/* Create (or open) the category type key. */
res = RegCreateKeyExW(class_key, type, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &type_key, NULL);
res = create_classes_key(class_key, type, KEY_READ|KEY_WRITE, &type_key);
if (res == ERROR_SUCCESS) {
for (; cCategories; --cCategories, ++rgcatid) {
HKEY key;
@ -113,8 +112,7 @@ static HRESULT COMCAT_RegisterClassCategories(
if (FAILED(res)) continue;
/* Do the register. */
res = RegCreateKeyExW(type_key, keyname, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &key, NULL);
res = create_classes_key(type_key, keyname, KEY_READ|KEY_WRITE, &key);
if (res == ERROR_SUCCESS) RegCloseKey(key);
}
res = S_OK;
@ -148,8 +146,7 @@ static HRESULT COMCAT_UnRegisterClassCategories(
lstrcpyW(keyname + 45, type);
/* Open the class category type key. */
res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0,
KEY_READ | KEY_WRITE, &type_key);
res = open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ|KEY_WRITE, &type_key);
if (res != ERROR_SUCCESS) return E_FAIL;
for (; cCategories; --cCategories, ++rgcatid) {
@ -237,11 +234,11 @@ static HRESULT COMCAT_IsClassOfCategories(
/* Check that every given category is implemented by class. */
if (*categories->impl_strings) {
res = RegOpenKeyExW(key, impl_keyname, 0, KEY_READ, &subkey);
res = open_classes_key(key, impl_keyname, KEY_READ, &subkey);
if (res != ERROR_SUCCESS) return S_FALSE;
for (string = categories->impl_strings; *string; string += 39) {
HKEY catkey;
res = RegOpenKeyExW(subkey, string, 0, 0, &catkey);
res = open_classes_key(subkey, string, 0, &catkey);
if (res != ERROR_SUCCESS) {
RegCloseKey(subkey);
return S_FALSE;
@ -252,7 +249,7 @@ static HRESULT COMCAT_IsClassOfCategories(
}
/* Check that all categories required by class are given. */
res = RegOpenKeyExW(key, req_keyname, 0, KEY_READ, &subkey);
res = open_classes_key(key, req_keyname, KEY_READ, &subkey);
if (res == ERROR_SUCCESS) {
for (index = 0; ; ++index) {
WCHAR keyname[39];
@ -335,8 +332,7 @@ static HRESULT WINAPI COMCAT_ICatRegister_RegisterCategories(
return E_POINTER;
/* Create (or open) the component categories key. */
res = RegCreateKeyExW(HKEY_CLASSES_ROOT, comcat_keyname, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &comcat_key, NULL);
res = create_classes_key(HKEY_CLASSES_ROOT, comcat_keyname, KEY_READ|KEY_WRITE, &comcat_key);
if (res != ERROR_SUCCESS) return E_FAIL;
for (; cCategories; --cCategories, ++rgci) {
@ -347,8 +343,7 @@ static HRESULT WINAPI COMCAT_ICatRegister_RegisterCategories(
/* Create (or open) the key for this category. */
if (!StringFromGUID2(&rgci->catid, keyname, 39)) continue;
res = RegCreateKeyExW(comcat_key, keyname, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &cat_key, NULL);
res = create_classes_key(comcat_key, keyname, KEY_READ|KEY_WRITE, &cat_key);
if (res != ERROR_SUCCESS) continue;
/* Set the value for this locale's description. */
@ -381,8 +376,7 @@ static HRESULT WINAPI COMCAT_ICatRegister_UnRegisterCategories(
return E_POINTER;
/* Open the component categories key. */
res = RegOpenKeyExW(HKEY_CLASSES_ROOT, comcat_keyname, 0,
KEY_READ | KEY_WRITE, &comcat_key);
res = open_classes_key(HKEY_CLASSES_ROOT, comcat_keyname, KEY_READ|KEY_WRITE, &comcat_key);
if (res != ERROR_SUCCESS) return E_FAIL;
for (; cCategories; --cCategories, ++rgcatid) {
@ -523,7 +517,7 @@ static HRESULT WINAPI COMCAT_ICatInformation_GetCategoryDesc(
/* Open the key for this category. */
if (!StringFromGUID2(rcatid, keyname + 21, 39)) return E_FAIL;
res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &key);
res = open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &key);
if (res != ERROR_SUCCESS) return CAT_E_CATIDNOEXIST;
/* Allocate a sensible amount of memory for the description. */
@ -616,7 +610,7 @@ static HRESULT WINAPI COMCAT_ICatInformation_IsClassOfCategories(
cRequired, rgcatidReq);
if (categories == NULL) return E_OUTOFMEMORY;
res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &key);
res = open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &key);
if (res == ERROR_SUCCESS) {
res = COMCAT_IsClassOfCategories(key, categories);
RegCloseKey(key);
@ -891,7 +885,7 @@ static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Next(
hr = CLSIDFromString(catid, &rgelt->catid);
if (FAILED(hr)) continue;
res = RegOpenKeyExW(This->key, catid, 0, KEY_READ, &subkey);
res = open_classes_key(This->key, catid, KEY_READ, &subkey);
if (res != ERROR_SUCCESS) continue;
hr = COMCAT_GetCategoryDesc(subkey, This->lcid,
@ -952,7 +946,7 @@ static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Clone(
new_this->ref = 1;
new_this->lcid = This->lcid;
/* FIXME: could we more efficiently use DuplicateHandle? */
RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &new_this->key);
open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &new_this->key);
new_this->next_index = This->next_index;
*ppenum = &new_this->IEnumCATEGORYINFO_iface;
@ -982,7 +976,7 @@ static IEnumCATEGORYINFO *COMCAT_IEnumCATEGORYINFO_Construct(LCID lcid)
This->IEnumCATEGORYINFO_iface.lpVtbl = &COMCAT_IEnumCATEGORYINFO_Vtbl;
This->lcid = lcid;
RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &This->key);
open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &This->key);
}
return &This->IEnumCATEGORYINFO_iface;
}
@ -1075,7 +1069,7 @@ static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Next(
hr = CLSIDFromString(clsid, rgelt);
if (FAILED(hr)) continue;
res = RegOpenKeyExW(This->key, clsid, 0, KEY_READ, &subkey);
res = open_classes_key(This->key, clsid, KEY_READ, &subkey);
if (res != ERROR_SUCCESS) continue;
hr = COMCAT_IsClassOfCategories(subkey, This->categories);
@ -1140,7 +1134,7 @@ static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Clone(
}
memcpy(new_this->categories, This->categories, size);
/* FIXME: could we more efficiently use DuplicateHandle? */
RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &new_this->key);
open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &new_this->key);
new_this->next_index = This->next_index;
*ppenum = (LPENUMGUID)new_this;
@ -1168,7 +1162,7 @@ static LPENUMGUID COMCAT_CLSID_IEnumGUID_Construct(struct class_categories *cate
This->lpVtbl = &COMCAT_CLSID_IEnumGUID_Vtbl;
This->categories = categories;
RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &This->key);
open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &This->key);
}
return (LPENUMGUID)This;
}
@ -1308,7 +1302,7 @@ static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Clone(
new_this->ref = 1;
lstrcpyW(new_this->keyname, This->keyname);
/* FIXME: could we more efficiently use DuplicateHandle? */
RegOpenKeyExW(HKEY_CLASSES_ROOT, new_this->keyname, 0, KEY_READ, &new_this->key);
open_classes_key(HKEY_CLASSES_ROOT, new_this->keyname, KEY_READ, &new_this->key);
new_this->next_index = This->next_index;
*ppenum = (LPENUMGUID)new_this;
@ -1339,7 +1333,7 @@ static LPENUMGUID COMCAT_CATID_IEnumGUID_Construct(
memcpy(This->keyname, prefix, sizeof(prefix));
StringFromGUID2(rclsid, This->keyname + 6, 39);
lstrcpyW(This->keyname + 44, postfix);
RegOpenKeyExW(HKEY_CLASSES_ROOT, This->keyname, 0, KEY_READ, &This->key);
open_classes_key(HKEY_CLASSES_ROOT, This->keyname, KEY_READ, &This->key);
}
return (LPENUMGUID)This;
}

View File

@ -1931,7 +1931,7 @@ HRESULT COM_OpenKeyForCLSID(REFCLSID clsid, LPCWSTR keyname, REGSAM access, HKEY
strcpyW(path, wszCLSIDSlash);
StringFromGUID2(clsid, path + strlenW(wszCLSIDSlash), CHARS_IN_GUID);
res = RegOpenKeyExW(HKEY_CLASSES_ROOT, path, 0, keyname ? KEY_READ : access, &key);
res = open_classes_key(HKEY_CLASSES_ROOT, path, keyname ? KEY_READ : access, &key);
if (res == ERROR_FILE_NOT_FOUND)
return REGDB_E_CLASSNOTREG;
else if (res != ERROR_SUCCESS)
@ -1943,7 +1943,7 @@ HRESULT COM_OpenKeyForCLSID(REFCLSID clsid, LPCWSTR keyname, REGSAM access, HKEY
return S_OK;
}
res = RegOpenKeyExW(key, keyname, 0, access, subkey);
res = open_classes_key(key, keyname, access, subkey);
RegCloseKey(key);
if (res == ERROR_FILE_NOT_FOUND)
return REGDB_E_KEYMISSING;
@ -1981,7 +1981,7 @@ HRESULT COM_OpenKeyForAppIdFromCLSID(REFCLSID clsid, REGSAM access, HKEY *subkey
strcpyW(keyname, szAppIdKey);
strcatW(keyname, buf);
res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, access, subkey);
res = open_classes_key(HKEY_CLASSES_ROOT, keyname, access, subkey);
if (res == ERROR_FILE_NOT_FOUND)
return REGDB_E_KEYMISSING;
else if (res != ERROR_SUCCESS)
@ -2074,7 +2074,7 @@ HRESULT WINAPI CLSIDFromProgID(LPCOLESTR progid, LPCLSID clsid)
buf = HeapAlloc( GetProcessHeap(),0,(strlenW(progid)+8) * sizeof(WCHAR) );
strcpyW( buf, progid );
strcatW( buf, clsidW );
if (RegOpenKeyW(HKEY_CLASSES_ROOT,buf,&xhkey))
if (open_classes_key(HKEY_CLASSES_ROOT, buf, MAXIMUM_ALLOWED, &xhkey))
{
HeapFree(GetProcessHeap(),0,buf);
WARN("couldn't open key for ProgID %s\n", debugstr_w(progid));

View File

@ -703,10 +703,7 @@ HRESULT WINAPI OleRegGetUserType(
/*
* Open the class id Key
*/
hres = RegOpenKeyW(HKEY_CLASSES_ROOT,
keyName,
&clsidKey);
hres = open_classes_key(HKEY_CLASSES_ROOT, keyName, MAXIMUM_ALLOWED, &clsidKey);
if (hres != ERROR_SUCCESS)
return REGDB_E_CLASSNOTREG;
@ -902,21 +899,14 @@ HRESULT WINAPI OleRegGetMiscStatus(
/*
* Open the class id Key
*/
result = RegOpenKeyW(HKEY_CLASSES_ROOT,
keyName,
&clsidKey);
result = open_classes_key(HKEY_CLASSES_ROOT, keyName, MAXIMUM_ALLOWED, &clsidKey);
if (result != ERROR_SUCCESS)
return REGDB_E_CLASSNOTREG;
/*
* Get the MiscStatus
*/
result = RegOpenKeyW(clsidKey,
miscstatusW,
&miscStatusKey);
result = open_classes_key(clsidKey, miscstatusW, MAXIMUM_ALLOWED, &miscStatusKey);
if (result != ERROR_SUCCESS)
{
RegCloseKey(clsidKey);
@ -933,10 +923,7 @@ HRESULT WINAPI OleRegGetMiscStatus(
*/
sprintfW(keyName, dfmtW, dwAspect);
result = RegOpenKeyW(miscStatusKey,
keyName,
&aspectKey);
result = open_classes_key(miscStatusKey, keyName, MAXIMUM_ALLOWED, &aspectKey);
if (result == ERROR_SUCCESS)
{
OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);

View File

@ -52,6 +52,7 @@
#include "winreg.h"
#include "wine/wingdi16.h"
#include "compobj_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(storage);
@ -8850,7 +8851,7 @@ HRESULT OLECONVERT_CreateCompObjStream(LPSTORAGE pStorage, LPCSTR strOleTypeName
HKEY hKey;
LONG hErr;
/* Get the CLSID Default Name from the Registry */
hErr = RegOpenKeyA(HKEY_CLASSES_ROOT, IStorageCompObj.strProgIDName, &hKey);
hErr = open_classes_key(HKEY_CLASSES_ROOT, bufferW, MAXIMUM_ALLOWED, &hKey);
if(hErr == ERROR_SUCCESS)
{
char strTemp[OLESTREAM_MAX_STR_LEN];

View File

@ -384,6 +384,8 @@ static void test_CoGetClassObject(void)
IUnknown *pUnk;
struct info info;
REFCLSID rclsid = &CLSID_InternetZoneManager;
HKEY hkey;
LONG res;
hr = CoGetClassObject(rclsid, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void **)&pUnk);
ok(hr == CO_E_NOTINITIALIZED, "CoGetClassObject should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr);
@ -428,6 +430,30 @@ static void test_CoGetClassObject(void)
CloseHandle(thread);
CloseHandle(info.wait);
CloseHandle(info.stop);
pCoInitializeEx(NULL, COINIT_MULTITHREADED);
hr = CoGetClassObject(rclsid, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void **)&pUnk);
if (hr == S_OK)
{
IUnknown_Release(pUnk);
res = RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Classes", 0, KEY_ALL_ACCESS, &hkey);
ok(!res, "RegOpenKeyExA returned %d\n", res);
res = pRegOverridePredefKey(HKEY_CLASSES_ROOT, hkey);
ok(!res, "RegOverridePredefKey returned %d\n", res);
hr = CoGetClassObject(rclsid, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void **)&pUnk);
ok(hr == S_OK, "CoGetClassObject should have returned S_OK instead of 0x%08x\n", hr);
res = pRegOverridePredefKey(HKEY_CLASSES_ROOT, NULL);
ok(!res, "RegOverridePredefKey returned %d\n", res);
if (hr == S_OK) IUnknown_Release(pUnk);
RegCloseKey(hkey);
}
CoUninitialize();
}
static ATOM register_dummy_class(void)