我在Windows 7上使用GDI / MFC开发了一个Deskstop应用。
此应用每5秒加载一张图片。 4-5小时后崩溃,我在CreateDIBSection中收到了ERROR_INVALID_PARAMETER。
这是我的代码:
UINT local_colors = 2;
RGBQUAD image_colormap[2];
image_colormap[0].rgbRed = image_colormap[0].rgbGreen = image_colormap[0].rgbBlue = 0;
image_colormap[1].rgbRed = image_colormap[1].rgbGreen = image_colormap[1].rgbBlue = 255;
UINT local_bmpInfo_size = sizeof(BITMAPINFO) + local_colors * sizeof(RGBQUAD);;
LPBITMAPINFO local_bmpInfo = (LPBITMAPINFO ) malloc(local_bmpInfo_size);
local_bmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
local_bmpInfo->bmiHeader.biBitCount = 1;
local_bmpInfo->bmiHeader.biClrUsed = local_colors;
local_bmpInfo->bmiHeader.biCompression = BI_RGB;
local_bmpInfo->bmiHeader.biHeight = 320l;
local_bmpInfo->bmiHeader.biPlanes = 1;
local_bmpInfo->bmiHeader.biWidth = 320l;
CopyMemory(local_bmpInfo->bmiColors, image_colormap, local_colors* sizeof(RGBQUAD));
HDC local_hDC = ::GetDC(NULL);
if(local_hDC)
{
UCHAR* image_bits = NULL;
HBITMAP local_imgHandle = CreateDIBSection(local_hDC , local_bmpInfo, DIB_RGB_COLORS, (void**)&image_bits, NULL, 0l);
}
::Release(NULL,local_hDC);
你有什么主意吗?