Upcoming Ahk2Exe changes

Community news and information about new or upcoming versions of AutoHotkey
User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Upcoming Ahk2Exe changes

18 Jul 2015, 12:36

The FileInstall that is never executed is just an old trick. you no longer to use that because of the directives :)
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Upcoming Ahk2Exe changes

18 Jul 2015, 21:22

2. Do i still need to use ;@Ahk2Exe-AddResource SNAP.wav ?
No.
3. Should the function call "PlaySound ( Sound)" be used to play the sound instead of "SoundPlay" ?
Yes.
4. Shouldn't "FileInstall, SNAP.wav, - " be in the autoexec section at the top of my code along with "ResRead( Sound, "SNAP.wav" )" ?
No. If you put into autoexec section, then the file will be extracted.
If you want to put in autoexec section, use this instead:

Code: Select all

If !A_IsCompiled
    FileInstall, SNAP.wav, -
Skrell
Posts: 302
Joined: 23 Jan 2014, 12:05

Re: Upcoming Ahk2Exe changes

18 Jul 2015, 22:37

Ok so i got the script playing sounds from the autoexec section; however, when i use PlaySound (SoundRef) in the "hotkey" section they NEVER play. Also this ONLY works in XP sound wise and not in 8.1 at all (no sounds are played in ANY section) even though i do see win 8.1 has the winmm.dll . Any thoughts ?
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Upcoming Ahk2Exe changes

18 Jul 2015, 23:18

Skrell wrote:when i use PlaySound (SoundRef) in the "hotkey" section they NEVER play
Make sure you have executed ResRead( Sound, "test.wav" ) before PlaySound.
Skrell
Posts: 302
Joined: 23 Jan 2014, 12:05

Re: Upcoming Ahk2Exe changes

19 Jul 2015, 12:00

Here try this:

Code: Select all

#NoEnv 
ResRead( tada, "tada.wav" )
return

#p::
PlaySound(tada)
return

PlaySound( ByRef Sound ) {
 Return DllCall( "winmm.dll\PlaySound" ( A_IsUnicode ? "W" : "A" ), UInt,&Sound, UInt,0
               , UInt, 0x6 ) ; SND_MEMORY := 0x4 | SND_NODEFAULT := 0x2
}


FileInstall, C:\Windows\Media\tada.wav, -
ResRead( ByRef Var, Key ) { 
  VarSetCapacity( Var, 128 ), VarSetCapacity( Var, 0 )
  If ! ( A_IsCompiled ) {
    FileGetSize, nSize, %Key%
    FileRead, Var, *c %Key%
    Return nSize
  }
 
  If hMod := DllCall( "GetModuleHandle", UInt,0 )
    If hRes := DllCall( "FindResource", UInt,hMod, Str,Key, UInt,10 )
      If hData := DllCall( "LoadResource", UInt,hMod, UInt,hRes )
        If pData := DllCall( "LockResource", UInt,hData )
  Return VarSetCapacity( Var, nSize := DllCall( "SizeofResource", UInt,hMod, UInt,hRes ) )
      ,  DllCall( "RtlMoveMemory", Str,Var, UInt,pData, UInt,nSize )
Return 0    
}
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Upcoming Ahk2Exe changes

19 Jul 2015, 15:01

Code: Select all

ResRead(tada, "C:\Windows\Media\tada.wav")
Skrell
Posts: 302
Joined: 23 Jan 2014, 12:05

Re: Upcoming Ahk2Exe changes

19 Jul 2015, 15:32

HotKeyIt wrote:

Code: Select all

ResRead(tada, "C:\Windows\Media\tada.wav")
I'm trying to execute the wav from within the compiled executable that's why I did that. There should be a fileinstall function in my code which is supposed to build the wav into the executable then I'm trying to make a reference to it so that I can play it with PlaySound.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Upcoming Ahk2Exe changes

19 Jul 2015, 16:07

The recource will be called the same as FileInstall, so you cannot use "tada.wav", you will need the full path
Skrell
Posts: 302
Joined: 23 Jan 2014, 12:05

Re: Upcoming Ahk2Exe changes

19 Jul 2015, 16:14

HotKeyIt wrote:The recource will be called the same as FileInstall, so you cannot use "tada.wav", you will need the full path
Omg.... I had no idea!! I'll try that asap!
Did you get it working with my hotkey code and your adjustment?

*UPDATE* this still does NOT work for a compiled executable. Please try it for yourself.
what version of windows and what version of the ahk2exe compiler are you using ? Is there some flag or something i need to set for the compiler?
I've tried it now on both win7 and win8.1 PCs and neither work for the compiled version. There is definitely some small thing i'm missing here.
Skrell
Posts: 302
Joined: 23 Jan 2014, 12:05

Re: Upcoming Ahk2Exe changes

20 Jul 2015, 21:11

Found the problem btw! The ResRead function does NOT work with 64bit OSes!
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Upcoming Ahk2Exe changes

29 Aug 2015, 22:48

Hope it will support to adding resources to other Resource Type.
Syntax:

Code: Select all

;@Ahk2Exe-AddResourceEx [File], [Resource Type], [Resource ID]
Example usage:

Code: Select all

;@Ahk2Exe-AddResourceEx image\test.gif, GIF, 110
;@Ahk2Exe-AddResourceEx image\test.png, PNG, 456
Attachments
2015-08-30_114428.png
2015-08-30_114428.png (3.89 KiB) Viewed 20471 times
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Upcoming Ahk2Exe changes

01 Sep 2015, 02:41

tmplinshi wrote:Hope it will support to adding resources to other Resource Type.
Syntax:

Code: Select all

;@Ahk2Exe-AddResourceEx [File], [Resource Type], [Resource ID]
Example usage:

Code: Select all

;@Ahk2Exe-AddResourceEx image\test.gif, GIF, 110
;@Ahk2Exe-AddResourceEx image\test.png, PNG, 456
It already supported! :mrgreen:

Code: Select all

;@Ahk2Exe-AddResource *GIF image\gif.gif, 110
;@Ahk2Exe-AddResource *PNG image\gif.gif, 456
Peter2
Posts: 325
Joined: 21 Sep 2014, 14:38
Location: CH

Re: Upcoming Ahk2Exe changes

26 Sep 2015, 17:33

Hi

what's the current state of this project?

The link in the first post is from January, the latest changes at Github are from August. The help at http://fincs.ahk4.net/Ahk2ExeDirectives.htm says "only BMP and DIB" as resource, the posting above says "also GIF and PNG" ....

Please update us with current information :idea: ;)
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Teemu
Posts: 3
Joined: 28 Nov 2015, 17:10

Re: Upcoming Ahk2Exe changes

28 Nov 2015, 17:20

If I compile my autohotkey script to exe, will it work at every computer?
User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Upcoming Ahk2Exe changes

29 Nov 2015, 08:04

It should.
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Bruttosozialprodukt
Posts: 463
Joined: 24 Jan 2014, 22:28

Re: Upcoming Ahk2Exe changes

29 Nov 2015, 09:09

Well.. more or less. Obviously it would only run under Windows.
And I think AHK_L dropped official support for everything prior to XP at some point.
And if you compile it as 64bit, it won't run on 32bit computers.
User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: Upcoming Ahk2Exe changes

30 Nov 2015, 07:57

I want get the text from the html resource of the compiled script.

Code: Select all

;@Ahk2Exe-AddResource  test.html
;compiled to test.exe
I was able to get it from another script with

Code: Select all

msgbox % getResource("test.exe","#23","test.html")
return
getResource(inFilePath,resourceType,resourceId){
;https://msdn.microsoft.com/en-us/library/windows/desktop/ms648009%28v=vs.85%29.aspx
;inFilePath somefile.exe 
;resourceType #23 for html; #10 js,css, >AUTOHOTKEY SCRIPT<
;resourceId Ex.: resource test.html .. >AUTOHOTKEY SCRIPT<
	hModule  := DllCall("LoadLibrary", Str,inFilePath)
        hResInfo := DllCall("FindResource", UInt,hModule, Str,resourceId, Str,resourceType)
	hResData := DllCall("LoadResource", UInt,hModule, UInt,hResInfo)
	pResData := DllCall("LockResource", UInt,hResData)
	resSize  := DllCall("SizeofResource", UInt,hModule, UInt,hResInfo)
	return StrGet(pResData, resSize, "UTF-8")
}
but i want it from the same exe. Like the Sound.wave Example
I tried this, but there seems to be something wrong

Code: Select all

get2Resource(resourceType,resourceId){
;----
	hModule := DllCall("GetModuleHandle", Uint,0)
	;hModule := DllCall("GetModuleHandle", Ptr,0)
	;hResInfo := DllCall("FindResource", UInt,hModule, Str,resourceId, Str,resourceType)
	hResInfo := DllCall("FindResource", UInt,hModule, Str,resourceId, UInt,23)
;----
	hResData := DllCall("LoadResource", UInt,hModule, UInt,hResInfo)
	pResData := DllCall("LockResource", UInt,hResData)
	resSize  := DllCall("SizeofResource", UInt,hModule, UInt,hResInfo)
	return StrGet(pResData, resSize, "UTF-8")
}
Thanks for advice
User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: Upcoming Ahk2Exe changes

30 Nov 2015, 12:34

Code: Select all

;@Ahk2Exe-AddResource  test.html
msgbox, %  ResRead(  "test.html" , "23")
return

ResRead(Key, resourceType) { 
;for textresources only
 If ! ( A_IsCompiled ) 
	FileRead, Var, %Key%
 return Var
  if hMod := DllCall( "GetModuleHandle", ptr, 0, ptr )
    if hRes := DllCall("FindResource", Ptr, 0, Str, Key, Ptr, resourceType, UPtr)
      if hData:= DllCall("LoadResource", Ptr, 0, Ptr, hRes, UPtr)
         if pData :=DllCall("LockResource", Ptr, hData, UPtr)
           if nSize :=DllCall("SizeofResource", ptr, hMod, ptr, hres, uint)
      return StrGet(pData, nSize, "UTF-8") 
Return 0    
}
}
This works!
Edit: The former function only worked with X32.
This ResRead() read Textresources also with X64 Autohotkey.
User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: Upcoming Ahk2Exe changes

02 Dec 2015, 12:44

I changed the above function to work with X32 and X64 Autohotkey.

I think it would be nice to integrate something like this in AHK2exe and add a Varname to the resource directive. So it will be very easy to access a embedded resource like text, html, images, sound and others.
User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: Upcoming Ahk2Exe changes

09 Dec 2015, 03:06

I combined the example from tmplinshi with mine from above to get text and binary resources with one function.

Code: Select all

;@Ahk2Exe-AddResource test.html
;@Ahk2Exe-AddResource C:\Windows\Media\tada.wav
;@Ahk2Exe-AddResource C:\Program Files (x86)\Microsoft Office\Office14\MEDIA\APPLAUSE.WAV

;http://www.angusj.com/resourcehacker/
;https://autohotkey.com/boards/viewtopic.php?f=24&t=521

If !A_IsCompiled 
{
    FileRead, tada, *c C:\Windows\Media\tada.wav
    FileRead, tada1, *c C:\Program Files (x86)\Microsoft Office\Office14\MEDIA\APPLAUSE.WAV
    FileRead, test, test.html
}
else
{
    ResRead(tada, "tada.wav" , 10) 
    ResRead(tada1, "APPLAUSE.wav" , 10)
    ResRead(test, "test.html" , 23)
}
#p::PlaySound(tada)
!p::PlaySound(tada1)
^p::msgbox, % test
return



ResRead( ByRef Var, Key , resourceType) { 
;resourceType as in fincs directives.ahk: 2 bmp,dib ; 23 htm,html,mht ; 24 manifest; 10 for the rest
VarSetCapacity( Var, 128 ), VarSetCapacity( Var, 0 )
SplitPath, Key, , , ext
bin=1
; define textfile extensions
if ext in txt,js,css,html,htm,mht
	bin=0
 if hMod := DllCall( "GetModuleHandle", ptr, 0, ptr )
    if hRes := DllCall("FindResource", Ptr, 0, Str, Key, Ptr, resourceType, UPtr)
      if hData:= DllCall("LoadResource", Ptr, 0, Ptr, hRes, UPtr)
         if pData :=DllCall("LockResource", Ptr, hData, UPtr)
            if !bin
                if nSize :=DllCall("SizeofResource", "ptr", hMod, "ptr", hres, "uint")
                    Return Var := StrGet(pData, nSize, "UTF-8")
             if bin
                Return VarSetCapacity( Var, nSize := DllCall( "SizeofResource", UInt,hMod, UInt,hRes ) )
                      ,  DllCall( "RtlMoveMemory", Str,Var, UInt,pData, UInt,nSize )
Return 0
}


PlaySound( ByRef Sound ) {
 Return DllCall( "winmm.dll\PlaySound" ( A_IsUnicode ? "W" : "A" ), UInt,&Sound, UInt,0
               , UInt, 0x6 ) ; SND_MEMORY := 0x4 | SND_NODEFAULT := 0x2
}

Return to “Announcements”

Who is online

Users browsing this forum: No registered users and 16 guests