急!!!!!0x7c812a5b 处未处理的异常: Microsoft C++ 异常: 内存位置 0x0012fa90 处的 std::bad_alloc。 错误怎么解决
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc,hdcMem;
FILE *fp;
int line,colum,MoveBits,btcounts;
BYTE *ReadBits=NULL;
UINT32 **Bits=NULL;
UINT32 *tmparray=NULL;
int dzsize=18;
PBITMAPINFO lpbmi=(BITMAPINFO*) new BYTE[sizeof(BITMAPINFOHEADER)];
ZeroMemory(lpbmi,sizeof(BITMAPINFO));
lpbmi->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
lpbmi->bmiHeader.biWidth=dzsize;
lpbmi->bmiHeader.biHeight=dzsize;
lpbmi->bmiHeader.biPlanes=1;
lpbmi->bmiHeader.biBitCount=32;
lpbmi->bmiHeader.biCompression=BI_RGB;
lpbmi->bmiHeader.biSizeImage =0;
lpbmi->bmiHeader.biXPelsPerMeter=GetSystemMetrics(SM_CXSCREEN);//GetDeviceCaps(hdc,HORZRES);
lpbmi->bmiHeader.biYPelsPerMeter=GetSystemMetrics(SM_CYSCREEN);//GetDeviceCaps(hdc,VERTRES);
lpbmi->bmiHeader.biClrUsed=0;
lpbmi->bmiHeader.biClrImportant=0;
switch (message)
{
case WM_PAINT :
hdc=BeginPaint(hwnd,&ps);
ReadBits=(BYTE*)malloc(sizeof(BYTE)*ceil(dzsize*dzsize/8.0));
ZeroMemory(ReadBits,ceil(dzsize*dzsize/8.0));
//二维动态数组
if(!(Bits=(UINT32**)malloc(sizeof(UINT32*)*dzsize)))
return 0;
if(!(tmparray=(UINT32*)malloc(sizeof(UINT32)*dzsize*dzsize)))
return 0;
ZeroMemory(tmparray,sizeof(UINT32)*dzsize*dzsize);
for(line=0;line<dzsize;++line)
Bits[line]=tmparray+i*dzsize*sizeof(UINT32);
。。。。。。给二维数组赋值 实际是将一个字符的点阵信息赋给这个二维数组,已验证过,二维数组里值正确
// 运行到底下这句时出错:0x7c812a5b 处未处理的异常: Microsoft C++ 异常: 内存位置 0x0012fa90 处的 std::bad_alloc。
SetDIBitsToDevice(hdc,0,0,dzsize,dzsize,0,0,0,dzsize,Bits,lpbmi,DIB_RGB_COLORS);
free(ReadBits);
free(tmparray);
free(Bits);
ReadBits=NULL;
Bits=NULL;
tmparray=NULL;
EndPaint(hwnd,&ps);
return 0 ;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
怎么解决啊 ?救命啦