I'm trying to open a DDS file with my DirectX 11 project, however, most of the cases, it refuses to open it. Everytimes it fails, I get E_ACCESSDENIED error. The only way to make it working is to put the relative path to the current directory or subdirectory. If it's a relative path to a parent directory, or if it's a absolute path, the function will fail.
The problem is that I wish to open the image using FileOpenPicker, so in every cases, I get an absolute path...
I will share my functions:
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.
});
}
And then, I call the function to load the texture...
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;
}
Well, since I have no idea why, that's why I come here to request your help.
Thank you very much!