AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Crazy Scripting : Create ResourceOnly DLL (ICON+BITMAP+RCD)
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
SKAN



Joined: 26 Dec 2005
Posts: 5816

PostPosted: Sat Mar 29, 2008 6:58 pm    Post subject: Crazy Scripting : Create ResourceOnly DLL (ICON+BITMAP+RCD) Reply with quote



Edit: The previous < 45 line code is here: ROD-45L.ahk


Last edited by SKAN on Fri May 23, 2008 4:51 pm; edited 2 times in total
Back to top
View user's profile Send private message
interiot



Joined: 06 Nov 2005
Posts: 64

PostPosted: Sat Mar 29, 2008 7:36 pm    Post subject: Reply with quote

Pish, a real hacker would have done it without creating a temporary file. Just kidding, very impressive. Razz

(on the serious side... can we have something like MemoryLoadLibrary() built-in to AHK?)
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5816

PostPosted: Sat Mar 29, 2008 9:35 pm    Post subject: Reply with quote

interiot wrote:
a real hacker would have done it without creating a temporary file


That is not a temporary, but the resultant file. I do not see any meaning in creating a resource file in memory and not write it back to disk.
For record: empty.dll ( 2560 bytes ) was created in RosAsm ( only DllMain ) with ASM source stripped off to save some bytes. Have avoided the dependency by including the DLL as a compressed 1480 byte function.
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2542
Location: Australia, Qld

PostPosted: Mon Apr 07, 2008 8:59 am    Post subject: Reply with quote

Do you plan to develop this any further? Smile

A few things I have learned:
  • Named resources aren't worth the trouble:
    • UpdateResource will succeed with lower-case resource names, but you can't reference the resources unless the names are upper-case. (Names seem to be case-insensitive when referencing existing resources.)
    • UpdateResource seems to clip the last character of the resource name. Consistently on XP and Vista, if I pass "NAME", it uses "NAM", so I instead pass "NAME." expecting the "." to be discarded. (I hope I am doing something wrong, but that seems unlikely given that the lpName parameter is a simple null-terminated string.)
  • Internet Explorer controls and ShowHtmlDialog seem able to read images regardless of the resource type. I've tried bmp, png, jpg and gif, with success.
  • Bitmap resources (RT_BITMAP=2) are in the same format as .bmp files, excluding the BITMAPFILEHEADER. In other words, discard the first 14 bytes.
  • Icon resources are a little trickier. Icons in Win32 explains the ICO format in addition to the RT_GROUP_ICON and RT_ICON resource formats.

I also have a custom build of Ahk2Exe which allows a custom bin file to be specified on the command line. I'll upload it if you're interested. (UpdateResource may be applied to AutoHotkeySC.bin the same way it is applied to a resource DLL.)
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5816

PostPosted: Mon Apr 07, 2008 2:17 pm    Post subject: Reply with quote

Quote:
A few things I have learned:


Highly resourceful. Thanks. Most of my success with resources came with brute-force methods.

Lexikos wrote:
Do you plan to develop this any further? Smile


I had wished as follows:

Quote:
Dear Mr.Chris,

This is my Wish.

I request a change in behaviour of ahk2exe.exe :
Within Windows Explorer, when I select Compile Script from the context menu, if AutoHotkeySC.bin exists on the same folder as the script, then that version should be used for compilation.

This is to facilitate multiple projects that require seperate internal resources.

Thanks.


I am thinking in following lines:
The user will have to code the script with resource building in the begining part:

Code:
Resource_BeginUpdate( params )

.. one command for each resource

Resource_EndUpdate()


resource.ahk will be the standard library that should take care of :

    1) either creating a empty resource.dll in a_scriptdir
    or copy autohotkeysc.bin to a_scriptdir
    2) add / modify / delete resources as user specification
    3) create a project.ini in a_scriptdir so that these lib functions do not get triggered on every run ( Resource_BeginUpdate() would hash check the source files to see if an update is required )
    4) the project.ini or ( whatever name ) would also be stored as RCDATA resource.
    5) there should be no dllcalls for the user ( atleast for the data retrieval part ) .. but only resource_*() functions that would help to fetch data with single line.
    6) the user would not be dealing with any numbers.. but only filenames and or aliases. the library would take care of assigning numbers
    7) the above would be made possible because resource_*() functions would be referring project.ini stored inside the PE


support for minimum: ICON,BITMAP,VERSION,RCDATA.

What I wonder is:
How to delete the lines between ( and including ) Resource_BeginUpdate() / Resource_EndUpdate() before the script is passed to ahk2exe ?
Resource_BeginUpdate() could check A_IsCompiled and play dead.. but still it will be unneccessary code inside a compiled script.
maybe a new directive that would automatically comment out / ignore a block of commands ( only if A_IsCompiled is true )

Quote:
I also have a custom build of Ahk2Exe which allows a custom bin file to be specified on the command line. I'll upload it if you're interested.


sure ... sure.

Quote:
(UpdateResource may be applied to AutoHotkeySC.bin the same way it is applied to a resource DLL.)


I am aware of.. but
1) I do not compile my scripts. 2) It did not interest me much because my wish was not considered..
but I am very much interested now, because you can make things happen. Smile
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2542
Location: Australia, Qld

PostPosted: Tue Apr 08, 2008 3:01 am    Post subject: Reply with quote

Ahk2Exe_L.zip
Ahk2Exe_L_src.zip
It should be put in the Compiler directory to support function libraries, but you may rename it to coexist with the original Ahk2Exe.
SKAN wrote:
What I wonder is:
How to delete the lines between ( and including ) Resource_BeginUpdate() / Resource_EndUpdate() before the script is passed to ahk2exe ?
Why not use a separate resource script?
Quote:
maybe a new directive that would automatically comment out / ignore a block of commands ( only if A_IsCompiled is true )
That could be done with pre-processing. See for example AHK preprocessor.
Quote:
I do not compile my scripts.
Nor do I, which is why I put a higher priority on finishing my other projects.

I also realised it is possible to extract FileInstall'd files; AutoHotkey itself may simply call FileExtractToMem, which is normally only used to load the script. I think it seems more appropriate to natively support "resources" embedded using FileInstall.

On the other hand, native support for PE resources (perhaps similar to the res protocol) could be used by compiled or uncompiled scripts, with resource DLLs, script-embedded resources or both.

There would probably be a lot of code overlap, so it would be worth supporting both.
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5816

PostPosted: Wed Apr 09, 2008 8:14 pm    Post subject: Reply with quote

Lexikos wrote:
Ahk2Exe_L.zip
Ahk2Exe_L_src.zip


Thanks Lexikos. Very Happy

I will reply after trying it out, but may I know the parameter, please.

Smile

Edit: Oh! Okay.. it is in readme.txt along with source.
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5816

PostPosted: Fri May 23, 2008 4:56 pm    Post subject: Reply with quote

Dear Lexikos, Smile

Earlier I wrote:
I will reply after trying it out


I am still interested!.. though I have to learn/work a lot more ..
Thanks for the tip on RT_BITMAP. I have implemented it and also RT_ICON/RT_GROUP_ICON

The title post has been updated.

Regards, Smile
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2542
Location: Australia, Qld

PostPosted: Sat May 24, 2008 12:47 am    Post subject: Reply with quote

Be warned that my custom build of Ahk2Exe does not support the /NoDecompile option. As far as I can tell, it is not implemented in the downloadable Ahk2Exe source. Confused
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5816

PostPosted: Sat May 24, 2008 1:33 am    Post subject: Reply with quote

OH!.. Shocked

I can somewhat understand the concern of Mr.Chris

Did you try my script Lexikos ?

I need some info. I found how to obtain hFont from raw TTF bytestream. It works fine with WM_SETFONT on AHK control.

You have already shown how to refer images from HTML .. but how to use an embedded font .. i.e., use it from HTML ?

I did not try, but my best guess is that WM_SETFONT would not work on an IE control. Rolling Eyes

Smile
Back to top
View user's profile Send private message
n-l-i-d
Guest





PostPosted: Sat May 24, 2008 8:28 am    Post subject: Reply with quote

Did you try font embedding with the res-protocol yet?
Back to top
heresy



Joined: 11 Mar 2008
Posts: 269

PostPosted: Sat May 24, 2008 8:58 am    Post subject: Reply with quote

you've done it finally !
i didn't tried it yet but i believe that i'll need it someday when i making gui scripts for public
though it's resource only, non-programmers can make dlls now.
how sweet it is Smile thanks for sharing SKAN!
_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5816

PostPosted: Sun May 25, 2008 2:08 pm    Post subject: Reply with quote

n-l-i-d wrote:
Did you try font embedding with the res-protocol yet?


er.. can you repeat the link, please.

heresy wrote:
i didn't tried it yet but i believe that i'll need it someday when i making gui scripts for public


Right now IconEx deals only with resource-icons.., I need to make it read .ICO files too. When done, this script would be built into IconEx

Smile
Back to top
View user's profile Send private message
n-l-i-d
Guest





PostPosted: Sun May 25, 2008 4:35 pm    Post subject: Reply with quote

.eot/WEFT (embedded open type), and res protocol (don't know if this works)
Back to top
ladiko



Joined: 14 Jul 2006
Posts: 190
Location: Berlin

PostPosted: Sun May 25, 2008 5:11 pm    Post subject: Reply with quote

could i use your work in compile_ahk to manual add resources to a script when it is compiled? a reference to you in the credits would be obvious Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group