// Processes a single argument which identifies the library to operate on; passes any remaining arguments to the derived class. HRESULT v_ProcessArguments(PCWSTR *ppszArgs, int cArgs) { PCWSTR pszLibPath = CONSUME_NEXT_ARG(ppszArgs, cArgs); HRESULT hr = pszLibPath ? S_OK : E_INVALIDARG; if (SUCCEEDED(hr)) { if (_fCreate) { // When creating a new library, interpret the argument as the file system path to save the library to. WCHAR szAbsPath[MAX_PATH]; hr = SHStrDupW(_wfullpath(szAbsPath, pszLibPath, ARRAYSIZE(szAbsPath)), &_pszSavePath); } else { // Check for the 'FOLDERID_' prefix, which indicates that the argument should be interpreted as a KNOWNFOLDERID. const WCHAR szPrefix[] = L"FOLDERID_"; const UINT cchPrefix = ARRAYSIZE(szPrefix) - 1; if (StrCmpNCW(pszLibPath, szPrefix, cchPrefix) == 0) { IKnownFolderManager *pkfm; hr = CoCreateInstance(CLSID_KnownFolderManager, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pkfm)); if (SUCCEEDED(hr)) { // KNOWNFOLDERIDs are GUIDs, but they have a corresponding canonical name which is a string. // By convention, the canonical name is the same as the name of the KNOWNFOLDERID #define. // That is, FOLDERID_DocumentsLibrary => "DocumentsLibrary". So, skip the prefix and pass // the remainder to GetFolderByName to retrieve the known folder. IKnownFolder *pkf; hr = pkfm->GetFolderByName(pszLibPath + cchPrefix, &pkf); if (SUCCEEDED(hr)) { hr = pkf->GetShellItem(KF_FLAG_INIT, IID_PPV_ARGS(&_psiLibrary)); pkf->Release(); } pkfm->Release(); } } else { // Default - interpret the argument as a file system path, and create a shell item for it. WCHAR szAbsPath[MAX_PATH]; hr = SHCreateItemFromParsingName(_wfullpath(szAbsPath, pszLibPath, ARRAYSIZE(szAbsPath)), NULL, IID_PPV_ARGS(&_psiLibrary)); } } } else { ParseError(L"Missing library path argument.\n"); } if (SUCCEEDED(hr)) { // Allow derived command to process any remaining arguments. hr = v_ProcessLibArguments(ppszArgs, cArgs); } return hr; }
// @pymethod <o PyIKnownFolder>|PyIKnownFolderManager|GetFolderByName|Returns a folder by canonical name PyObject *PyIKnownFolderManager::GetFolderByName(PyObject *self, PyObject *args) { IKnownFolderManager *pIKFM = GetI(self); if ( pIKFM == NULL ) return NULL; // @pyparm str|Name||The nonlocalized name of a known folder PyObject *obname; TmpWCHAR name; IKnownFolder *ret; if ( !PyArg_ParseTuple(args, "O:GetFolderByName", &obname)) return NULL; if (!PyWinObject_AsWCHAR(obname, &name, FALSE)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIKFM->GetFolderByName(name, &ret); PY_INTERFACE_POSTCALL; return PyCom_PyObjectFromIUnknown(ret, IID_IKnownFolder, FALSE); }