コード例 #1
0
ファイル: Utils2.cpp プロジェクト: TReKiE/freecompose
bool _GetAppDataFolderFromKfm( CString& str ) {
	IKnownFolderManager* pkfm = NULL;
	IKnownFolder* pkf = NULL;
	LPWSTR path = NULL;
	bool ret = false;
	HRESULT hr;

	hr = CoCreateInstance( CLSID_KnownFolderManager, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS( &pkfm ) );
	if ( FAILED(hr) ) {
		debug( L"CoCreateInstance(CLSID_KnownFolderManager) failed: %08x\n", hr );
		goto out1;
	}

	hr = pkfm->GetFolder( FOLDERID_RoamingAppData, &pkf );
	if ( FAILED( hr ) ) {
		debug( L"pkfm->GetFolder(FOLDERID_RoamingAppData) failed: %08x\n", hr );
		goto out2;
	}

	hr = pkf->GetPath( 0, &path );
	if ( FAILED( hr ) ) {
		debug( L"pkf->GetPath failed: %08x\n", hr );
		goto out3;
	}

	str = path;
	CoTaskMemFree( path );

	ret = true;

out3:	pkf->Release( );
out2:	pkfm->Release( );
out1:	return ret;
}
コード例 #2
0
bool _GetAppDataFolderFromKfm( LPWSTR& lpsz ) {
	IKnownFolderManager* pkfm = nullptr;
	IKnownFolder* pkf = nullptr;
	bool ret = false;
	HRESULT hr;

	hr = CoCreateInstance( CLSID_KnownFolderManager, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS( &pkfm ) );
	if ( FAILED(hr) ) {
		debug( L"_GetAppDataFolderFromKfm: CoCreateInstance(CLSID_KnownFolderManager) failed: 0x%08x\n", hr );
		goto out1;
	}

	hr = pkfm->GetFolder( FOLDERID_RoamingAppData, &pkf );
	if ( FAILED( hr ) ) {
		debug( L"_GetAppDataFolderFromKfm: pkfm->GetFolder(FOLDERID_RoamingAppData) failed: 0x%08x\n", hr );
		goto out2;
	}

	hr = pkf->GetPath( 0, &lpsz );
	if ( FAILED( hr ) ) {
		debug( L"_GetAppDataFolderFromKfm: pkf->GetPath failed: 0x%08x\n", hr );
		goto out3;
	}

	ret = true;

out3:	pkf->Release( );
out2:	pkfm->Release( );
out1:	return ret;
}
コード例 #3
0
HRESULT RemovePhysicalFolder(REFKNOWNFOLDERID kfid)
{
    IKnownFolderManager *pkfm;
    HRESULT hr = CoCreateInstance(CLSID_KnownFolderManager, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pkfm));
    if (SUCCEEDED(hr))
    {
        IKnownFolder *pkf;
        hr = pkfm->GetFolder(kfid, &pkf);
        if (SUCCEEDED(hr))
        {
            PWSTR pszPath;
            hr = pkf->GetPath(0, &pszPath);
            if (SUCCEEDED(hr))
            {
                SHFILEOPSTRUCT fos = {};
                fos.wFunc = FO_DELETE;
                fos.pFrom = pszPath;
                fos.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT;
                if (0 != SHFileOperation(&fos))
                {
                    hr = E_FAIL;
                }

                CoTaskMemFree(pszPath);
            }
            pkf->Release();
        }
        pkfm->Release();
    }
    return hr;
}
コード例 #4
0
ファイル: WorkshareMenu.cpp プロジェクト: killbug2004/WSProf
bool CWorkshareMenu::GetPathForSendToFolder(CStdString& sSendToPath) const
{
	IKnownFolderManager* pkfm = NULL;
	HRESULT hr = CoCreateInstance(CLSID_KnownFolderManager, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pkfm));

	if( SUCCEEDED(hr) )
	{
		IKnownFolder* pkf = NULL;
		hr = pkfm->GetFolder(FOLDERID_SendTo, &pkf);

		if( SUCCEEDED(hr) )
		{
			LPWSTR pszPath = NULL;
			hr = pkf->GetPath(0, &pszPath);

			if( SUCCEEDED(hr) )
			{
				sSendToPath = pszPath;                

				CoTaskMemFree(pszPath);
			}

			pkf->Release();
		}

		pkfm->Release();
	}

	return SUCCEEDED(hr);
}