Hey,
can anybody tell me how to access a resource which was added to the compiled exe via AddResource, especially if it is a bitmap picture but not a icon?
(Have tried a million ways with "LoadPicture")
Thanks in advance.
Kind Regards
Rolo
AddResource and how to access it?
Re: AddResource and how to access it?
Code: Select all
% A_ScriptFullPath, # ; Replace # with 6 or higher
Re: AddResource and how to access it?
Thanks for your support, but it do not work.
Cause of the "% " I guessed it would work directly (without a handle) like
Then I tried with
(which I had tried before already)
But all those code only shows the first icon of the exe.
Cause of the "% " I guessed it would work directly (without a handle) like
Code: Select all
Gui, Add, Picture, w500 h-1, % A_ScriptFullPath, 6
Code: Select all
LogoHandle := LoadPicture( A_ScriptFullPath, "6")
But all those code only shows the first icon of the exe.
-
- Posts: 4331
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: AddResource and how to access it?
@Rollo007
Show the code you use to add the resource.
Show the code you use to add the resource.
Re: AddResource and how to access it?
Code: Select all
;@Ahk2Exe-AddResource C:\Program Files\MyApp\Logo.bmp, LOGO1
-
- Posts: 4331
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: AddResource and how to access it?
Try this:
Code: Select all
;@Ahk2Exe-AddResource C:\Program Files\MyApp\Logo.bmp, LOGO1
if !A_IsCompiled
hBitmap := LoadPicture("C:\Program Files\MyApp\Logo.bmp")
else {
hModule := DllCall("GetModuleHandle", "Str", A_ScriptFullPath, "Ptr")
hBitmap := DllCall("LoadImage", "Ptr", hModule, "Str", "LOGO1", "UInt", 0, "Int", 0, "Int", 0, "UInt", 0, "Ptr")
}
Gui, Add, Pic,, HBITMAP: %hBitmap%
Gui, Show
Return
GuiClose:
ExitApp
Re: AddResource and how to access it?
teadrinker wrote: ↑16 May 2021, 10:52Try this:Code: Select all
hModule := DllCall("GetModuleHandle", "Str", A_ScriptFullPath, "Ptr") hBitmap := DllCall("LoadImage", "Ptr", hModule, "Str", "LOGO1", "UInt", 0, "Int", 0, "Int", 0, "UInt", 0, "Ptr")
Thanks so much Teadrinker, it works perfect.
What is about the first answer from Ecimeric? Just bullshit?
-
- Posts: 4331
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: AddResource and how to access it?
Perhaps he just didn't quite understand the question. His answer seems to be about displaying the tray icon.
Re: AddResource and how to access it?
I thought similar fist, but the "6 or higher" makes me wondering.
Do you know a way how to access the bmp if the module is not loaded? (by another compiled script for example)
Do you know a way how to access the bmp if the module is not loaded? (by another compiled script for example)
-
- Posts: 4331
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: AddResource and how to access it?
Code: Select all
modulePath := "D:\CompiledScriptPath.exe"
resourceName := "LOGO1"
hLib := DllCall("LoadLibraryEx", "Str", modulePath, "Ptr", 0, "UInt", LOAD_LIBRARY_AS_IMAGE_RESOURCE := 0x20, "Ptr")
hBitmap := DllCall("LoadImage", "Ptr", hLib, "Str", resourceName, "UInt", 0, "Int", 0, "Int", 0, "UInt", 0, "Ptr")
DllCall("FreeLibrary", "Ptr", hLib)
Gui, Add, Pic,, HBITMAP: %hBitmap%
Gui, Show
Return
GuiClose:
ExitApp
Re: AddResource and how to access it?
You are FANTASTIC !!
Thanks so much.
Thanks so much.
Re: AddResource and how to access it?
I guess it would be necessary to add a
after the LoadImage.
What do you think?
Code: Select all
DllCall("FreeLibrary", "Ptr", hModule)
What do you think?
-
- Posts: 4331
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: AddResource and how to access it?
Nope.
GetModuleHandle wrote:The GetModuleHandle function returns a handle to a mapped module without incrementing its reference count. However, if this handle is passed to the FreeLibrary function, the reference count of the mapped module will be decremented. Therefore, do not pass a handle returned by GetModuleHandle to the FreeLibrary function.
-
- Posts: 4331
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: AddResource and how to access it?
However, GetModuleHandle can be called like this:
Code: Select all
hModule := DllCall("GetModuleHandle", "Ptr", 0, "Ptr")
Re: AddResource and how to access it?
Missunderstanding. I wrote this regarding the LoadLibraryEx function
-
- Posts: 4331
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: AddResource and how to access it?
Do you understand now?
Re: AddResource and how to access it?
Ha ha nooo -it was not a misunderstanding by me.
The misunderstanding was that you thought I mentioned FreeLibrary regarding GetModuleHandle,
BUT I wrote it regarding the LoadLibraryEx function.
And the LoadLibraryEx do incrementing the reference counter.
So it is necessary to call a FreeLibrary after loading the pic.
Or am i wrong?
The misunderstanding was that you thought I mentioned FreeLibrary regarding GetModuleHandle,
BUT I wrote it regarding the LoadLibraryEx function.
And the LoadLibraryEx do incrementing the reference counter.
So it is necessary to call a FreeLibrary after loading the pic.
Or am i wrong?
-
- Posts: 4331
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: AddResource and how to access it?
But after calling LoadLibraryEx I do call FreeLibrary with the handle which LoadLibraryEx returns (hLib):
Code: Select all
hLib := DllCall("LoadLibraryEx", "Str", modulePath, "Ptr", 0, "UInt", LOAD_LIBRARY_AS_IMAGE_RESOURCE := 0x20, "Ptr")
hBitmap := DllCall("LoadImage", "Ptr", hLib, "Str", resourceName, "UInt", 0, "Int", 0, "Int", 0, "UInt", 0, "Ptr")
DllCall("FreeLibrary", "Ptr", hLib)
Re: AddResource and how to access it?
OMG
Unbelievable, but I've just overlooked this.
Okay, your code were perfect.
Just one more question:
I tried to free the image like
but it do not work. (e = 0)
Unbelievable, but I've just overlooked this.
Okay, your code were perfect.
Just one more question:
I tried to free the image like
Code: Select all
e:= DllCall("DeleteObject", "Ptr", hLogo)
-
- Posts: 4331
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: AddResource and how to access it?
If your hLogo is the same as my hBitmap, you don't need to free it explicitly, it will be automatically deleted after the control is destroyed.