AutoHotkey Community

It is currently May 27th, 2012, 3:32 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 563 posts ]  Go to page Previous  1 ... 13, 14, 15, 16, 17, 18, 19 ... 38  Next
Author Message
 Post subject:
PostPosted: June 29th, 2010, 7:19 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
This is a definitely a bug, I think I know what the problem is, I will fix on the weekend when I get back home, many thanks for reporting :)

When you comment out #Persistent the dll will exit and no function will run, so this is not related to the problem.

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 30th, 2010, 2:55 am 
HotKeyIt wrote:
This is a definitely a bug, I think I know what the problem is, I will fix on the weekend when I get back home, many thanks for reporting :)

Thanks for taking a look. Good luck with the fix :)

Quote:
When you comment out #Persistent the dll will exit and no function will run, so this is not related to the problem.

I thought that would be the case, but IIUC that doesn't seem to be what I observe.

After commenting out #Persistent in ahkdllissuehelper.ahk, I drag ahkdllissue.ahk and drop it on to AutoHotkey.exe. Subsequent presses of Control+Shift+1 and Control+Shift+2 lead to output from what I presume is the functions in ahkdllissuehelper.ahk (e.g. in DbgView.exe).

Perhaps I am misunderstanding something. Help?


Report this post
Top
  
Reply with quote  
PostPosted: June 30th, 2010, 6:27 am 
I had some success with Lexikos' idea using a single function :) Thanks again, Lexikos!

In the process of adapting the idea to local code I noticed that A_ScriptParams doesn't seem to be available within functions in the same way that A_AhkVersion and other such variables are. Using 'global' seemed to allow access.

Is this by design? Or may be there's some pilot error here :)

Below is some code that reproduces here (Windows XP Pro SP3, HotkeyIt ahkdll 1.0.48.05.L52H17, ReleaseA directory):

ascriptparamstest.ahk
Code:
; for A_AhkVersion: 1.0.48.05.L52H17
DllPath := A_ScriptDir . "\AutoHotkey.dll"

MsgBox, % "Please have something like DbgView.exe running before "
        . "clicking the button."

OutputDebug, % "----"
OutputDebug, % "Dll Path: " . DllPath
OutputDebug, % "----"

Sleep, 1

handleLibrary
  := DllCall("LoadLibrary"
           , "Str", DllPath)

handleThread
  := DllCall(DllPath . "\ahkdll"
           , "Str", A_ScriptDir . "\ascriptparamstesthelper.ahk"
           , "Str", ""
           , "Str", "test test and test"
           , "Cdecl UInt")

Sleep, 1

R1
  := DllCall(DllPath . "\ahkFunction"
           , "Str", "OutputSomeVars"
           , "Cdecl Str")

Sleep, 1

R2
  := DllCall(DllPath . "\ahkFunction"
           , "Str", "OutputSomeVars2"
           , "Cdecl Str")

Return

ascriptparamstesthelper.ahk
Code:
; for A_AhkVersion: 1.0.48.05.L52H17
#Persistent

OutputDebug, % "Outside a function"
OutputDebug, % "  A_ScriptParams: " . A_ScriptParams
OutputDebug, % "  A_AhkVersion: " . A_AhkVersion
OutputDebug, % "----"

OutputSomeVars()
{
  OutputDebug, % "Inside a function"
  OutputDebug, % "  A_ScriptParams: " . A_ScriptParams
  OutputDebug, % "  A_AhkVersion: " . A_AhkVersion
  OutputDebug, % "----"
}

OutputSomeVars2()
{
  global A_ScriptParams
  OutputDebug, % "Inside a function (2)"
  OutputDebug, % "  A_ScriptParams: " . A_ScriptParams
  OutputDebug, % "  A_AhkVersion: " . A_AhkVersion
  OutputDebug, % "----"
}


Report this post
Top
  
Reply with quote  
 Post subject: ahkFunction crashing
PostPosted: June 30th, 2010, 6:51 am 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
Guest_AutoHotkey_L wrote:
It appears that once ReturnEmptyString has been called once, calling ReturnNonEmptyString leads to crashing...

I have fixed ahkFunction so it doesn't crash. I have also cleaned up its implementation a little. Source and binaries updated.
Quote:
I noticed that A_ScriptParams doesn't seem to be available within functions in the same way that A_AhkVersion and other such variables are. Using 'global' seemed to allow access.
Thanks for pointing it out. Will add it to the list of things to fix.

@Lexikos Will also update the documentation about A_ScriptParams.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: addScript and addFile
PostPosted: June 30th, 2010, 7:43 am 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
fixed addScript and addFile, so they can be called from within a function.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: ahkFunction crashing
PostPosted: June 30th, 2010, 10:14 am 
tinku99 wrote:
I have fixed ahkFunction so it doesn't crash. I have also cleaned up its implementation a little.

Thanks for taking a look and working on a fix.

I confirmed that there is no more crashing :) I don't seem to be getting back the strings I'm expecting from ahkFunction though...

Should I try to provide some code to reproduce?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 30th, 2010, 10:25 am 
Guest_AutoHotkey_L wrote:
HotKeyIt wrote:
When you comment out #Persistent the dll will exit and no function will run, so this is not related to the problem.

I thought that would be the case, but IIUC that doesn't seem to be what I observe.

After commenting out #Persistent in ahkdllissuehelper.ahk, I drag ahkdllissue.ahk and drop it on to AutoHotkey.exe. Subsequent presses of Control+Shift+1 and Control+Shift+2 lead to output from what I presume is the functions in ahkdllissuehelper.ahk (e.g. in DbgView.exe).

Perhaps I am misunderstanding something.

Yes, my own code :) I get it now.


Report this post
Top
  
Reply with quote  
PostPosted: June 30th, 2010, 1:38 pm 
Lexikos wrote:
If you need to make multiple functions accessible, create an array of pointers and pass its address. The script can retrieve each address as follows:
Code:
func1 := NumGet(A_ScriptParams+0)
func2 := NumGet(A_ScriptParams+4)
func3 := NumGet(A_ScriptParams+8)
...
Note that NumGet differentiates between variables and values, not types of values. NumGet(A_ScriptParams) will not work for that purpose, but NumGet(A_ScriptParams+0) and NumGet(A_ScriptParams . "") will.

Just wanted to report that I had some success here with this approach. Thanks again!


Report this post
Top
  
Reply with quote  
PostPosted: July 2nd, 2010, 9:37 am 
Guest_AutoHotkey_L wrote:
Just wanted to report that I had some success here with this approach. Thanks again!

Some further news on this.

I can tell func1 and func2 (referred to as CFns[1] and CFns[2] below) get called via DbgView, but it looks to me like DllCall is returning empty results.

Is there anything special I need to do? Or perhaps there are some things I am doing wrong :)

This is all with: A_AhkVersion: 1.0.48.05.L52H17 and 1.0.48.05.L52dllH17 from HotkeyIt's zip file.

The test C functions are:
Code:
const char * ReturnString(
  void)
{
  odprintf("ReturnString");
  //
  return "a string value";
}

int ReturnInt(
  void)
{
  odprintf("ReturnInt");
  //
  return 42;
}

The AHK code that is run from ahkFunction is the function InHelper within the code below. Also, ahkdll is invoked with a 3rd argument of the form:

<number-of-functions> <address-of-function-array>

Code:
#NoEnv
#Persistent

ready := 0

InHelper()
{
  global A_ScriptParams
  OutputDebug, % "InHelper"
  OutputDebug, % "A_ScriptParams: " . A_ScriptParams
  FoundPos := RegExMatch(A_ScriptParams, "^(\d+) (\d+)", Matches)
  If (ErrorLevel != 0)
  {
    OutputDebug, % "RegExMatch set ErrorLevel to: " . ErrorLevel
    Return False
  }
  If (FoundPos == 0)
  {
    OutputDebug, % "RegExMatch failed to parse: " . A_ScriptParams
    Return False
  }
  NumFuncs := Matches1
  FuncArrAddr := Matches2
  OutputDebug, % "Number of functions: " . NumFuncs
  OutputDebug, % "Address of functions array: " . FuncArrAddr
  ; make functions in c accessible
  CFns := Object()
  Loop, % NumFuncs
  {
    CFns[A_Index] := NumGet(FuncArrAddr + (4 * (A_Index - 1)))
  }
  If (!VarSetCapacity(Result, 1024 * 1000))
  {
    OutputDebug, % "VarSetCapacity encountered invalid var name"
  }
  Else
  {
    Result :=
      DllCall(CFns[1]
            , "Cdecl Str")
    If (ErrorLevel != 0)
    {
      OutputDebug, % "DllCall() (ReturnString) set ErrorLevel to: "
                   . ErrorLevel
    }
    ; XXX: not working...why?
    OutputDebug, % "ReturnString: '" . Result . "'"
  }
  If (!VarSetCapacity(Result, 100))
  {
    OutputDebug, % "VarSetCapacity encountered invalid var name"
  }
  Else
  {
    Result :=
      DllCall(CFns[2]
            , "Cdecl Int")
    If (ErrorLevel != 0)
    {
      OutputDebug, % "DllCall() (ReturnInt) set ErrorLevel to: "
                   . ErrorLevel
    }
    ; XXX: not working...why?
    OutputDebug, % "ReturnInt: '" . Result . "'"
  }
  Return True
}

ready := 1


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 2nd, 2010, 10:50 am 
it's project amazing, but i'm found several bugs:
1)
    example:
    Code:
    #Persistent
    SetWorkingDir, A_ScriptDir
    #include %A_ScriptDir%\img\func_threads_init.ahk
    If 0
       FileInstall,VkBot_threads.dll,threads.dll


    Thread_Auto =
    (`%
    msgbox, %A_ScriptDir%
    )

    auto_dll:=AhkDllThread()
    auto_dll.ahktextdll(("#NoTrayIcon`n" Thread_Auto))


    1. i'm run "cmd"
    2. type "cd c:\"
    3. type "c:\test\qwe.exe" (for working directory = "c:\")

    and it aler "c:\", but Script directory = "c:\test"
    Why in "ahkdll" A_ScriptDir=A_WorkingDir?

    if, i change code to:
    Code:
    #Persistent
    SetWorkingDir, A_ScriptDir
    #include %A_ScriptDir%\img\func_threads_init.ahk
    If 0
       FileInstall,VkBot_threads.dll,threads.dll


    Thread_Auto =
    (`%
    msgbox, %A_WorkingDir%
    )

    auto_dll:=AhkDllThread()
    auto_dll.ahktextdll(("#NoTrayIcon`nSetWorkingDir, " A_ScriptDir "`n" Thread_Auto))



    it's works, but if directory name have Russian charater "я" -- it's alert Error:
    screenshoot
    Becouse, i'm using "ANSI build", and he have small bug -- he not support Russian charater "я", and always gives an error if this character meets in the script.

    I'm can't use "Unicode build" becouse HttpQuery not stable work with him (i'm try "HttpQuery for Autohotkey_L", but remote server not working with header "Content-Type: text/xml; charset=utf-8")...

2)
    If the script is running for a long time (~24 hours) --- he alert Error "memory can not be read" and program close


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 2nd, 2010, 9:20 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Try
coder wrote:
it's project amazing, but i'm found several bugs:
1)
    example:
    Code:
    #Persistent
    SetWorkingDir, A_ScriptDir
    #include %A_ScriptDir%\img\func_threads_init.ahk
    If 0
       FileInstall,VkBot_threads.dll,threads.dll


    Thread_Auto =
    (
    SetWorkingDir, %A_ScriptDir%
    msgbox, `%A_ScriptDir`%
    )

    auto_dll:=AhkDllThread()
    auto_dll.ahktextdll(("#NoTrayIcon`n" Thread_Auto))


    1. i'm run "cmd"
    2. type "cd c:"
    3. type "c:\test\qwe.exe" (for working directory = "c:")

    and it aler "c:", but Script directory = "c:\test"
    Why in "ahkdll" A_ScriptDir=A_WorkingDir?

    I'm can't use "Unicode build" becouse HttpQuery not stable work with him (i'm try "HttpQuery for Autohotkey_L", but remote server not working with header "Content-Type: text/xml; charset=utf-8")...

2)
    If the script is running for a long time (~24 hours) --- he alert Error "memory can not be read" and program close


You can use ANSI exe and use unicode dll or vice versa, you can read/convert the text using WideCharToMultiByte and MulitByteToWideChar.
Does above script produce that error in msgbox? It says that this folder is the a line in the script :?
b. This is because AhkDllThread() starts from memory and has not got a directory, Try AhkDllObject().
2) Where is the script?

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


Report this post
Top
 Profile  
Reply with quote  
PostPosted: July 2nd, 2010, 9:27 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Guest_AutoHotkey_L wrote:
I can tell func1 and func2 (referred to as CFns[1] and CFns[2] below) get called via DbgView, but it looks to me like DllCall is returning empty results.

Is there anything special I need to do? Or perhaps there are some things I am doing wrong :)

This is all with: A_AhkVersion: 1.0.48.05.L52H17 and 1.0.48.05.L52dllH17 from HotkeyIt's zip file.

Following will not work because you need to provide parameters when using DllCall
Code:
 DllCall(CFns[2]
            , "Cdecl Int")

See code for AhkDllThread and AhkDllObject where you can use DynaCall, here you can run any dll function and omit not required parameters.

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


Report this post
Top
 Profile  
Reply with quote  
PostPosted: July 3rd, 2010, 3:27 am 
HotKeyIt wrote:
Guest_AutoHotkey_L wrote:
I can tell func1 and func2 (referred to as CFns[1] and CFns[2] below) get called via DbgView, but it looks to me like DllCall is returning empty results.

Is there anything special I need to do? Or perhaps there are some things I am doing wrong :)

This is all with: A_AhkVersion: 1.0.48.05.L52H17 and 1.0.48.05.L52dllH17 from HotkeyIt's zip file.

Following will not work because you need to provide parameters when using DllCall
Code:
 DllCall(CFns[2]
            , "Cdecl Int")


Thanks for the response.

Both of the functions have no parameters in their definitions.

It seems to be working now and as I understand it, what was wrong was:
Code:
    Result :=
      DllCall(CFns[1]
            , "Cdecl Str")

The following appears to work:
Code:
    Result
      := DllCall(CFns[1]
               , "Cdecl Str")

Pilot error on the placement of := :)
Quote:
See code for AhkDllThread and AhkDllObject where you can use DynaCall, here you can run any dll function and omit not required parameters.

Thanks for these pointers. Got it working with DynaCall too. Seems quite nice!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 3rd, 2010, 3:59 am 
HotKeyIt wrote:
Does above script produce that error in msgbox? It says that this folder is the a line in the script :?


This error occurs when run the program from the directory in which there is a symbol of "я" (ahkdll start with line "` nSetWorkingDir, " A_ScriptDir " `n")


HotKeyIt wrote:
b. This is because AhkDllThread() starts from memory and has not got a directory, Try AhkDllObject().


ok, i'm try, and when i run my compiled script from console (type "cd c:" and run script) -- this say "c:" again, but path of script is "c:\test"

HotKeyIt wrote:
2) Where is the script?

script -- loop with getting data from remote server with HttpQuery (Autohotkey_L version)....
script work fine, but if "working time" of script is long -- he crashing with this error (i'm tried run his on Win7, WinXP)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 3rd, 2010, 10:08 am 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
@coder, what happens when you run a script with original AutoHotkey.exe without using dll? ANSI version cannot work with unicode path.

Did you try that
Code:
#Persistent
SetWorkingDir, A_ScriptDir
MsgBox % A_WorkingDir


Thread_Auto =
(
msgbox, %A_WorkingDir%
)

auto_dll:=AhkDllThread("x:\AutoHotkey.dll")
auto_dll.ahktextdll("#NoTrayIcon`n" Thread_Auto)


so when you run your httpQuery script without using dll does it crash as well?

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


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 ... 13, 14, 15, 16, 17, 18, 19 ... 38  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 8 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