Jump to content

  • Log In with Google      Sign In   
  • Create Account


Direct2D loading bitmap from file


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Divergence   Members   -  Reputation: 111

Like
0Likes
Like

Posted 10 May 2014 - 08:11 AM

Hi! First of all, sry for my not perfect english unsure.png

MS Visual Studio 2010 C++, Windows 7 x64, GeForce GTS450.

I cant solve one problem about 2 days.

I wanna create simple 2D game. I trying to use DX11 for it, but understood, that Direct2D will be much better and easy for this task.

The first thing i wanted to try: load bmp file to my window.

I find how to make it here: http://msdn.microsoft.com/en-us/library/windows/desktop/dd756686(v=vs.85).aspx

But when i trying to build solution i get acces violation in adress 0x0000000.

There is part of my code:

IWICImagingFactory *pFactory = NULL; //Creating pointer factory
IWICBitmapDecoder *pDecoder = NULL; //Creating pointer decoder
pFactory->CreateDecoder(GUID_ContainerFormatBmp, &GUID_VendorMicrosoft, &pDecoder); //here is the first AV
pFactory->CreateDecoderFromFilename(  //here is the second AV (when i commented line of code above 
        L"man.bmp",
        NULL,
        GENERIC_READ,
        WICDecodeMetadataCacheOnDemand,
        &pDecoder
        );

I have one idea why this code dont wanna work: i dont allocating memory for pointer pDecoder. But i saw many examples from MSDN, where teachers didnt do this too. So i totaly cant understand what i doing wrong... i puted file "man.bmp"  in many locations, but it didnt helped me too.

Plz, help with any adwice blink.png 


Edited by Divergence, 10 May 2014 - 08:13 AM.


Sponsor:

#2 Divergence   Members   -  Reputation: 111

Like
0Likes
Like

Posted 10 May 2014 - 10:10 AM

I tried add this after defining pointers:

 

CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFactory));
CoCreateInstance(CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDecoder));

but still i have acces violation =(((



#3 Divergence   Members   -  Reputation: 111

Like
2Likes
Like

Posted 10 May 2014 - 11:29 AM

It is solved!!!

The key is CoInitializeEx!!!

There is a code, that works:

IWICImagingFactory *pFactory = NULL; 
IWICBitmapDecoder *pDecoder = NULL;
CoInitializeEx(NULL,COINIT_MULTITHREADED);
HRESULT hr = CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFactory));
hr = CoCreateInstance(CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDecoder));
pFactory->CreateDecoderFromFilename( 
        L"man.bmp",
        NULL,
        GENERIC_READ,
        WICDecodeMetadataCacheOnDemand,
        &pDecoder
        );

I hope it will help smbdy! smile.png


Edited by Divergence, 10 May 2014 - 11:30 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS