?
Solved

BitBlt & EnhMetaFile

Posted on 2003-03-26
4
Medium Priority
?
630 Views
Last Modified: 2013-12-03
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
Comment
Question by:drnick
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 8214382
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
 
LVL 49

Accepted Solution

by:
DanRollins earned 500 total points
ID: 8214394
And check the return codes of every operation (such as all of the DeleteObject calls) and GetLastError() on failures.
0
 
LVL 5

Author Comment

by:drnick
ID: 8215789
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 8215868
Awfully sporting of you Doc!  And good info for the PAQ database.  Thanks!
-- Dan
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question