Page 4 of 8

Re: Upcoming Ahk2Exe changes

Posted: 18 Jul 2015, 12:36
by joedf
The FileInstall that is never executed is just an old trick. you no longer to use that because of the directives :)

Re: Upcoming Ahk2Exe changes

Posted: 18 Jul 2015, 21:22
by tmplinshi
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, -

Re: Upcoming Ahk2Exe changes

Posted: 18 Jul 2015, 22:37
by Skrell
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 ?

Re: Upcoming Ahk2Exe changes

Posted: 18 Jul 2015, 23:18
by tmplinshi
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.

Re: Upcoming Ahk2Exe changes

Posted: 19 Jul 2015, 12:00
by Skrell
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    
}

Re: Upcoming Ahk2Exe changes

Posted: 19 Jul 2015, 15:01
by HotKeyIt

Code: Select all

ResRead(tada, "C:\Windows\Media\tada.wav")

Re: Upcoming Ahk2Exe changes

Posted: 19 Jul 2015, 15:32
by Skrell
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.

Re: Upcoming Ahk2Exe changes

Posted: 19 Jul 2015, 16:07
by HotKeyIt
The recource will be called the same as FileInstall, so you cannot use "tada.wav", you will need the full path

Re: Upcoming Ahk2Exe changes

Posted: 19 Jul 2015, 16:14
by Skrell
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.

Re: Upcoming Ahk2Exe changes

Posted: 20 Jul 2015, 21:11
by Skrell
Found the problem btw! The ResRead function does NOT work with 64bit OSes!

Re: Upcoming Ahk2Exe changes

Posted: 29 Aug 2015, 22:48
by tmplinshi
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

Re: Upcoming Ahk2Exe changes

Posted: 01 Sep 2015, 02:41
by tmplinshi
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

Re: Upcoming Ahk2Exe changes

Posted: 26 Sep 2015, 17:33
by Peter2
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: ;)

Re: Upcoming Ahk2Exe changes

Posted: 28 Nov 2015, 17:20
by Teemu
If I compile my autohotkey script to exe, will it work at every computer?

Re: Upcoming Ahk2Exe changes

Posted: 29 Nov 2015, 08:04
by joedf
It should.

Re: Upcoming Ahk2Exe changes

Posted: 29 Nov 2015, 09:09
by Bruttosozialprodukt
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.

Re: Upcoming Ahk2Exe changes

Posted: 30 Nov 2015, 07:57
by haichen
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

Re: Upcoming Ahk2Exe changes

Posted: 30 Nov 2015, 12:34
by haichen

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.

Re: Upcoming Ahk2Exe changes

Posted: 02 Dec 2015, 12:44
by haichen
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.

Re: Upcoming Ahk2Exe changes

Posted: 09 Dec 2015, 03:06
by haichen
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
}