我試圖用我的DirectX 11項目打開DDS文件,但是,大多數情況下,它拒絕打開它。每次失敗,我都會收到E_ACCESSDENIED錯誤。 使其工作的唯一方法是將相對路徑放到當前目錄或子目錄中。如果它是到父目錄的相對路徑,或者它是絕對路徑,則該函數將失敗。無法打開C++(directx應用程序)訪問被拒絕的文件
的問題是,我想打開使用FileOpenPicker的形象,所以在每一個情況下,我得到一個絕對路徑...
我將分享我的功能:
void Element::FileOpenDialog()
{
FileOpenPicker^ fileOpenPicker = ref new FileOpenPicker();
fileOpenPicker->ViewMode = PickerViewMode::Thumbnail;
fileOpenPicker->SuggestedStartLocation = PickerLocationId::PicturesLibrary;
fileOpenPicker->CommitButtonText = "Load";
fileOpenPicker->FileTypeFilter->Append(".dds");
create_task(fileOpenPicker->PickSingleFileAsync()).then([this](StorageFile^ file)
{
if (file)
{
m_fullPath = const_cast<wchar_t*>(file->Path->Data());
wcout << m_fullPath << endl; // prints the correct path of the selected file
m_loadedImage = false;
}
m_choseImage = true; // Checking in another code if the user chose an image to load.
});
}
然後,我稱之爲加載紋理的函數...
bool Texture::LoadFile(wchar_t* path, GameWindow^ gameWindow)
{
m_gameWindow = gameWindow;
ComPtr<ID3D11Resource> resource = nullptr;
if (!FH::ThrowIfFailed(CreateDDSTextureFromFile(m_gameWindow->dev.Get(), L"texture.dds", resource.GetAddressOf(), m_texture.ReleaseAndGetAddressOf()))) return false; // Works
if (!FH::ThrowIfFailed(CreateDDSTextureFromFile(m_gameWindow->dev.Get(), L"texture\\texture.dds", resource.GetAddressOf(), m_texture.ReleaseAndGetAddressOf()))) return false; // Works
if (!FH::ThrowIfFailed(CreateDDSTextureFromFile(m_gameWindow->dev.Get(), L"..\\texture.dds", resource.GetAddressOf(), m_texture.ReleaseAndGetAddressOf()))) return false; // E_ACCESSDENIED
if (!FH::ThrowIfFailed(CreateDDSTextureFromFile(m_gameWindow->dev.Get(), path, resource.GetAddressOf(), m_texture.ReleaseAndGetAddressOf()))) return false; // E_ACCESSDENIED
return true;
}
那麼,因爲我不知道爲什麼,這就是爲什麼我來這裏要求你的幫助。
非常感謝!
非常感謝,我不知道它,現在它的工作! – Drake