Creating HBITMAP from memory buffer
I’d use CreateCompatibleBitmap, and then call SetDIBits to fill it with your data. These are functions I have seen to work, and SetDIBits is quite flexible, although verbose. In my MFC years, CreateBitmap was avoided due to suspected performance issues.