HRESULT GetKnownFolderForPath(PCWSTR pszPath, KNOWNFOLDERID *pkfid, KNOWNFOLDER_DEFINITION *pkfd)
{
    IKnownFolderManager *pkfm;
    HRESULT hr = CoCreateInstance(CLSID_KnownFolderManager, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pkfm));
    if (SUCCEEDED(hr))
    {
        IKnownFolder *pkf;
        hr = pkfm->FindFolderFromPath(pszPath, FFFP_EXACTMATCH, &pkf);
        if (S_OK == hr)
        {
            hr = pkf->GetId(pkfid);
            if (S_OK == hr)
            {
                hr = pkf->GetFolderDefinition(pkfd);
                if (S_OK != hr)
                {
                    wprintf(L"IKnownFolderManager::GetFolderDefinition return hr=0x%x\n", hr);
                }
            }
            else
            {
                wprintf(L"IKnownFolder::GetId return hr=0x%x\n", hr);
            }
            pkf->Release();
        }
        else
        {
            wprintf(L"IKnownFolderManager::FindFolderFromPath return hr=0x%x\n", hr);
        }
        pkfm->Release();
    }
    return hr;
}
// @pymethod <o PyIKnownFolder>|PyIKnownFolderManager|FindFolderFromPath|Retrieves a known folder by path
PyObject *PyIKnownFolderManager::FindFolderFromPath(PyObject *self, PyObject *args)
{
	IKnownFolderManager *pIKFM = GetI(self);
	if ( pIKFM == NULL )
		return NULL;
	// @pyparm str|Path||Path of a folder
	// @pyparm int|Mode||FFFP_EXACTMATCH or FFFP_NEARESTPARENTMATCH	
	TmpWCHAR path;
	PyObject *obpath;
	FFFP_MODE mode;
	IKnownFolder *ret;
	if ( !PyArg_ParseTuple(args, "Oi:FindFolderFromPath", &obpath, &mode))
		return NULL;
	if (!PyWinObject_AsWCHAR(obpath, &path, FALSE))
		return NULL;
	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pIKFM->FindFolderFromPath(path, mode, &ret);
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIKFM, IID_IKnownFolderManager );
	return PyCom_PyObjectFromIUnknown(ret, IID_IKnownFolder, FALSE);
}