Hye Jeff,
Sorry If you are confused from my questions... Actually What I am doing
is, Capturing window into a bitmap file, saving it to BMP (with RLE8
compression), so for saving it to disk, I am creating a hell lot of
variables to handle all the complexity. Now, as you told, my GlobalFree
returns NULL, so, that object is freedup, but the problem is for other
objects of structures and variables that I created to save it to disk. How
to free that.. e.g. here is a snippet of code...
----------------------------------------------------------------------------
-------------
//code starts here... (it is a small function that allocates memory for DIB)
----------------------------------------------------------------------------
-------------
HANDLE CDV_ClientDlg::AllocRoomForDIB(BITMAPINFOHEADER bi, HBITMAP hBitmap,
HWND hwnd)
{
// Figure out the size needed to hold the BITMAPINFO structure
// (which includes the BITMAPINFOHEADER and the color table).
dwLen = bi.biSize + PaletteSize((LPSTR) &bi);
hDIB = GlobalAlloc(GHND,dwLen);
// Check that DIB handle is valid
if (!hDIB)
return NULL;
// Set up the BITMAPINFOHEADER in the newly allocated global memory,
// then call GetDIBits() with lpBits = NULL to have it fill in the
// biSizeImage field for us.
lpbi_2 = (LPBITMAPINFOHEADER)GlobalLock(hDIB);
*lpbi_2 = bi;
hDC_1 = CreateDC ( TEXT("DISPLAY"), NULL, NULL, NULL );
GetDIBits(hDC_1, hBitmap, 0, (UINT) bi.biHeight, NULL, (LPBITMAPINFO)lpbi_2,
DIB_RGB_COLORS);
::ReleaseDC(hwnd, hDC_1);
// If the driver did not fill in the biSizeImage field,
// fill it in -- NOTE: this is a bug in the driver!
if (lpbi_2->biSizeImage == 0)
lpbi_2->biSizeImage = WIDTHBYTES((DWORD)lpbi_2->biWidth *
lpbi_2->biBitCount) * lpbi_2->biHeight;
// Get the size of the memory block we need
dwLen = lpbi_2->biSize + PaletteSize((LPSTR) &bi) + lpbi_2->biSizeImage;
// Unlock the memory block
GlobalUnlock(hDIB);
// ReAlloc the buffer big enough to hold all the bits
if (hTemp = GlobalReAlloc(hDIB,dwLen,0))
return hTemp;
else
{
// Else free memory block and return failure
GlobalFree(hDIB);
return NULL;
}
}
HANDLE CDV_ClientDlg::AllocRoomForDIB(BITMAPINFOHEADER bi, HBITMAP hBitmap,
HWND hwnd)
{
// Figure out the size needed to hold the BITMAPINFO structure
// (which includes the BITMAPINFOHEADER and the color table).
dwLen = bi.biSize + PaletteSize((LPSTR) &bi);
hDIB = GlobalAlloc(GHND,dwLen);
// Check that DIB handle is valid
if (!hDIB)
return NULL;
// Set up the BITMAPINFOHEADER in the newly allocated global memory,
// then call GetDIBits() with lpBits = NULL to have it fill in the
// biSizeImage field for us.
lpbi_2 = (LPBITMAPINFOHEADER)GlobalLock(hDIB);
*lpbi_2 = bi;
hDC_1 = CreateDC ( TEXT("DISPLAY"), NULL, NULL, NULL );
GetDIBits(hDC_1, hBitmap, 0, (UINT) bi.biHeight, NULL, (LPBITMAPINFO)lpbi_2,
DIB_RGB_COLORS);
::ReleaseDC(hwnd, hDC_1);
// If the driver did not fill in the biSizeImage field,
// fill it in -- NOTE: this is a bug in the driver!
if (lpbi_2->biSizeImage == 0)
lpbi_2->biSizeImage = WIDTHBYTES((DWORD)lpbi_2->biWidth *
lpbi_2->biBitCount) * lpbi_2->biHeight;
// Get the size of the memory block we need
dwLen = lpbi_2->biSize + PaletteSize((LPSTR) &bi) + lpbi_2->biSizeImage;
// Unlock the memory block
GlobalUnlock(hDIB);
// ReAlloc the buffer big enough to hold all the bits
if (hTemp = GlobalReAlloc(hDIB,dwLen,0))
return hTemp;
else
{
// Else free memory block and return failure
GlobalFree(hDIB);
return NULL;
}
}
----------------------------------------------------------------------------
-------------
//code ends here
----------------------------------------------------------------------------
-------------
Now here you can see that I am allocating some memory, after that I Save the
bitmap and then I want to free these memory.. All variables used are global
so, I will be able to free them up later.. But free() method gives me error
for lpbi_2 i.e. free(lpbi_2) gives runtime error (that abort dialog)...
If you are still confused and want a full application code, (want to help me
really), Please tell me, I will send you full application (of VC.NET). I am
tired of this as I am trying to do this from last 4 hours.)