c++winapidirectxdirect2dwic

D2D1 failed initializing Imaging factory


I am new to d2d1, and tried to use LoadImageFromFile function from msdn to load mitmap, it need as one of it arguments pointer to IWICImagingFactory, because i need to pass it into the function, it must be initialized ant can`t be NULL, how to initialize it with non NULL value, or how to pass it into the function? Visual studio 2019. Thanks for help/


Solution

  • You need to call CoCreateInstance with CLSID_WICImagingFactory argument. See this question, for example: CoCreateInstance of IWICImagingFactory

    Or this intro: Introduction to WIC: How to use WIC to load an image, and draw it with GDI?

    Or, this sample:

        hr = CoCreateInstance(
            CLSID_WICImagingFactory,
            NULL,
            CLSCTX_INPROC_SERVER,
            IID_IWICImagingFactory,
            reinterpret_cast<void **>(&pWICFactory)
            );
    

    Or this SimpleDirect2DApplication sample which features Driect2D and WIC capabilities to load from file.