Re: Upcoming Ahk2Exe changes
Posted: 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
Let's help each other out
https://www.autohotkey.com/boards/
No.2. Do i still need to use ;@Ahk2Exe-AddResource SNAP.wav ?
Yes.3. Should the function call "PlaySound ( Sound)" be used to play the sound instead of "SoundPlay" ?
No. If you put into autoexec section, then the file will be extracted.4. Shouldn't "FileInstall, SNAP.wav, - " be in the autoexec section at the top of my code along with "ResRead( Sound, "SNAP.wav" )" ?
Code: Select all
If !A_IsCompiled
FileInstall, SNAP.wav, -
Make sure you have executed ResRead( Sound, "test.wav" ) before PlaySound.Skrell wrote:when i use PlaySound (SoundRef) in the "hotkey" section they NEVER play
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
}
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 wrote:Code: Select all
ResRead(tada, "C:\Windows\Media\tada.wav")
Omg.... I had no idea!! I'll try that asap!HotKeyIt wrote:The recource will be called the same as FileInstall, so you cannot use "tada.wav", you will need the full path
Code: Select all
;@Ahk2Exe-AddResourceEx [File], [Resource Type], [Resource ID]
Code: Select all
;@Ahk2Exe-AddResourceEx image\test.gif, GIF, 110
;@Ahk2Exe-AddResourceEx image\test.png, PNG, 456
It already supported!tmplinshi wrote:Hope it will support to adding resources to other Resource Type.
Syntax:Example usage:Code: Select all
;@Ahk2Exe-AddResourceEx [File], [Resource Type], [Resource ID]
Code: Select all
;@Ahk2Exe-AddResourceEx image\test.gif, GIF, 110 ;@Ahk2Exe-AddResourceEx image\test.png, PNG, 456
Code: Select all
;@Ahk2Exe-AddResource *GIF image\gif.gif, 110
;@Ahk2Exe-AddResource *PNG image\gif.gif, 456
Code: Select all
;@Ahk2Exe-AddResource test.html
;compiled to test.exe
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")
}
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")
}
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
}
}
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
}