• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 642
  • Last Modified:

BitBlt & EnhMetaFile

Hello,
and again I got a question concernin 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,
dr. nick
0
drnick
Asked:
drnick
  • 3
1 Solution
 
DanRollinsCommented:
There are several places the scenario could go wrong and a narrative description will not shake them loose.  We'll need to see the code... preferrably a complete sequence with just the minumum number of operations to reproduce the leak.

One diagnostic tool:  Start debugging.  Open the Task Manager, and scroll it to display the stopped program.  Under the View menu, set it to display GDI objects nad User Objects.  As you single-step, watch these very carefully.  You might be able to pinpoint where the handle is being allocated and not freed.

-- Dan
0
 
DanRollinsCommented:
And check the return codes of every operation (such as all of the DeleteObject calls) and GetLastError() on failures.
0
 
drnickAuthor Commented:
hi dan,
emf's seem to dislike mine.
however, i found the problem
('cause i asked also in msdn news, since i needed it
quickly).
You are not allowed to use DeleteDC on an emf-dc,
must use CloseEnhMetaFile and DeleteEnhMetaFile.
Thought it returns "properly done" and that's nowhere
written in the msdn.
However, i'm sure you'd also found that problem and 'd've
give me that advise, so i give you the points.
dr.nick
0
 
DanRollinsCommented:
Awfully sporting of you Doc!  And good info for the PAQ database.  Thanks!
-- Dan
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now