简体   繁体   中英

MFC static library and external rc(resource) file icon loading problem

I have a problem with loading icons from external resource files in main application. I'll try to explain how application is set right now. The resources of the main application includes external dialog *.rc and appropriate *.h. And linker includes dialog implementation (CDialog/CFormView) which resides in external static library *.lib.

External *.rc has:

IDI_MY_ICON ICON "my_icon.ico"

External *.h has:

#define IDI_MY_ICON 10000

Dialog implementation in static lib *.cpp has:

HICON MyDialog::GetNeededIcon()
{
  return AfxGetApp()->LoadIcon(IDI_MY_ICON);
}

I thought that it should reside in the same folder as external *.rc file is. I also tried to place them in the main app folder, but application still doesn't load them. Could someone explain me where my_icon.ico is searched in?

PS - Contents of files are only examples here.

AfxGetApp()->LoadIcon(IDI_MY_ICON); tries to load the icon from the current app (exe).

If you want to load it from another module, you will either have to remember the handle returned from LoadLibrary, or call GetModuleHandle to retrieve it again.

Your .rc file is compiled by rc.exe to embed the icon in your executable. rc.exe uses the include path to find the resources. This is specified by either the INCLUDE environment variable or by using /I option to rc.exe. If "my_icon.ico" doesn't work, try moving the file or change the include path.

Clarification:

rc.exe compiles .rc files into .res, but its the linker that does the actual embedding into the executable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM