Jump to content
  • Advertisement
Sign in to follow this  
Divergence

DX11 Direct2D loading bitmap from file

This topic is 1680 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

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 =(((

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!