Solved

Is Multiple LoadIcon() safe ?

Posted on 1998-08-22
5
380 Views
Last Modified: 2013-12-03
Dear experts

I'm using VC++5.0 SP3 on WIndows NT 4.0 SP3.
In my app, I'd like to use LoadIcon() several times
for a button control in a DialogBar to notice user the situaltion is changed.
But I'm afraid that if I use LoadIcon() for a Button Control, there may take place resourse leak or memory leak...
Is it safe to using LoadIcon() multiple times for a Button Control ?

Any comments will be appreciated.
0
Comment
Question by:okg
5 Comments
 
LVL 11

Expert Comment

by:alexo
ID: 1413814
I think so.  LoadIcon() behaves similarly to the more generic LoadResource().
Here's what the documentation of LoadResource() says:

"Both Windows 95 and Windows NT automatically free resources. You do not need to call the FreeResource function to free a resource loaded by using the LoadResource function."

So, no leaks.

0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 100 total points
ID: 1413815
 Function Load Icon

HICON LoadIcon(hinst, pszIcon)

HINSTANCE hinst;      /* handle of application instance      */
LPCSTR pszIcon;      /* icon-name string or icon resource identifier      */

The LoadIcon function loads the specified icon resource
from the executable file associated with the given
application instance.

This function loads the icon resource only
if it has not been loaded; otherwise, it retrieves a handle
of the existing resource.

An application can use the LoadIcon function to access
the predefined icons used by Windows.
To do this, the application must set the hinst parameter
to NULL and the pszIcon parameter to one of the following values:

Value      Meaning

IDI_APPLICATION      Default application icon.
IDI_ASTERISK      Asterisk (used in informative messages).
IDI_EXCLAMATION      Exclamation point (used in warning messages).
IDI_HAND      Hand-shaped icon (used in serious warning messages).
IDI_QUESTION      Question mark (used in prompting messages).

It is not necessary to destroy these system icons.
But an application should use the DestroyIcon function
to destroy any private icons it loads.

If you use LoadIcon and  DestroyIcon , it is very save!

0
 
LVL 23

Expert Comment

by:chensu
ID: 1413816
I agree with alexo.

"It is only necessary to call DestroyIcon for icons and cursors created with the CreateIconIndirect function."
0
 

Author Comment

by:okg
ID: 1413817
Thanks a lot.

I'm using LoadIcon() for custom Icon. i.e. I drew it.
No leak anyway ?
0
 
LVL 11

Expert Comment

by:alexo
ID: 1413818
None.  Don't worry.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now