1
votes

I am using CreateDIBSection() to create a HBITMAP from a buffer, but sometimes - with no regular occurrence - I get a NULL pointer from it. I can't understand what may cause the function to return a NULL pointer because - as I said before - it is not regular. Sometimes it happens after displaying 10 frames, sometimes after 2 frames. Can someone explain me which are the possible reasons of the unexpected fail?

1
What does GetLastError() return when it fails? - Alan Stokes
@Alan GetLastError is not set for CreateDIBSection. At least not according to the docs. - David Heffernan
@David The documentation is somewhat unclear - it says the function returns NULL for failure, and also that it can "return" ERROR_INVALID_PARAMETER. - Alan Stokes
@Alan If SetLastError was called it would say so. You have to check for NULL or ERROR_INVALID_PARAMETER. Those are the failure modes. - David Heffernan
The online MSDN Library page is broken, unlike my local copies. It definitely sets the GetLastError return value. - Hans Passant

1 Answers

0
votes

If this function is failing at random, I would be inclined to think that the buffer is not correctly formatted or is messed up. Go back in the code that creates the buffer and see if any of the functions fail there. I would suspect that a functions return status is not being correctly checked before the code continues.