Board index » cppbuilder » How to load an icon in a DLL

How to load an icon in a DLL


2004-01-13 04:53:14 PM
cppbuilder26
Hi,
I have a DLL, that I compile with a resource (.res) file containing an icon.
How can I get access to this icon fromwithin the DLL?
I have tried this
Graphics::TIcon *Icon = new Graphics::TIcon;
Icon->Handle = LoadIcon(HInstance, "Icon1");
where "Icon1" is the name of the icon in the resource.
However, the Handle is always NULL,
I can load "system" icons by
Icon->Handle = LoadIcon(HInstance, IDI_ASTERISK);
I guess the problem has to do with the HInstance parameter?
/totte
 
 

Re:How to load an icon in a DLL

"Totte Karlsson" < XXXX@XXXXX.COM >wrote in message
Quote
Icon->Handle = LoadIcon(HInstance, "Icon1");
You need to specify the HINSTANCE that belongs to the DLL itself. You are
trying to use the application's HINSTANCE instance, which will only work for
resources that are in the EXE file itself.
Gambit
 

Re:How to load an icon in a DLL

Yeah, I assumed it had to do with something like that. I get the HINSTANCE
of the DLL, from "outside" (LoadLibrary()) when I load it, but how can I get
it from "inside" the DLL?
Is it OK to add a function to hand it to the DLL from outside (just after
it's loaded)? Or is there a simpler way?
/tk
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Totte Karlsson" < XXXX@XXXXX.COM >wrote in message
news:4003b250$ XXXX@XXXXX.COM ...

>Icon->Handle = LoadIcon(HInstance, "Icon1");

You need to specify the HINSTANCE that belongs to the DLL itself. You are
trying to use the application's HINSTANCE instance, which will only work
for
resources that are in the EXE file itself.


Gambit


 

{smallsort}

Re:How to load an icon in a DLL

"TotteKarlsson" < XXXX@XXXXX.COM >wrote in message
Quote
Yeah, I assumed it had to do with something like that. I get
the HINSTANCE of the DLL, from "outside" (LoadLibrary())
when I load it, but how can I get it from "inside" the DLL?
The DLL's HINSTANCE is passed to it as a parameter to its exported
DllEntryPoint() function. It is your own responsibility to store that
handle if you need to use it later.
Gambit