简体   繁体   English

无法在Direct2D项目中初始化IWICImagingFactory

[英]can't initialize IWICImagingFactory in a direct2d project

i'm creating a direct2d project and i can't load a bitmap picture because the object of the class IWICImagingFactory is null. 我正在创建一个Direct2d项目,并且我无法加载位图图片,因为IWICImagingFactory类的对象为null。 i don't know if i am calling correctly the function CoCreateInstance. 我不知道我是否正确调用了函数CoCreateInstance。

this is the code i am using for initialize everything: 这是我用于初始化所有内容的代码:

// ... d2dFactory ... and others objects
IWICImagingFactory* pIWICFactory = 0;

HRESULT TDE_Device::Initialize(HWND hwnd)
{
    HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &d2dFactory);
    //
    RECT rc;
    GetClientRect(hwnd, &rc);
    //
    D2D1_SIZE_U size = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top);
    d2dFactory->CreateHwndRenderTarget(D2D1::RenderTargetProperties(),     D2D1::HwndRenderTargetProperties(hwnd, size), &MainD2DCore.d2dRenderTarg);
    wndHandle = hwnd;
    //
    // ----------  HERE IS THE CoCreateInstance ------------------------
    CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, reinterpret_cast<void **>(&pIWICFactory));
    if (pIWICFactory == 0)
    {
        // I GET THIS MESSAGE
        MessageBox(NULL, L"Error creating the Image Factory", L"ERROR", MB_OK);
        return E_FAIL;
    }
    //
    return hr;
}

when i try to use this IWICImagingFactory for load a picture from file, i get the Access violation exception because is reading the address 0x0. 当我尝试使用此IWICImagingFactory从文件加载图片时,由于读取地址0x0,我遇到了访问冲突异常。

what the correct way to call the function CoCreateInstance? 调用函数CoCreateInstance的正确方法是什么?

Yes it is the correct way of creating an ImagingFactory but did you call CoInitializeEx( NULL, COINIT_MULTITHREADED); 是的,这是创建ImagingFactory的正确方法,但是您是否调用了CoInitializeEx(NULL,COINIT_MULTITHREADED); befor calling CoCreateInstance? 之前调用CoCreateInstance吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM