Florisve
Florisve

Reputation: 3

UWP CreateDDSTextureFromFile unable to loard .dds file

I'm currently trying to get a .dds file onto a cube, but having trouble loading in the file.

I'm using the DirectXTK libaries from nuget, more specificly the DDSTextureLoarder.

CreateDDSTextureFromFile(m_deviceResources->GetD3DDevice(), L"..\Assests\rocks.DDS", nullptr, &cubeStoneRV);

The error that comes up:

Error LNK2019 unresolved external symbol __imp__CreateFileW@28 referenced in function "long __cdecl DirectX::LoaderHelpers::LoadTextureDataFromFile(wchar_t const *,class std::unique_ptr > &,struct DirectX::DDS_HEADER const * *,unsigned char const * *,unsigned int *)" (?LoadTextureDataFromFile@LoaderHelpers@DirectX@@YAJPB_WAAV?$unique_ptr@$$BY0A@EU?$default_delete@$$BY0A@E@std@@@std@@PAPBUDDS_HEADER@2@PAPBEPAI@Z)

I believe that the problem lies with trying to get the D3DDevice, yet everything I have tried hasn't worked.

The work is started from the base UWP DirectX11 template and outside Sample3DSceneRenderer/phc, nothing else has changed.

edit: If there is a better way of doing this, im open for advice/suggestions

Upvotes: 0

Views: 263

Answers (1)

Chuck Walbourn
Chuck Walbourn

Reputation: 41127

For UWP you cannot use CreateFile. You must use CreateFile2.

    #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
        ScopedHandle hFile(safe_handle(CreateFile2(fileName,
                           GENERIC_READ,
                           FILE_SHARE_READ,
                           OPEN_EXISTING,
                           nullptr)));
    #else
        ScopedHandle hFile(safe_handle(CreateFileW(fileName,
                           GENERIC_READ,
                           FILE_SHARE_READ,
                           nullptr,
                           OPEN_EXISTING,
                           FILE_ATTRIBUTE_NORMAL,
                           nullptr)));
    #endif

I do this in DirectX Tool Kit already, but you need to use the correct build configuration of the library. Likely you are using the desktop NuGet version rather than the UWP NuGet version.

Upvotes: 0

Related Questions