AutoHotkey Community

It is currently May 27th, 2012, 1:31 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 563 posts ]  Go to page Previous  1 ... 33, 34, 35, 36, 37, 38  Next
Author Message
PostPosted: December 27th, 2011, 3:29 pm 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
BUG
HotKeyIt wrote:
Hey tinku99, many thanks for reporting, this is fixed now ;)
Thanks for fixing #2: calling ansi from unicode now works.
However, issue #1 above is is still broken: second call to ahkFunction somehow puts the 1st param from first call into 2nd param from second call...
Further, even the first param is somehow broken:
Code:
ahk:=ComObjCreate("AutoHotkey.Script")   
script =                                 
( %                                       
#persistent                               
return                                   
                                         
filter(w){                               
return w[0]                               
}                                                 
)                                                 
ahk.ahktextdll(script)                             
Sleep, 1000                                       
arr := ComObjArray(VT_VARIANT:=12, 3)     
arr[0] := "hello world"                   
msgbox % ahk.ahkFunction("filter", arr)  ; works first time 
                                                         
arr[0] := "world"                                         
msgbox % ahk.ahkFunction("filter", arr)  ; fails as arr has been somehow broken by dll
                                                                                   
arr := ComObjArray(VT_VARIANT:=12, 3)  ; if you create a new array...   
arr[0] := "hello"                                                   
msgbox % ahk.ahkFunction("filter", arr)  ; then it works again                           

SANDBOXING
HotKeyIt wrote:
We can simply override the functions with user defined functions that do nothing or notify the user [in ahktextdll].
Code:
NumPut(p*){
   MsgBox Function %A_ThisFunc% has been deactivated
}
, than you would addFile or addScript [for sandboxed scripts

That seems to work :)
example:
Code:
ahk:=ComObjCreate("AutoHotkey.Script")
   
script =                   
( %                         
#persistent                 
NumPut(p*){
   MsgBox Function %A_ThisFunc% has been deactivated
}
return                     
)                                 
ahk.ahktextdll(script)             
Sleep, 1000                                 

sandboxed =
(
fx(){
VarSetCapacity(x, 5)
static s := numput(5, x)
}
  VarSetCapacity(x, 5)
numput(5, x) 
)               

ahk.addScript(sandboxed , 1) 
return

!r::reload
!q::exitapp   


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 27th, 2011, 9:06 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
This is also fixed now, thanks ;)

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject: progid of alpha dll
PostPosted: December 28th, 2011, 5:20 am 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
Hotkeyit,
Thanks for fixing ahkFunction.
HotKeyIt wrote:
You can register and test all of them.
Code:
Regsvr64.exe .\x64w\AutoHotkey.dll
Regsvr32.exe .\win32a\AutoHotkey.dll
Regsvr32.exe .\win32w\AutoHotkey.dll

Code:
AutoHotkey.Script ;Last one registered will be used
AutoHotkey.Script.ANSI ;Ansi - .\win32a\
AutoHotkey.Script.UNICODE ;Unicode .\win32w\
AutoHotkey.Script.X64 ;x64 - .\x64w\

I think this info would be good in the help file.
Also, do you have different progid's for the alpha versions also ?
maybe:
AutoHotkey2.Script32
AutoHotkey2.Script64

would you mind putting up the alpha dll source on github?
Also the source for the help file ? I would like to help expand some of the examples, for ex. ahkFunction using some com arrays...


Report this post
Top
 Profile  
Reply with quote  
 Post subject: JHK
PostPosted: December 28th, 2011, 7:32 am 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
Hey, I though this might be of interest here. I wrote a really short piece of Java that uses AutoHotkey.dll. I made a video of how to set it up, and I uploaded the code.

Video
Gist
Zip (Everything you need)

Let me know what you think. And of course, if you can improve it, please do!

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 31st, 2011, 1:57 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Thanks tinku99, I have changed COM interface for AutoHotkey2 and also uploaded it to git.

Documentation was updated as well.
Source is also available on git.

Thanks Frankie, looks interesting.

Merged AutoHotkey 1.1.05.06

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 19th, 2012, 2:05 am 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Merged AutoHotkey 1.1.06.02
Merged AutoHotkey v2.0 a030
Update wrote:
- AutoHotkey_H now supports Lib folder in Resource.
- - So functions can be included in exe now.
- V2 version supports pointers in Str/AStr/WStr for DllCall and DynaCall now. e.g. DllCall("LoadLibrary","Str",&libstring)
- Removed ahkKey exported function
- FileInstall for scripts compiled with AutoHotkey.exe

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2012, 7:49 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Update wrote:
- ahkFunction,ahkPostFunction support calling build-in functions now
Code:
dll:=ComObjCreate("AutoHotkey.Script")
dll.ahktextdll("#Persistent`nfunc(a=""true""){`nReturn a`n}")
MsgBox % dll.ahkFunction("InStr","test","s") "`n"
      . dll.ahkFunction("Func","return") "`n"
      . dll.ahkFunction("DllCall","MessageBox","UInt",0,"Str","Text","Str","Title","UInt",4)

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2012, 8:27 pm 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
HotKeyIt wrote:
Update wrote:
- ahkFunction,ahkPostFunction support calling build-in functions now
Code:
dll:=ComObjCreate("AutoHotkey.Script")
dll.ahktextdll("#Persistent`nfunc(a=""true""){`nReturn a`n}")
MsgBox % dll.ahkFunction("InStr","test","s") "`n"
      . dll.ahkFunction("Func","return") "`n"
      . dll.ahkFunction("DllCall","MessageBox","UInt",0,"Str","Text","Str","Title","UInt",4)
Thanks. Must have broke when support for variants was enabled.

I have uploaded an experimental sandbox branch to github. It basically removes all dangerous commands and functions. example host.ahk
Code:
ahk := comobjcreate("AutoHotkey.Script.ANSISANDBOX")
FileRead, sandbox, sandbox.ahk                 
ahk.ahktextdll(sandbox)       
x := ahk.ahkFunction("inStr", "helloworld", "hello")
msgbox % "substr returned: " x
return               
!r::reload
!q::exitapp         
sandbox.ahk
Code:
#Persistent
mousemove, 100, 100   ; disabled, mouse will not move
WhichButton := DllCall("MessageBox", "Int", "0", "Str", "Press Yes or No", "Str", "Title of box", "Int", 4)   ;; dllcall disabled
MsgBox You pressed button #%WhichButton%.  ; msgbox disabled
fx(a, b ){
return substr(a, b)
}     
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2012, 9:00 pm 
Offline

Joined: May 23rd, 2009, 4:48 am
Posts: 365
Location: north bay, california
Is an ahk2dll "compiler" a possibility for future goals of this project? It'd be nice to wrap a custom function(set) in a dll for use with other languages without users knowledge of ahk

- gwarble

_________________
Notify() | Compile() | Instance() | LV_Group()
EitherMouse
Recommended: AHK_L (don't forget its a superset of _Basic)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2012, 9:21 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Not sure what you mean, it is already possible to compile a dll using Ahk2Exe for AHK_H.
Also you can include functions in resource (in Folder LIB) since 1.1.06, so they are like build in functions and loaded at load time from resource.

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2012, 10:45 pm 
Offline

Joined: May 23rd, 2009, 4:48 am
Posts: 365
Location: north bay, california
Oh sweet, my bad i guess i didnt look close enough...
Thanks, i'll give it a try

_________________
Notify() | Compile() | Instance() | LV_Group()
EitherMouse
Recommended: AHK_L (don't forget its a superset of _Basic)


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 26th, 2012, 11:15 pm 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
works fine from autohotkey hosts:
Code:
ahk := comobjcreate("AutoHotkey.Script.UNICODE")                   
ahk.ahktextdll("#persistent")                         
arr := ComObjArray(VT_VARIANT:=12, 3)
arr[0] := "Auto"
arr[1] := "Hot"
arr[2] := "key"       
ahk.ahkassign("x", arr)
y := ahk.ahkgetvar("x")
for i in y{
msgbox % i   ; works
}         
return               
but it fails from python:
Code:
import pythoncom, win32com.client, time
ahk = win32com.client.Dispatch("AutoHotkey.Script.UNICODE")
script = '''                     
#persistent                       
echo(x){   
for i in x {
msgbox % i  ; ok                         
return x                         
}                                 
'''                               
ahk.ahktextdll(script)           
time.sleep(1)

ahk.ahkassign('simple', 'simple value')
simple = ahk.ahkgetvar('simple') # ok
                                 
ahk.ahkassign('x', ['auto', 'hot', 'key'])
x = ahk.ahkgetvar('x')  # error                             

autohotkey = ahk.ahkFunction('echo', ['auto', 'hot', 'key'])  # ok
the problem seems to be with getting out global variables containing safearrays. ahkgetvar on simple numbers and strings works ok even from python.

edit: assigning an array using a function that clones the array allows ahkgetvar to work, so maybe the problem is with ahkassign ?
Code:
import pythoncom, win32com.client, time
# ahk = win32com.client.Dispatch("AutoHotkey.Script.ANSISANDBOX")
ahk = win32com.client.Dispatch("AutoHotkey.Script.UNICODE")
script = '''                         
#persistent                           
putreports(r){                           
global reports                       
loop % 2 {                           
msgbox % r[A_Index - 1, A_Index - 1] 
}                                     
reports := r.clone()  ; fails without the clone()
}                                     
getreport(i, j){                     
global reports                           
listvars       
VarType := ComObjType(reports)
maxindex := reports.maxindex()
x := reports[i, j]         
msgbox % "vartype: " vartype "`nmaxindex: " maxindex "`nx: " x
return x                             
}                                     
'''                                   
ahk.ahktextdll(script)               
time.sleep(1)                                     
ahk.ahkFunction('putreports', [['auto', 'hot', 'key'],
                               ['2auto', '2hot', '2key']])                                                                                             
y = ahk.ahkFunction('getreport', 1, 1)           
z = ahk.ahkgetvar('reports') # works


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Unexpected behaviour
PostPosted: February 28th, 2012, 9:02 pm 
Offline

Joined: June 12th, 2008, 1:48 am
Posts: 27
Hi,

first of: Great work.

Second, I ran into a problem, and it took me a while to find the error. It's a unexpected behaviour with the built-in variable A_ScriptDir if used with ahktextdll ! I could not find a remark in the docs, and could reproduce it with a simple test script. So the question is, did I miss something and this is expected behaviour, or did I run into a bug?

Test script setup:
The autohotkey.exe is in "C:\Programs (x86)\Autohotkey\AHK_H"
The test files are in "D:\AHK\Test"
The only modification done to AhkDllThread.ahk is directly inserting Skans function and thus removing the dependency!

The main.ahk:
Code:
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

T1 := AhkDllThread(A_ScriptDir "\AutoHotkey.dll")
FileRead, sstr, %A_ScriptDir%\t\test.ahk
T1.ahktextdll(sstr)

While T1.ahkReady()
  sleep, 100

T2 := AhkDllThread(A_ScriptDir "\AutoHotkey.dll")
T2.ahkdll(A_ScriptDir "\t\test.ahk")

While T2.ahkReady()
  sleep, 100

return

#Include AhkDllThread.ahk

and the test.ahk, residing in the subfolder "t":
Code:
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

MsgBox, %A_ScriptDir%
return


Both messageboxes should show the same path "D:\AHK\Test", but the first one shows the path to the autohotkey.exe ! Same is if I run the code with AHK_L. Shouldn't the var point both times to the dll-path ??

Thx in advance.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 28th, 2012, 9:55 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
    @tinku99, thanks for reporting, I will look into that.
    @dadepp

    - AutoHotkey.dll is loaded from Memory to enable multi-threading, that is the reason why the path to exe and not to dll is shown in general.
    - A_ScriptDir is not A_AhkPath and not A_DllPath, so it should show the path to script, not to exe or dll.
    - ahktextdll loads the script from Memory/String, so there is no file and no path, that is why again the exe path is shown.

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 28th, 2012, 10:14 pm 
Offline

Joined: June 12th, 2008, 1:48 am
Posts: 27
Thanks for the fast reply.

As I thought, I missed something completly: The fact that the dll is loaded from memory. Now that you mentioned it, it makes sense :roll: .
Now I feel kinda silly :oops: for not thinking about that fact.

Thanks again for taking your time.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 563 posts ]  Go to page Previous  1 ... 33, 34, 35, 36, 37, 38  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group