/*********************************************************************** * SHELL32_CoCreateInitSF * * Creates a shell folder and initializes it with a pidl and a root folder * via IPersistFolder3 or IPersistFolder. * * NOTES * pathRoot can be NULL for Folders being a drive. * In this case the absolute path is built from pidlChild (eg. C:) */ HRESULT SHELL32_CoCreateInitSF (LPCITEMIDLIST pidlRoot, PERSIST_FOLDER_TARGET_INFO* ppfti, LPCITEMIDLIST pidlChild, const GUID* clsid, REFIID riid, LPVOID *ppvOut) { HRESULT hr; CComPtr<IShellFolder> pShellFolder; hr = SHCoCreateInstance(NULL, clsid, NULL, IID_PPV_ARG(IShellFolder, &pShellFolder)); if (FAILED(hr)) return hr; LPITEMIDLIST pidlAbsolute = ILCombine (pidlRoot, pidlChild); CComPtr<IPersistFolder> ppf; CComPtr<IPersistFolder3> ppf3; if (ppfti && SUCCEEDED(pShellFolder->QueryInterface(IID_PPV_ARG(IPersistFolder3, &ppf3)))) { ppf3->InitializeEx(NULL, pidlAbsolute, ppfti); } else if (SUCCEEDED(pShellFolder->QueryInterface(IID_PPV_ARG(IPersistFolder, &ppf)))) { ppf->Initialize(pidlAbsolute); } ILFree (pidlAbsolute); return pShellFolder->QueryInterface(riid, ppvOut); }
/*********************************************************************** * SHELL32_CoCreateInitSF * * Creates a shell folder and initializes it with a pidl and a root folder * via IPersistFolder3 or IPersistFolder. * * NOTES * pathRoot can be NULL for Folders being a drive. * In this case the absolute path is built from pidlChild (eg. C:) */ static HRESULT SHELL32_CoCreateInitSF (LPCITEMIDLIST pidlRoot, LPCWSTR pathRoot, LPCITEMIDLIST pidlChild, REFCLSID clsid, IShellFolder** ppsfOut) { HRESULT hr; CComPtr<IShellFolder> pShellFolder; TRACE ("%p %s %p\n", pidlRoot, debugstr_w(pathRoot), pidlChild); hr = SHCoCreateInstance(NULL, &clsid, NULL, IID_PPV_ARG(IShellFolder, &pShellFolder)); if (SUCCEEDED (hr)) { LPITEMIDLIST pidlAbsolute = ILCombine (pidlRoot, pidlChild); CComPtr<IPersistFolder> ppf; CComPtr<IPersistFolder3> ppf3; if (SUCCEEDED(pShellFolder->QueryInterface(IID_PPV_ARG(IPersistFolder3, &ppf3)))) { PERSIST_FOLDER_TARGET_INFO ppfti; ZeroMemory (&ppfti, sizeof (ppfti)); /* fill the PERSIST_FOLDER_TARGET_INFO */ ppfti.dwAttributes = -1; ppfti.csidl = -1; /* build path */ if (pathRoot) { lstrcpynW (ppfti.szTargetParsingName, pathRoot, MAX_PATH - 1); PathAddBackslashW(ppfti.szTargetParsingName); /* FIXME: why have drives a backslash here ? */ } if (pidlChild) { int len = wcslen(ppfti.szTargetParsingName); if (!_ILSimpleGetTextW(pidlChild, ppfti.szTargetParsingName + len, MAX_PATH - len)) hr = E_INVALIDARG; } ppf3->InitializeEx(NULL, pidlAbsolute, &ppfti); } else if (SUCCEEDED((hr = pShellFolder->QueryInterface(IID_PPV_ARG(IPersistFolder, &ppf))))) { ppf->Initialize(pidlAbsolute); } ILFree (pidlAbsolute); } *ppsfOut = pShellFolder.Detach(); TRACE ("-- (%p) ret=0x%08x\n", *ppsfOut, hr); return hr; }
HRESULT WINAPI CDesktopFolder::FinalConstruct() { WCHAR szMyPath[MAX_PATH]; HRESULT hr; CComPtr<IPersistFolder3> ppf3; /* Create the root pidl */ pidlRoot = _ILCreateDesktop(); /* Create the inner fs folder */ hr = SHCoCreateInstance(NULL, &CLSID_ShellFSFolder, NULL, IID_PPV_ARG(IShellFolder2, &m_DesktopFSFolder)); if (FAILED(hr)) return hr; hr = m_DesktopFSFolder->QueryInterface(IID_PPV_ARG(IPersistFolder3, &ppf3)); if (FAILED(hr)) return hr; PERSIST_FOLDER_TARGET_INFO info; ZeroMemory(&info, sizeof(PERSIST_FOLDER_TARGET_INFO)); info.csidl = CSIDL_DESKTOPDIRECTORY; hr = ppf3->InitializeEx(NULL, pidlRoot, &info); /* Create the inner shared fs folder */ hr = SHCoCreateInstance(NULL, &CLSID_ShellFSFolder, NULL, IID_PPV_ARG(IShellFolder2, &m_SharedDesktopFSFolder)); if (FAILED(hr)) return hr; hr = m_SharedDesktopFSFolder->QueryInterface(IID_PPV_ARG(IPersistFolder3, &ppf3)); if (FAILED(hr)) return hr; info.csidl = CSIDL_COMMON_DESKTOPDIRECTORY; hr = ppf3->InitializeEx(NULL, pidlRoot, &info); if (!SHGetSpecialFolderPathW( 0, szMyPath, CSIDL_DESKTOPDIRECTORY, TRUE )) return E_UNEXPECTED; sPathTarget = (LPWSTR)SHAlloc((wcslen(szMyPath) + 1) * sizeof(WCHAR)); wcscpy(sPathTarget, szMyPath); return S_OK; }
HRESULT SHELL32_BindToGuidItem(LPCITEMIDLIST pidlRoot, PCUIDLIST_RELATIVE pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut) { CComPtr<IPersistFolder> pFolder; HRESULT hr; if (!pidlRoot || !ppvOut || !pidl || !pidl->mkid.cb) return E_INVALIDARG; *ppvOut = NULL; GUID *pGUID = _ILGetGUIDPointer(pidl); if (!pGUID) { ERR("SHELL32_BindToGuidItem called for non guid item!\n"); return E_INVALIDARG; } hr = SHCoCreateInstance(NULL, pGUID, NULL, IID_PPV_ARG(IPersistFolder, &pFolder)); if (FAILED(hr)) return hr; if (_ILIsPidlSimple (pidl)) { hr = pFolder->Initialize(ILCombine(pidlRoot, pidl)); if (FAILED(hr)) return hr; return pFolder->QueryInterface(riid, ppvOut); } else { LPITEMIDLIST pidlChild = ILCloneFirst (pidl); if (!pidlChild) return E_OUTOFMEMORY; hr = pFolder->Initialize(ILCombine(pidlRoot, pidlChild)); ILFree(pidlChild); if (FAILED(hr)) return hr; CComPtr<IShellFolder> psf; hr = pFolder->QueryInterface(IID_PPV_ARG(IShellFolder, &psf)); if (FAILED(hr)) return hr; return psf->BindToObject(ILGetNext (pidl), pbcReserved, riid, ppvOut); } }
/*********************************************************************** * SHELL32_CoCreateInitSF * * Creates a shell folder and initializes it with a pidl and a root folder * via IPersistFolder3 or IPersistFolder. * * NOTES * pathRoot can be NULL for Folders being a drive. * In this case the absolute path is built from pidlChild (eg. C:) */ static HRESULT SHELL32_CoCreateInitSF (LPCITEMIDLIST pidlRoot, LPCWSTR pathRoot, LPCITEMIDLIST pidlChild, REFCLSID clsid, LPVOID * ppvOut) { HRESULT hr; TRACE ("(%p %s %p %s %p)\n", pidlRoot, debugstr_w(pathRoot), pidlChild, debugstr_guid(clsid), ppvOut); hr = SHCoCreateInstance(NULL, clsid, NULL, &IID_IShellFolder, ppvOut); if (SUCCEEDED (hr)) { LPITEMIDLIST pidlAbsolute = ILCombine (pidlRoot, pidlChild); IPersistFolder *pPF; IPersistFolder3 *ppf; if (_ILIsFolder(pidlChild) && SUCCEEDED (IUnknown_QueryInterface ((IUnknown *) * ppvOut, &IID_IPersistFolder3, (LPVOID *) & ppf))) { PERSIST_FOLDER_TARGET_INFO ppfti; ZeroMemory (&ppfti, sizeof (ppfti)); /* fill the PERSIST_FOLDER_TARGET_INFO */ ppfti.dwAttributes = -1; ppfti.csidl = -1; /* build path */ if (pathRoot) { lstrcpynW (ppfti.szTargetParsingName, pathRoot, MAX_PATH - 1); PathAddBackslashW(ppfti.szTargetParsingName); /* FIXME: why have drives a backslash here ? */ } if (pidlChild) { int len = lstrlenW(ppfti.szTargetParsingName); if (!_ILSimpleGetTextW(pidlChild, ppfti.szTargetParsingName + len, MAX_PATH - len)) hr = E_INVALIDARG; } IPersistFolder3_InitializeEx (ppf, NULL, pidlAbsolute, &ppfti); IPersistFolder3_Release (ppf); } else if (SUCCEEDED ((hr = IUnknown_QueryInterface ((IUnknown *) * ppvOut, &IID_IPersistFolder, (LPVOID *) & pPF)))) { IPersistFolder_Initialize (pPF, pidlAbsolute); IPersistFolder_Release (pPF); } ILFree (pidlAbsolute); } TRACE ("-- (%p) ret=0x%08x\n", *ppvOut, hr); return hr; }
/************************************************************************* * AssocCreate [SHLWAPI.@] * * Create a new IQueryAssociations object. * * PARAMS * clsid [I] CLSID of object * refiid [I] REFIID of interface * lpInterface [O] Destination for the created IQueryAssociations object * * RETURNS * Success: S_OK. lpInterface contains the new object. * Failure: An HRESULT error code indicating the error. * * NOTES * clsid must be equal to CLSID_QueryAssociations and * refiid must be equal to IID_IQueryAssociations, IID_IUnknown or this function will fail */ HRESULT WINAPI AssocCreate(CLSID clsid, REFIID refiid, void **lpInterface) { TRACE("(%s,%s,%p)\n", debugstr_guid(&clsid), debugstr_guid(refiid), lpInterface); if (!lpInterface) return E_INVALIDARG; *(DWORD*)lpInterface = 0; if (!IsEqualGUID(&clsid, &CLSID_QueryAssociations)) return CLASS_E_CLASSNOTAVAILABLE; return SHCoCreateInstance( NULL, &clsid, NULL, refiid, lpInterface ); }