Remember that C++ parameters like ID2D1Bitmap* bitmap1
are passed by value. That means you have two completely separate (and almost unrelated) variables bmp1
and bitmap1
. The only relationship the two variables have is that bitmap1
starts life with the same value that bmp1
had when decode
was called - i.e., NULL
.
Your decode
logic calls CreateBitmapFromWicBitmap
passing in the address of bitmap1
and CreateBitmapFromWicBitmap
carefully fills bitmap1
with the address of the newly created bitmap. But that doesn't affect bmp1
at all. So bmp1
remains set to null. You can check this for yourself by placing a breakpoint on return hr
and then looking at the contents of bmp1
and bitmap1
.
If you want Decode to change the contents of bmp1
you need to pass the address of bmp1
to decode
not the contents. That means bitmap1 should be type ID2D1Bitmap **
and decode should be called like this... rl->decode(L"Menu_corner.png", &bmp1);
Update
Several comments pointed out that I was rather careless in saying "C++ parameters are passed by value", I've reworded the text above to be more focused.
The comments also point out that that C++ parameters can be passed by reference as well as by value. In the case of the decode
function by using the syntax ID2D1Bitmap*& bitmap1
.
I have to confess I'm somewhat ambivalent about the relative merits of ID2D1Bitmap** bitmap1
and ID2D1Bitmap*& bitmap1
. But that may say more about my personal biases than about anything else.