|
Can you give me any advice on tracking GDI resource leaks ? My application leaks quite badly! I have dealt with the HICON issue now, creating in OnCreate and destroying in OnDestroy(). I was also using a class called CSXButton which leaks pretty badly too, so i've removed all traces of that and am now using just a CButton with icons. I also did use some text drawing functions on a splash screen which had leaks, but i resolved that by freeing my CFonts before changing them and started to use dc.save and dc.restore. I don't believe i am using any other gdi functions, but i am using several control classes sourced from codeguru and from here that may be leaking. How can i trace the source of the leak ? Please don't suggest a third party product that i have to pay for ... i want to become familar with some methods to track these problems myself.
Jase
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
View your digital photos and images with ease using the ultimate desktop image manager for Microsoft Windows
Download your free copy of SlideShow Desktop today from http://www.slideshowdesktop.com
|
|
|
|
|
It is easy to forget (I forget quite often ), but you just have to make sure that everytime you load or create a resource you delete it when you are finished with it. If you look in MSDN at the functions that load/create a resource, there will be info on the function that is needed to delete it.
for example, if you load a cursor with the ::LoadImage() function, you have to remove it with the ::DestroyCursor() function.
The way I find leaks is to read the source code, and lots of trial and error, sorry I don't have a quick fix for you, but c'ést la vie.
---
Blessed are those who can laugh at themselves, for they shall never cease to be amused
|
|
|
|
|
Well, as the other guy mentioned, you always need to free everything you allocate. So, tracking resource usage at its simplest is mental; remember all the resources loaded by a class & make sure they're released before the class is destroyed, either by an OnDestroy() message handler (for a window class) or by the class destructor. If you've a lot of resources to keep track of, consider creating a separate manager class to deal with allocating and releasing them.
And now, i'm going to contradict myself ... Looking at the example given in your original post, one easy solution suggests itself: use the LR_SHARED option in your call to LoadImage(). Unless you have multiple resources with the same ID, this will allow you to put the responsibility of managing these icons back on Windows. No need to free them, no need to worry about loading the same resource multiple times.
As for more advanced tools... I guess if you're using Win2000, you could watch the USER objects / GDI objects columns in the task manager over time... If you change your mind on commercial products, i'll recommend the one i use from time to time.
|
|
|
|
|
Hi,
Thanks for your reply. So tell me then, which commercial product do you use and is there an evaluation version ?
Jase
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
View your digital photos and images with ease using the ultimate desktop image manager for Microsoft Windows
Download your free copy of SlideShow Desktop today from http://www.slideshowdesktop.com
|
|
|
|
|
NuMega BoundsChecker; http://www.numega.com
They do provide an evaluation version, though not as a direct download. Definately worth a try, as is their TrueTime profiling app.
|
|
|
|
|
Hi
I need to write a dll in VC++6 that can be used in delphi
What kind of dll should I use?
regards
|
|
|
|
|
It must be a regular DLL (it cannot be an extension DLL).
You *can* use MFC in the DLL as long as you don't try to export any MFC classes. It may also be a good idea to choose to link MFC statically.
You must provide export functions, and I think you may even need a def file but I'm not sure on that.
The best way to find out what you need (beyond the requirement to be a regular DLL), is to write a small DLL with one exported function, and make that work first.
To hell with those thin-skinned pillow-biters. - Me, 10/03/2001
|
|
|
|
|
It does depend on what you want delphi to access. If you are just exporting straight C functions like the Windows API does, then a regular DLL will do just fine. You are limited to exporting just C Datatypes so you can't pass in and out things like CString.
If you wanted to communicate via objects then you have to go the COM root. ATL simplifies this, but COM isn't for the faint-hearted (A least not at the start)
MFC DLL's are a non-started with Delphi, so you either have to use a regular C DLL or create a COM object.
Michael
|
|
|
|
|
Thank you !
I need objects as CDialog in it and I'm faint-hearted and beginner.
So what do you say on my idea :
1. make extension DLL
2. after make a regular dll that import in own the extention DLL
3. provide the last dll(that use in the first dll);)
Is it not a good idea ?
|
|
|
|
|
Is dll that good for delphi will match to every another language ?
|
|
|
|
|
It depends, you might have trouble using it with COBOL for instance . You'd be able to use it in VB though as well if you wanted and the .NET languages.
--
Andrew.
|
|
|
|
|
1. What you mean : .NET languages ?
2. Is the Idea that Anonymous suggest good ?
|
|
|
|
|
1 - .NET languages - you know, the new set programming idiom from Microsoft (C#, Managed C++ [not actually a language in itself, but an extension to one], ASP.NET etc?).
2 - What John and Matt said is perfectly correct - I would suggest doing a regular DLL. If you need to access a CDialog class then do a regular DLL which itself uses the extension DLL. This should work. You will have to make the regular DLL link with MFC but it CAN'T be an extension DLL itself to work with Delphi/VB.
If you need objects to be exported (i.e. providing an API for an extension DLL isn't enough) then the only solution is to use COM. I can't give you any Pascal examples 'cause I don't use Delphi.
If you want quicker responses then register and post through a proper account 'cause then we get notified when you reply to our messages, as Christian will tell you .
--
Andrew.
|
|
|
|
|
* "If you need to access a CDialog class then do a regular DLL which itself uses the extension DLL. " -
and this way dont good for delphi and another ??? Why ???
* "to use COM" -
Are you mean to ATL ?
|
|
|
|
|
|
Chill out, everyones questions are 'urgent'
ATL is a template library that simplifies creation of COM objects. I have a feeling I've answered this question several times by advising you that COM objects will not create themselves for you via a wizard and you need to go buy some books and learn some ATL if you want to do what you're intending. My advice on this front stands - I'm sure others as well as myself would be glad to keep helping, but you are *not* going to learn ATL from a post like this, you're going to learn it by reading a book and doing the examples in it. Richard Grimes books are good, the 'teach yourself in 24 hours' book is a better start if you're not confident or you get lost ( I resorted to it before going back to the Grimes book )
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
I second Christian's comments. I would recommend a book like "Inside COM" (from microsoft press at http://www.microsoft.com/mspress/) or "Professional DCOM Programming" by Richard Grimes, Wrox Press (http://www.wrox.co.uk/).
These should easily get you started. I know that Grimes was my bible during a big project no too long ago.
Sincerely Yours,
Brian Hart
"And that's the news from Lake Wobegon, where all the women are strong, the men are good-looking, and the children are above-average." - Garrison Keillor
|
|
|
|
|
I must it urgent , So I need book that teach quickly and clearly.
It seems that what I need is the book :
'teach yourself in 24 hours' is about ATL in fact ?
Who is the author ?
|
|
|
|
|
The book 'Teach yourself ATL in 24 hours' appears to be out of print, Fatbrain is not listing it. I would recommend
Creating Lightweight Components with Atl with Cdrom
By Jonathan Bates,Brad Jones,Matt Purcell ISBN: 0672315351
as a book more accessible than the Grimes books and which helped me enormously when I was trying to wrap my head around it all.
By all means ask questions if you get stuck.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Wierd - a search for teach 24 did not list this book at Fatbrain, neither did ATL 24. But it's there - ISBN: 0672318679
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Are you sure that I cant manage if I will do regular dll that use in extention dll ?
|
|
|
|
|
Bloody hell. Look, I don't know much about regular/extension dll's, but it seems obvious to me that given the whole idea of COM is language agnostic code, that it's the way to do what you want. You clearly know that yourself, you've been asking the same sort of questions for two weeks now and getting roughly the same answers.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
|
I have a settings dialog in my application.
In mIRC and Winamp they have a configuration file which has headings:
[Winamp]
visplugin_name=vis_avs.dll
visplugin_num=0
[WinampMini]
blah=0
etc etc
I want this in my program where when a user fills in an edit control it will save the string in the configuration file i specify like this
[SNEToptions]
Username=Ashman
Password=blah
Email=ashman@settlers.net
[SNETappearance]
Icon=4
Splash=No
and everytime I go into the Settings dialog, it will load up in each edit control or control each preference, like the Username edit box will say Ashman, the password will say blah etc etc....
If someone can help, or point me to a sample, Id appreciate it very much!
Thanks
Ashley 'Ashman' Rowe
www.settlers.net
|
|
|
|
|
You would load the information in the "OnInitDialog()" using:
DWORD GetPrivateProfileString(
LPCTSTR lpAppName, // points to section name
LPCTSTR lpKeyName, // points to key name
LPCTSTR lpDefault, // points to default string
LPTSTR lpReturnedString, // points to destination buffer
DWORD nSize, // size of destination buffer
LPCTSTR lpFileName // points to initialization filename
);
and write it using:
BOOL WritePrivateProfileString(
LPCTSTR lpAppName, // pointer to section name
LPCTSTR lpKeyName, // pointer to key name
LPCTSTR lpString, // pointer to string to add
LPCTSTR lpFileName // pointer to initialization filename
);
Once you get the information, use "GetDlgItem(IDC_EDIT...)->SetWindowText(Your-CString)".
Hopes this helps!
Thanks in advance,
Dan
|
|
|
|