question

DeadStack avatar image
0 Votes"
DeadStack asked ·

WicImagingFactory.CreateDecoderFromFileName | FileNotFoundException

I have the following code

cs
private static async Task<BitmapSource> LoadBitmapSourceUsingWIC(Folders folder, string path)
{
    StorageFile file = await GetStorageFileAsync(folder, path);
    BitmapSource bmSource;
    unsafe
    {
        IWICImagingFactory* wicImagingFactory = CoreGraphics.WicImagingFactory.GetPtr();
        IWICBitmapDecoder* bmDecoder;
        IWICBitmapFrameDecode* bmFrame = null;

        IntPtr fileNameIntPtr = Marshal.StringToHGlobalAnsi(file.Path);

        HRESULT hr = wicImagingFactory->CreateDecoderFromFilename(
            (ushort*)fileNameIntPtr,
            null,
            GENERIC_READ,
            WICDecodeOptions.WICDecodeMetadataCacheOnDemand,
            &bmDecoder);


But it's throwing a FileNotFoundException. The file (StorageFile) is valid.

windows-uwp
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DeadStack avatar image
0 Votes"
DeadStack answered ·

I had to use this instead...

IntPtr fileNameIntPtr = Marshal.StringToHGlobalUni(file.Path);

There is so much inconsistency in Windows API's with strings. Why not just fix up the API's across Windows and between languages and make a collection of API's that are really easy to use together?

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.