Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

AutoHotkey_L v1.0.91.05


  • Please log in to reply
20 replies to this topic
  • Guests
  • Last active:
  • Joined: --
I tried to run k3ph's spectacular x-mas script with the latest version of AHK_L and it didn't work. However, it runs fine using an original AHK 1.0.48. Can you tell me why?

  • Guests
  • Last active:
  • Joined: --
I have found out that it must have something to do with the DllCall function as with AHK DllCall(A_Temp . "\BASS.dll\BASS_MusicLoad", UInt, mem, UInt, &file, UInt64, offset, UInt, length, UInt, flags, UInt, freq) returns a handle while it does not when run with AHK_L.

Using bass.dll and song.mo3 from k3ph's script (just comment out the
FileDelete commands and find them in your TEMP directory and copy them to the directory which the script is running in) and this
code

SetBatchLines,-1
Thread, NoTimers 

BASS_Init(device,freq,flags,win,clsid){
	global
	BassDll:=DllCall("LoadLibrary", "str", "\BASS.dll")
	Return DllCall("\BASS.dll\BASS_Init", Int, device, Int, freq, Int, flags, UInt, win, UInt, clsid)
}

BASS_ChannelPlay(handle,restart){
	;Return DllCall("\BASS.dll\BASS_ChannelPlay", UInt, handle, Int, restart)
	Return DllCall("\BASS.dll\BASS_ChannelPlay", UInt, handle, Int, restart, Cdecl Int)	
}

BASS_MusicLoad(mem,file,offset,length,flags,freq){
	Return DllCall("\BASS.dll\BASS_MusicLoad", UInt, mem, UInt, &file, UInt64, offset, UInt, length, UInt, flags, UInt, freq)
}

BASS_ChannelGetLength(handle,mode){
	Return DllCall("\BASS.dll\BASS_ChannelGetLength", UInt, handle, UInt, mode, UInt64)
}

BASS_ChannelBytes2Seconds(handle,pos){
	Return DllCall("\BASS.dll\BASS_ChannelBytes2Seconds", UInt, handle, UInt64, pos, Double)
}

BASS_ErrorGetCode(){
	Return DllCall("\BASS.dll\BASS_ErrorGetCode", Int)
}

BASS_Free(){
	global
	Return DllCall("\BASS.dll\BASS_Free", UInt, true),
				 DllCall("FreeLibrary", UInt, BassDll)
}

onexit,exit
bass=BASS.dll
fullbass=bass
fullfile=song.mo3
; -------------- Init ------------------------------
BASS_Init(-1,44100,0,0,0)
; -------------- Load ------------------------------
hStream:=BASS_MusicLoad( False, fullfile, 0, 0, 0x40000+0x20000+0x1000, 44100)
MsgBox,,hstream,%hstream%
a:=BASS_ErrorGetCode()
MsgBox ,,ErrorCode, %a%,
; -------------- GetLength ------------------------------
hStream_time:=Floor(BASS_ChannelBytes2Seconds(hStream,BASS_ChannelGetLength(hStream,0)))
hStream_sleep:=hStream_time*1000
; -------------- Play ------------------------------
a:=BASS_ChannelPlay( hStream, 0)
MsgBox,,ChannelPlay,%a%
a:=BASS_ErrorGetCode()
MsgBox ,,ErrorCode, %a%,
sleep %hStream_sleep%

exit:
  BASS_Free()
  ExitApp

I get MessageBoxes as follows:

AHK: -1610612735 (a valid handle) / 0 (no error) / 1 (ChannelPlay successful) / 0 (no error)


AHK_L ANSI: -1610612735 / 0 / 1 / 0 --> however, this only works when the "Cdecl Int" in the DllCall to BASS_ChannelPlay is removed (see the commented line above), otherwise I get an empty string insted of 1 and it doesn't play anything


AHK_L Unicode: 0 (no handle) / 2 ( BASS_ERROR_FILEOPEN) / 0 (ChannelPlay failed) / 5 (BASS_ERROR_HANDLE)

What has to be changed to make the script run with AHK_L Unicode and why does it run with AHK_L ANSI only without "Cdecl Int"?

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
This thread is for discussion about the latest release, not for requesting help with incompatible scripts.

Due to some fundamental differences between AutoHotkey and AutoHotkey_L (particularly Unicode and x64 builds), scripts written for AutoHotkey may not work as expected on AutoHotkey_L. For details of known compatibility problems and solutions, refer to the following:
[*:jl4aye2d]Script compatibility - Unicode vs ANSI, DllCall, NumPut/Get, other changes
[*:jl4aye2d]Script file code page - save your scripts as UTF-8!
Source: AutoHotkey_L (recently added)

Since this one is simple, I will post the answers:
[*:jl4aye2d]BASS expects ANSI strings, but the script is passing it a Unicode string. Replace UInt, &file with AStr, file.
[*:jl4aye2d]DllCall(..., Cdecl Int) was never valid, but in AutoHotkey Basic this error is not caught. Use quotation marks.

Note: When specifying an argument type or return type that does not contain a space or asterisk, the quotes around it may be omitted.
Source: DllCall



Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

1.0.91.04 - December 29, 2010
Fixed (Unicode): RegExReplace omitted all text up to StartingPosition (broken by v1.0.90.00).



Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

1.0.91.05 - January 1, 2011
Fixed: Cleanup code in COM method calls was freeing the wrong parameters.
Fixed (ANSI): DllCall set incorrect length for wstr parameters on output.
Fixed: Variadic function calls were unstable when param object was empty.



Smurth
  • Members
  • 120 posts
  • Last active: Feb 23 2014 09:58 PM
  • Joined: 13 Dec 2006
I was away of AHK during a whole year. I'm very glad to see all of these inprovements.
I've read the roadmap, especially http://www.autohotke...toHotkey-v2.htm and I must say "yes!", breaking backward-compatibility would lead in a cleaner way to write scripts.

Happy New Year to everyone !

(2011 is really starting good)