Problem with Metafile Functions

Problem with Metafile Functions

Problem with Metafile Functions

I have been using Metafile Functions to create several pictures. I have been showing those pictures in a dialog box.

To creat the pictures I have used the functions:

hdcEMF = CreateEnhMetaFile(Null,TRIM &(szTitleName)//'.emf'C,Null,"MetaSketchEMF ")
hemf = CloseEnhMetaFile (hdcEMF)
bret = DeleteEnhMetaFile (hemf)

To show the pictures I have used the following functions:

hEmf = GetEnhMetaFile(szTitleName)
ret = SendMessage(GetDlgItem(hdlg, IDC_GraficoEMF), & STM_SETIMAGE, IMAGE_ENHMETAFILE,hEmf(IncTempo))
lret = DeleteEnhMetaFile (hemf)

The problem happen during the program execution. When the picture is created or shown, it occur the drastic decrease of the available system memory. After that, the functions fails. Is there any way to avoid this kind of problem. How can I increase or maintain constant the system memory during the program execution ?

Thanks,

Fau.

2 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Bild des Benutzers Jugoslav Dujic

I'd guess you have a GDI memory leak within your metafile. Strange, ha? To verify that, get a "clean" metafile (exported from Corel or a similar program) and set it into the static control. Does it leak now?

Remember that a metafile is just a journal of calls to GDI functions you do on hdcEMF (CreateSolidBrush, Rectangle, SetMapMode etc.). When a metafile is attached to a static control, it just repeats the same set of calls every time the control should be redrawn. If, however, you failed to clean up properly, you'll have a memory leak each time the control is redrawn. I guess you violated the "1st Law of GDI Programming":

Every GDI object you create using CreateXXX must be deselected and deleted using DeleteObject when no longer needed.

You may want to check out my XFTGDI module, which does most of tedious Create/Select/Delete job for you automatically. It comes with a sample working with metafiles.

HTH
Jugoslav

Jugoslav www.xeffort.com

Melden Sie sich an, um einen Kommentar zu hinterlassen.