debugging help!!!

L

Lloyd Dupont

I have a managed class which calls into win32/GDI to do its drawing.
Somehow there is some GDI resource not freed.
Although in my OnPaint I do a try finally, restore the HPEN, HBRUSH, etc..
and then DeleteObject() everything I have created...

I have no idea...
Do you have any tip or do you know of any application (or debugging library)
which could help me see what's going on in the GDI and what's not
deallocated properly?
 
J

Jochen Kalmbach [MVP]

Hi Lloyd!
I have a managed class which calls into win32/GDI to do its drawing.
Somehow there is some GDI resource not freed.
Although in my OnPaint I do a try finally, restore the HPEN, HBRUSH, etc..
and then DeleteObject() everything I have created...

I have no idea...
Do you have any tip or do you know of any application (or debugging library)
which could help me see what's going on in the GDI and what's not
deallocated properly?

You can use the gdileaks.exe tool to see which gdi-handles are leaking..
http://msdn.microsoft.com/msdnmag/issues/03/01/GDILeaks/default.aspx

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
L

Lloyd Dupont

Oops...
big problem with GDILeaks.exe

1. it doesn't compile, with such dangerous looking error as: 'variable i
undeclared'
2. the prebuilb version doesn't run because of missing MFC70.DLL

well I think I will look the web for this DLLs.. but I'm little worry abot
tis sample application...
 
L

Lloyd Dupont

After some testing with GDIUsage.exe (executable in GDILeaks)
I found not unfreed HBITMAP/HPEN/Hxxxx
However...
The total number of GDI object (whatever they could be..) keeps growing....
Maybe there is a leak somewhere in Uniscribe.. going back to the
documentation...
 
L

Lloyd Dupont

Thanks to GDIIndicator prebuild version (as the source code is bugged :-( ),
I found that font.ToHfont() create some (to be released) GDI object....

And, in fact, whild it's not stated in the documentation, if I had look at
the sample code I would have guessed it was necessary!!
 
T

Tamas Demjen

Lloyd said:
1. it doesn't compile, with such dangerous looking error as: 'variable i
undeclared'

I don't think it's bugged. It sounds like the sample code is using
MFC-C++ not standard C++. Microsoft mode != Standard mode. I bet the
code looks like this:

for(int i = 0; i < 1; ++i) ;
for(i = 0; i < 1; ++i) ;

This compiles in MFC-compatible C++ compilers, but it's wrong in
standard C++.

Tom
 
L

Lloyd Dupont

I don't think it's bugged. It sounds like the sample code is using MFC-C++
not standard C++. Microsoft mode != Standard mode. I bet the code looks
like this:

for(int i = 0; i < 1; ++i) ;
for(i = 0; i < 1; ++i) ;

This compiles in MFC-compatible C++ compilers, but it's wrong in standard
C++.
You bet it right.
so the reason it doesn't compile might be because I don't have the right
version of VS, only VS2005 and some setting get losts...
I see thanks.
 
T

Tamas Demjen

Lloyd said:
You bet it right.
so the reason it doesn't compile might be because I don't have the right
version of VS, only VS2005 and some setting get losts...
I see thanks.

OK, so in this case you can switch back to MFC-compatibility mode for
the file in question. In Solution Explorer, right click, Configuration
Properties -> C/C++ -> Language -> Force Conformance In For Loop Scope =
No. (Compiler switch /Zc:forScope-)

Alternatively, declare loop variables outside of the for scope:

int i;
for(i = 0; i < 1; ++i) ;
[...]
for(i = 0; i < 1; ++i) ;

This way it will conform with both the old conventions and the standard.

Tom
 
L

Lloyd Dupont

great, thanks!

Tamas Demjen said:
Lloyd said:
You bet it right.
so the reason it doesn't compile might be because I don't have the right
version of VS, only VS2005 and some setting get losts...
I see thanks.

OK, so in this case you can switch back to MFC-compatibility mode for the
file in question. In Solution Explorer, right click, Configuration
Properties -> C/C++ -> Language -> Force Conformance In For Loop Scope =
No. (Compiler switch /Zc:forScope-)

Alternatively, declare loop variables outside of the for scope:

int i;
for(i = 0; i < 1; ++i) ;
[...]
for(i = 0; i < 1; ++i) ;

This way it will conform with both the old conventions and the standard.

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top