{
WCHAR wszInstanceKey[] = { 'C','L','S','I','D','\\','{','0','0','0','0','0','0','0','0','-',
'0','0','0','0','-','0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0',
'0','0','0','0','}','\\','I','n','s','t','a','n','c','e', 0 };
constWCHAR wszCLSID[] = { 'C','L','S','I','D',0 };
constWCHAR wszInitPropertyBag[] =
{ 'I','n','i','t','P','r','o','p','e','r','t','y','B','a','g',0 };
WCHAR wszCLSIDInstance[CHARS_IN_GUID];
CLSID clsidInstance;
HKEY hInstanceKey, hInitPropertyBagKey;
DWORD dwType, cbBytes = sizeof(wszCLSIDInstance);
IPropertyBag *pInitPropertyBag;
HRESULT hr;
LONGres;
TRACE("(rclsid=%s, riid=%s, ppvClassObject=%p)\n", debugstr_guid(rclsid), debugstr_guid(riid),
ppvClassObj);
/* Figure if there is an 'Instance' subkey for the given CLSID and acquire a handle. */if (!StringFromGUID2(rclsid, wszInstanceKey + 6, CHARS_IN_GUID) ||
!(wszInstanceKey[5+CHARS_IN_GUID]='\\') || /* Repair the null-termination. */ERROR_SUCCESS != RegOpenKeyExW(HKEY_CLASSES_ROOT, wszInstanceKey, 0, KEY_READ, &hInstanceKey))
{
/* If there is no 'Instance' subkey, then it's not a Shell Instance Object. */returnCLASS_E_CLASSNOTAVAILABLE;
}
if (RegQueryValueExW(hInstanceKey, wszCLSID, NULL, &dwType, (LPBYTE)wszCLSIDInstance, &cbBytes)
!= ERROR_SUCCESS || FAILED(CLSIDFromString(wszCLSIDInstance, &clsidInstance)))
{
/* 'Instance' should have a 'CLSID' value with a well-formed clsid-string. */FIXME("Failed to infer instance CLSID! %s\n", debugstr_w(wszCLSIDInstance));
RegCloseKey(hInstanceKey);
returnCLASS_E_CLASSNOTAVAILABLE;
}
/* Try to open the 'InitPropertyBag' subkey. */
res = RegOpenKeyExW(hInstanceKey, wszInitPropertyBag, 0, KEY_READ, &hInitPropertyBagKey);
RegCloseKey(hInstanceKey);
if (res != ERROR_SUCCESS) {
/* Besides 'InitPropertyBag's, shell instance objects might be initialized by streams. * So this case might not be an error. */TRACE("No InitPropertyBag key found!\n");
returnCLASS_E_CLASSNOTAVAILABLE;
}
/* If the construction succeeds, the new RegistryPropertyBag is responsible for closing * hInitProperyBagKey. */
hr = RegistryPropertyBag_Constructor(hInitPropertyBagKey, &IID_IPropertyBag,
(LPVOID*)&pInitPropertyBag);
if (FAILED(hr)) {
RegCloseKey(hInitPropertyBagKey);
return hr;
}
/* Construct an Instance Object Factory, which creates objects of class 'clsidInstance' * and asks them to initialize themselves with the help of the 'pInitiPropertyBag' */
hr = InstanceObjectFactory_Constructor(&clsidInstance, pInitPropertyBag, riid, ppvClassObj);
IPropertyBag_Release(pInitPropertyBag); /* The factory will hold a reference the bag. */return hr;
}
Generated on Sat May 26 2012 05:17:05 for ReactOS by
1.7.6.1
ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.