My project inputs a telemetry stream that includes a real time image. From various places I have put together some code that seems like it should create a DIB and be ready to use. But the call to CreatDIBSection leaves my_bitmap and the pointer ppvBits both set to zero. The GetLastError returns zero indicating no error.
The project is a Win32 application under Visual Studio 2008, C++, with SDI and MFC enabled. Eventually this will become part of an ActiveX project, but for now I am just trying to write bits to the screen.
What have I done wrong here?
We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
The project is a Win32 application under Visual Studio 2008, C++, with SDI and MFC enabled. Eventually this will become part of an ActiveX project, but for now I am just trying to write bits to the screen.
What have I done wrong here?
Code:
const int IMAGE_ROW_COUNT = 120;
const int IMAGE_COLUMN_COUNT = 120;
const int BYTES_PER_PIXEL = 3; // unknown, presume 3, one each RBG, change later
const int RGB_THREE_BYTES_PER_PIXEL = 24;
BITMAPINFO my_bit_map_info;
BITMAPINFOHEADER my_bit_map_info_header;
RGBQUAD my_rgb_quad;
HBITMAP my_bitmap;
VOID *ppvBits = NULL;
HDC client_area_DC;
HDC my_hdc;
DWORD last_error = 3;
my_bit_map_info_header.biSize = IMAGE_ROW_COUNT * IMAGE_COLUMN_COUNT * BYTES_PER_PIXEL;
my_bit_map_info_header.biWidth = IMAGE_COLUMN_COUNT;
my_bit_map_info_header.biHeight = IMAGE_ROW_COUNT;
my_bit_map_info_header.biPlanes = 1; // F1 help says must be 1.
my_bit_map_info_header.biBitCount = RGB_THREE_BYTES_PER_PIXEL;
my_bit_map_info_header.biCompression = BI_RGB;
my_bit_map_info_header.biSizeImage = 0; // per F1 help
// but: [URL unfurl="true"]http://www.codeguru.com/forum/printthread.php?t=456626[/URL]
// uses 256.
my_bit_map_info_header.biXPelsPerMeter = 0; // Google found something that said always 0;
my_bit_map_info_header.biYPelsPerMeter = 0;
my_bit_map_info_header.biClrUsed = 0; // my guess
my_bit_map_info_header.biClrImportant = 0; // my guess
my_rgb_quad.rgbBlue = 255;
my_rgb_quad.rgbGreen = 255;
my_rgb_quad.rgbRed = 255;
my_rgb_quad.rgbReserved = 0;
my_bit_map_info.bmiHeader = my_bit_map_info_header;
my_bit_map_info.bmiColors[0] = my_rgb_quad;
client_area_DC = ::GetDC( NULL );
my_hdc = CreateCompatibleDC( client_area_DC );
my_bitmap = CreateDIBSection(
my_hdc, // handle to DC
&my_bit_map_info, // bitmap data
DIB_RGB_COLORS, // data type indicator
&ppvBits, // Provide the address of a pointer so the function can
// return a bit map. So says the documentation.
NULL, //
0 ); // zero.Goes with the previous NULL
last_error = GetLastError();
return nRetCode;
We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)