Click here to Skip to main content
16,011,849 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralProblems with hooking events!! HELP !! Pin
TomK26-Feb-01 21:16
TomK26-Feb-01 21:16 
QuestionHow to make a deque from scratch in C++ Pin
Theo26-Feb-01 15:53
Theo26-Feb-01 15:53 
AnswerRe: How to make a deque from scratch in C++ Pin
l a u r e n26-Feb-01 21:29
l a u r e n26-Feb-01 21:29 
QuestionHow to resize the DataGrid columns ! Pin
26-Feb-01 12:23
suss26-Feb-01 12:23 
GeneralCPen leaking memory - ARGH !!!! Pin
Christian Graus26-Feb-01 12:13
protectorChristian Graus26-Feb-01 12:13 
GeneralRe: CPen leaking memory - ARGH !!!! Pin
Todd Wilson26-Feb-01 12:59
Todd Wilson26-Feb-01 12:59 
GeneralRe: CPen leaking memory - ARGH !!!! Pin
26-Feb-01 13:07
suss26-Feb-01 13:07 
GeneralRe: CPen leaking memory - ARGH !!!! Pin
Todd Wilson26-Feb-01 13:25
Todd Wilson26-Feb-01 13:25 
Heck it doesn't remember it under IE55 either.

I think I spotted your problem; it's in the loop:

for (int i=0;i<500;i++)
{
CPen pen;
pen.CreatePen(PS_SOLID, 1, RGB(0,0,0));
dc.SafeSelect(&pen);
/* Okay, here is the problem as I see it: the first time this is called, there is no pen to release, so the pen handle is selected into the device context, which basically takes ownership of it. Then your loop exits, and the CPen object is destroyed, taking the handle with it - but more than likly just a COPY of the handle, leaving the other one still selected into the device context, since it was never selected out. Then the 2nd time into the loop you create a new CPen, and then select it in, but you never got rid of the other one. */
}

I've never written code like this; I've always done it like, the scope of the function:
CPen *pOldPen = dc.SelectObject(&pen);
...dowhatever....
dc.SelectObject(pOldPen);

If I was going to attempt to re-write the SafeSelect, I would probably NOT do it like this (IMHO), but instead, make a helper class (or nested class) that does the need balanced SelectObject's on construct and destruct.
GeneralRe: CPen leaking memory - ARGH !!!! Pin
26-Feb-01 13:58
suss26-Feb-01 13:58 
GeneralRe: CPen leaking memory - ARGH !!!! Pin
Erik Funkenbusch26-Feb-01 13:40
Erik Funkenbusch26-Feb-01 13:40 
GeneralCDialog and dll Pin
Mel Stober26-Feb-01 12:10
Mel Stober26-Feb-01 12:10 
GeneralProblem displaying arbitrary Solid Brushs between machines Pin
Michael A Barnhart26-Feb-01 6:27
Michael A Barnhart26-Feb-01 6:27 
GeneralRe: Problem displaying arbitrary Solid Brushs between machines Pin
l a u r e n26-Feb-01 10:29
l a u r e n26-Feb-01 10:29 
GeneralRe: Problem displaying arbitrary Solid Brushs between machines Pin
Michael A Barnhart28-Feb-01 2:09
Michael A Barnhart28-Feb-01 2:09 
GeneralRe: Processes Pin
l a u r e n26-Feb-01 6:08
l a u r e n26-Feb-01 6:08 
GeneralRe: Processes Pin
l a u r e n27-Feb-01 1:02
l a u r e n27-Feb-01 1:02 
GeneralRe: Processes Pin
28-Feb-01 1:55
suss28-Feb-01 1:55 
GeneralUnique system id Pin
26-Feb-01 5:03
suss26-Feb-01 5:03 
GeneralStarting an App.Exe at Bootup time using NT Service Pin
trilok_soni26-Feb-01 2:34
trilok_soni26-Feb-01 2:34 
QuestionODBC drivers? Pin
Kannan26-Feb-01 0:52
Kannan26-Feb-01 0:52 
GeneralString table Pin
26-Feb-01 0:02
suss26-Feb-01 0:02 
GeneralRe: String table Pin
Tim Deveaux26-Feb-01 4:32
Tim Deveaux26-Feb-01 4:32 
QuestionWindows Installer's DLL's? Pin
AlexMarbus25-Feb-01 23:17
AlexMarbus25-Feb-01 23:17 
AnswerRe: Windows Installer's DLL's? Pin
Tim Deveaux26-Feb-01 5:22
Tim Deveaux26-Feb-01 5:22 
GeneralProblems with hooking events!! Pin
TomK25-Feb-01 22:24
TomK25-Feb-01 22:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.