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;
}
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;
}