I cant create WIC decoder and load image

Hi!
I tyring to download from file "man.bmp" image. I using WIC for it.
Here the code:
1
2
3
4
5
6
7
8
9
10
11
12
IWICImagingFactory *pFactory = NULL; //Создали фабрику
IWICBitmapDecoder *pDecoder = NULL; //Создаем декодер
pFactory->CreateDecoder(GUID_ContainerFormatBmp, 
                       &GUID_VendorMicrosoft, 
                       &pDecoder);
	pFactory->CreateDecoderFromFilename( 
        L"D\\man.bmp",
        NULL,
        GENERIC_READ,
        WICDecodeMetadataCacheOnDemand,
        &pDecoder
        );

First of all, code is from MSDN.
http://msdn.microsoft.com/en-us/library/windows/desktop/dd756686(v=vs.85).aspx
They creating pointers without memory allocation then using CreateDecoderFromFilename function. When i buildling project, i geting error: access Violation reading "0x00000000".
I cant beat this... plz help!
You set pFactory to NULL and tried to call methods through it. Other than an access violation, I am not sure what you expected to happen. The MSDN page you linked to does not initialize pFactory to NULL, but assumes you already have a valid pointer to the Factory object.

Adding:

 
CoCreateInstance(CLSID_WICImagingFactor, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFactory));


prior to calling methods through pFactory will at least solve your access violation problem.
Last edited on
Thank you! i thought about that... i tried it, but problem didnt went away =(
Now i need to create IWICBitmapDecoder from my pointer.
Can somebody help me with it? I cant find in MSDN any answer(((
I tried this:
CoCreateInstance(CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDecoder));
but still accees violation ...
Sadly, i cant say here what i think about this... sheet)
Well, did the call to CoCreateInstance(...) succeed? If it did not, what error value did CoCreateInstance return? The only reason I can think CoCreateInstance would fail in this case is that you did not initialize the COM library with a call to CoInitializeEx before calling CoCreateInstance.
Well, did the call to CoCreateInstance(...) succeed? If it did not, what error value did CoCreateInstance return? The only reason I can think CoCreateInstance would fail in this case is that you did not initialize the COM library with a call to CoInitializeEx before calling CoCreateInstance.

Oh! Well, it is nice idea, i will try it.
But description of CoInitializeEx on MSDN pwnd me hard... i am too low for understandig it fast =(
Thx for adwices! =)
OMG! U were soooo right!
The key is CoInitializeEx!!!!
Now ill try to understand how to use it...
YES!!! YES!!! IT WORKS NOW!!!
I AM SOOO HAPPY! SOOO HAPY!
cburn11, great big awesome thank you from me!!
Topic archived. No new replies allowed.