Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

P.S. - Contents of files are only examples here.

like image 408
faya Avatar asked Nov 28 '25 21:11

faya


1 Answers

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.

like image 61
Bo Persson Avatar answered Dec 01 '25 11:12

Bo Persson