bool CMainDlg: : DrawPicture (const int ip_array_subscript, const char * buf)
{
The RECT rec.
Rec=GetPictureCoordinate (ip_array_subscript);
//GlobalAlloc is a Windows API function, the function from the global heap allocated in a certain number of bytes
//if the function call is successful, it returns a handle to the newly allocated memory object,
HGLOBAL HGLOBAL=GlobalAlloc (GMEM_MOVEABLE, 4096);
//lock memory specified memory block, and return a address values, make it points to the memory block at beginning
Void * pData=https://bbs.csdn.net/topics/GlobalLock (hGlobal);
//memory copy
Memcpy (pData, buf, 4096);
GlobalUnlock (hGlobal);
Cost * pStream=NULL;
//CreateStreamOnHGlobal function from the specified memory to create stream objects,
If (CreateStreamOnHGlobal (hGlobal, TRUE, & amp; PStream)==S_OK)
{
CImage image;
If (SUCCEEDED (image. The Load (pStream)))
{
The RECT the RECT.
GetDlgItem (idc) [ip_array_subscript] - & gt; GetWindowRect (& amp; The rect);
The ScreenToClient (& amp; The rect);
If (the rect left!=rec. Left & amp; & The rect. Top!=rec. Top)
{
GetDlgItem (idc) [ip_array_subscript] - & gt; MoveWindow (rec) left, rec. Top, rec. Right - rec. Left, rec. Bottom - rec. Top, TRUE);
}
CStatic * PIC=(CStatic *) GetDlgItem (idc [ip_array_subscript]);
HBITMAP hold=PIC - & gt; SetBitmap (image);
DeleteObject (hold);
}
PStream - & gt; Release ();
Image. ReleaseGDIPlus ();
Image. The Destroy ();
}
GlobalFree (hGlobal);
return 0;
}
CodePudding user response:
You have done in the create method of memory allocationCodePudding user response:
Didn't see any special leakage, leakage is there any other placeCodePudding user response:
Check the CreateStreamOnHGlobal (hGlobal, TRUE, & amp; PStream) this look