簡體   English   中英

在Windows運行時組件中使用WRL獲取文件夾路徑將返回空字符串

[英]Using WRL in Windows runtime component to get folder path returns empty string

我目前正在將Boost“文件系統”庫移植到Windows Phone 8.1。 通過用其他較新的非禁止功能替換“禁止”的Win32 API函數,我成功移植了大約一半的問題功能。

現在,我需要解決沒有替代Win32 API的那些Boost函數。 基於史蒂夫·蓋茨(Steve Gates)將其他Boost庫移植到WP8.1的出色移植,並與他私下交流,我決定在Boost代碼中使用WRL,而不是C ++ / CX。

為了學習WRL並掌握方向,我編寫了一個最小的WP8.1應用程序,其中包括一個C ++ / CX客戶端應用程序,該應用程序調用一個Windows運行時組件,后者由C ++編寫。 在運行時組件中,我有一個函數試圖確定圖片庫的文件系統路徑。 我遇到的問題是,我得到的最終路徑(即pszPath)是一個空字符串。

這是運行時組件代碼:

void Class1::Test1()
{
    HRESULT hr;

    HString hstrKnownFolders;
    hstrKnownFolders.Set(RuntimeClass_Windows_Storage_KnownFolders);

    // Get the Activation Factory
    ComPtr<IActivationFactory> pKnownFoldersActivationFactory;
    hr = ABI::Windows::Foundation::GetActivationFactory(hstrKnownFolders.Get(), 
                                                        &pKnownFoldersActivationFactory);
    if (FAILED(hr))
    {
        ::Microsoft::WRL::Details::RaiseException(hr);
    }

    // QI for the IKnownFoldersStatics
    ComPtr<IKnownFoldersStatics> pKnownFolders;
    hr = pKnownFoldersActivationFactory.As(&pKnownFolders);
    if (FAILED(hr))
    {
        ::Microsoft::WRL::Details::RaiseException(hr);
    }

    // Get the Pictures library folder
    ComPtr<IStorageFolder> pStorageFolder;
    hr = pKnownFolders->get_PicturesLibrary(&pStorageFolder);
    if (FAILED(hr))
    {
        ::Microsoft::WRL::Details::RaiseException(hr);
    }

    // QI for the IStorageItem interface (from which IStorageFolder is derived)
    ComPtr<IStorageItem> pItem;
    hr = pStorageFolder.As(&pItem);

    // Get the path corresponding to the folder
    HSTRING hsPath;
    pItem->get_Path(&hsPath);
    PCWSTR pszPath = WindowsGetStringRawBuffer(hsPath, 0);
}

在函數的末尾,函數get_Path()返回一個空字符串。 誰能說明我做錯了什么,以及應該怎么做?

提前致謝!

沒有路徑是正確的結果:Pictures庫是一個shell文件夾,它編譯來自多個位置(例如公共Pictures目錄和用戶的picture目錄)的數據。 圖片庫本身沒有路徑。

庫中的單個項目可能具有路徑,但它們可能不是同一文件系統目錄中的路徑。

StorageFiles不限於文件系統中的“文件”。 它們還可以包括外殼中其他位置的對象以及其他應用程序的對象。 所有這些都表示為文件流,但不一定具有文件系統路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM