[讨论]有关开辟内存的源程序
我是在DLL中绘制一条直线,然后开辟了一块儿内存(BMP_W*BMP_H)保存它
void CGriphic::BMP_Line( CDC* pDC,
unsigned char* return_buffer,
BYTE BMP_W,
int BMP_H)
{
HWND hwnd=GetForegroundWindow();
BYTE* pmem = (BYTE*)GlobalLock(hwnd);
CPen pen;
pen.CreatePen(PS_SOLID,10,RGB(255,0,0));
CPen *oldpen;
oldpen=pDC->SelectObject(&pen);
pDC->MoveTo(100,100);
pDC->LineTo(200,200);
pDC->SelectObject(oldpen);
GlobalUnlock(hwnd);
HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED,BMP_W*BMP_H);
return_buff = (unsigned char*)GlobalLock(m_hMem);
memcpy(return_buff,pmem,BMP_W*BMP_H);
GlobalUnlock(m_hMem);
}
大家给我提提意见啊,马上要交了
还有,有没有好的办法验证开辟内存是否成功,谢谢大家了