Solved

Is Multiple LoadIcon() safe ?

Posted on 1998-08-22
5
383 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

911 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

25 Experts available now in Live!

Get 1:1 Help Now