×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

using CreateDIBSection()

using CreateDIBSection()

using CreateDIBSection()

(OP)
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?

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: http://www.codeguru.com/forum/printthread.php?t=456626
                                                // 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)
 

RE: using CreateDIBSection()

At the least, initialize biSize member by sizeof(BITMAPINFOHEADER).

 

RE: using CreateDIBSection()

(OP)
That made a difference. Now my_bitmap and ppvBits both are no longer zeroes.  I was thinking that was the size of the bit map I wanted.  

I do find it curious that the size of the structure must be in there.  There are no pointers, no arrays, nothing I can see that would ever change the size of the structure. The debugger shows 40 so it will always be 40.  Oh well.

You have helped me make another step.  Now I will go back and see what to do next.  If you want to throw any more hints my way I am all ears.

Thanks for taking the time to post.

We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
 

RE: using CreateDIBSection()

It's Windows API style to place the size of a structure into the 1st element. Probably it helps to recognize the structure object version.

Win API calculates the size of the bitmap automatically by another members.
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close