Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Losing HBITMAP

Status
Not open for further replies.

elgohary

Programmer
Feb 16, 2005
8
0
0
US
Hi all,

I have function that takes an HBITMAP as a param. The function internally generates a TBitmap and releases the handle to the passed HBITMAP param. The function correctly generated the TBitmap. After I release the handle to the parameter, I inspected the bitmap object and it looks fine as well. When I return to the calling function, the handle is NULL.

Below is the source... Any help would be greatly appreciated. Thanks.


// scans a document and returns an error code
// hdib - Handle to the bitmap image of the document
BYTE ScanDoc( HBITMAP hdib )
{
BTYE ec = 0;
UCHAR *buf = new UCHAR[1024*64];

ec = GetImageBuf(buf);

if(ec == 0)
{
ec = BufferToDIB(buf, hdib);
// at this point hdib = null
}

// house keeping
delete buf;

return ec;
}

// converts a custom image buffer to a bitmap
UCHAR BufferToDIB( UCHAR *buf, HBITMAP hdib)
{
// create a pointer to a TBitmap object
Graphics::TBitmap *bmp = new Graphics::TBitmap();

// populate the TBitmap
.
.
.

// save the bitmap image !!!DEBUG
bmp->SaveToFile("C:\\Temp\\TestImage.bmp");

// transfer ownership to the HBITMAP
hdib = bmp->ReleaseHandle();

// house keeping
delete bmp;

// inspect the HBITMAP
BITMAP bm;
GetObject(hdib, sizeof(BITMAP), (LPSTR)&bm);
int planes = bm.bmPlanes;
int bits = bm.bmBitsPixel;
// at this point, planes and bits look good

return 0;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top