Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

BitBlt & EnhMetaFile

67 views
Skip to first unread message

Thomas Weise

unread,
Mar 26, 2003, 10:42:12 AM3/26/03
to
Hello,
and again I got a question concerning the Windows GUI.

I want to do the following:
I have an array of color values for a normal bitmap.
I want this bitmap to be copied into an enhanced meta file.

So first, I create a DC compatible to the Screen,
CreateCompatibleDC(0);
Then I create the DIB-section with CreateDIBSection,
fill in the color values,
and select it into the dc.
Next I create an emf-dc with CreateEnhMetaFile.
Now I do BitBlt the dc to the emf-dc.
Then I unselect the bmitmap from the dc,
deleteobject the bitmap and deletedc the dc.

later, i deletedc the emf-dc (and deleteenhmetafile
the emf-handles i got with closeenhmetafile).

Now my problem: This leads to a memory leak.
Whenever I use this algorithm, i loose about the size
of the bitmap of memory.
if i leave bitblt away, the leak disappeares
(but also the content of the image).
since i'm dealing with big images, there're 200mb ram
thrown out the window whenever it comes to action.
I need help to remove the memory leak.

Can somebody help me with hints what i'm missing
or small example code (c++ or delphi)?
the stuff's direct api, so please no components/mfc.
thanks a lot,

John Hornick [MSFT]

unread,
Mar 26, 2003, 11:08:32 AM3/26/03
to
Hi,


You shouldn't be calling DeleteDC() on an EMF DC. The
CloseEnhMetaFile() and DeleteEnhMetaFile() handle the
EMF cleanup.

If that doesn't help, then look into the following:
1) How do you know you're leaking?
2) Are you leaking GDI object (use Task Manager to see)

Thanks,
- John
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Visit http://www.microsoft.com/security for current information on security.

Thomas Weise

unread,
Mar 27, 2003, 1:00:17 AM3/27/03
to

Thanks, that was it.

CloseEnhMetaFile!

Maybe the guys making msdn could consider,
and that is just a positive idea of myself,
to also explain that in msdn.
There is no hint anywhere stating how to
kill an emf-dc. So DeleteDC was just a logic
decision. Also, someone could include the
really emf-deleting function into deletedc,
since it's return value stated that the dc
IS killed properly. (or it could return false
otherwise).

Thanks, Thomas.
(posting late because of gmt+1h)

Mike D Sutton

unread,
Mar 27, 2003, 4:13:36 AM3/27/03
to
> Maybe the guys making msdn could consider,
> and that is just a positive idea of myself,
> to also explain that in msdn.
> There is no hint anywhere stating how to
> kill an emf-dc. So DeleteDC was just a logic
> decision. Also, someone could include the
> really emf-deleting function into deletedc,
> since it's return value stated that the dc
> IS killed properly. (or it could return false
> otherwise).

DeleteDC() is used in a different manor though. CloseEnhMetaFile() destroys
the DC, but creates a handle to the EMF behind the scenes then passes it
back to you. I do agree though that there should be some mention of the
lifespan of a MetaDC in the docs, I remember hitting the same problem when
working with them myself and only found the answer by going through all the
EMF API calls.

Mike


-- EDais --

- Microsoft Visual Basic MVP -
WWW: Http://www20.brinkster.com/EDais/
Work E-Mail: ED...@btclick.com
Other E-Mail: Mike....@btclick.com


0 new messages