// JP opened flex table

Click to See Complete Forum and Search --> : LPPICTUREDISP -- CPictureHolder --- How to release memory?


srinatvc
April 7th, 2004, 12:10 PM
Hi,

I've been working on an image based application. I'm using VB and VC++ to work with the images. Both are activex controls. I created a property like Get/SetActivePicture(LPPICTUREDISP pPicture). The code is given below.

I'm facing memory problems. Can someone help me how can I release the memory from VC++ after I use the picture object? Thanks in advance .. I can't release the component until I solve this issue. Pls. somebody help me.

The implemenation in VB is like this ...

....
PicEd.Open("C:\Temp.bmp")
set PicEd.ActivePicture = Picture1.Picture
PicEd.RotateBy(90)
set Picture1.Picture = PicEd.ActivePicture()
....


//----------------------------------------------------------------------
//NOTE: m_Pic is of type CPictureHolder
// image is of type CxImage [ a class library found on CodeProject]

void CPicEdCtrl::SetActivePicture(LPPICTUREDISP newValue)
{
// TODO: Add your property handler here
if (newValue == NULL) return;

try
{
HBITMAP hBMP;
HRESULT lResult;

newValue->AddRef ();
m_Pic.SetPictureDispatch(newValue);
newValue->Release();

lResult = m_Pic.m_pPict->get_Handle((OLE_HANDLE FAR *) &hBMP);

//CxImage* image;
image->CreateFromHBITMAP((HBITMAP)hBMP);

}catch (CException e)
{
e.ReportError();
e.Delete();
}
SetModifiedFlag();
}

// ------------ ---------------------- --------------- ------

LPPICTUREDISP CPicEdCtrl::GetActivePicture()
{
// TODO: Add your property handler here
if (image == NULL)
{
m_Pic.CreateEmpty();
goto EndProp;
}

try
{
m_Pic.CreateFromBitmap (image->MakeBitmap(0));

}catch (CException e)
{
//Suppress any exceptions
e.Delete();
m_Pic.CreateEmpty();
}
EndProp:
//return the IPicture dispatch interface
return m_Pic.GetPictureDispatch();
}

//JP added flex table