Two questions while trying to convert Gdip lib

Discuss the future of the AutoHotkey language
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Two questions while trying to convert Gdip lib

17 Nov 2016, 23:05

1. I've made Regexmatch backward compatible like this, since v2 forces the output as a match object instead of pseudoarray:

Code: Select all

	pattern_opts := (A_AhkVersion < "2") ? "iO)" : "i)"
	RegExMatch(Options, pattern_opts "C(?!(entre|enter))([a-f\d]+)", Colour)
Now because i'm using objects for the match, I have to check for the existence of the object each time i try to access the subpattern, because v2 now throws an exception if there is no obj to invoke. Is there a more elegant way to handle this?

Code: Select all

;before
	(Colour2 ? Colour2 : "ff000000")
;after
	(Colour && Colour[2] ? Colour[2] : "ff000000")

2. The example scripts won't close when run on v2. Here is my Gdip v2 repository. When I run any of the examples, I trying to close by simply right clicking the tray icons but it just hangs and I have to kill it via Task Manager. Is it something to do with the Gdip_Shutdown() func?

Code: Select all

Gdip_Shutdown(pToken)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	DllCall("gdiplus\GdiplusShutdown", Ptr, pToken)
	if hModule := DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
		DllCall("FreeLibrary", Ptr, hModule)
	return 0
}

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Two questions while trying to convert Gdip lib

18 Nov 2016, 02:18

For #1, you could use if !RegExMatch(...), Colour := {} or similar.

Rather than using {}, you could use a more specialized object, such as:

Code: Select all

(x or never_mind).foo().bar()

class never_mind extends never_mind._Base {
	class _Base {
		__Get() {
			return this
		}
		__Set() {
			return
		}
		__Call() {
			return this
		}
	}
}
For #2, can you step through the shutdown sequence with a debugger (e.g. SciTE4AutoHotkey)?
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Two questions while trying to convert Gdip lib

18 Nov 2016, 11:07

lexikos wrote:For #1, you could use if !RegExMatch(...), Colour := {} or similar.

For #2, can you step through the shutdown sequence with a debugger (e.g. SciTE4AutoHotkey)?
1. thanks
2. the debugger gets through the Gdip_Shutdown() ok and then hangs at ExitApp :(

found the problem:

v2-changes says the OnExit command was removed, i still had that line in there. but no error was thrown mentioning 'invalid command' or anything like that. changing to OnExit() func works

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Two questions while trying to convert Gdip lib

18 Nov 2016, 18:06

OnExit xxx is not invalid - it is the same as OnExit("xxx"). If xxx is not a function name, an error is thrown.

However, you had OnExit, Exit. Exit is a function. That should effectively do nothing, like registering a function which just calls Exit. Because your actual Exit handler wasn't being called, it would have the effect of preventing Gdip_Shutdown from being called on exit; but then how could it "get through the Gdip_Shutdown() ok"?

OnExit, Exit in a debug build triggers an error indicating parameter #2 should be an output variable, due to a bug. As far as I can tell, it doesn't affect the current release builds. (The bug relates to calling a command-function dynamically and passing more parameters than expected.)
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Two questions while trying to convert Gdip lib

18 Nov 2016, 18:44

lexikos wrote:OnExit xxx is not invalid - it is the same as OnExit("xxx"). If xxx is not a function name, an error is thrown.
ah yes i forgot functions can be called with command syntax
lexikos wrote: However, you had OnExit, Exit. Exit is a function. That should effectively do nothing, like registering a function which just calls Exit.
that probably explains why it hung
lexikos wrote:Because your actual Exit handler wasn't being called, it would have the effect of preventing Gdip_Shutdown from being called on exit; but then how could it "get through the Gdip_Shutdown() ok"?
i didn't know how to trigger the exit sequence with the debugger (i never use s4ahk), since i was previously right clicking the tray icon. so when i tried the debugger, i just put the gdip_shutdown directly in the autoexec to make sure that that wasn't the issue

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Two questions while trying to convert Gdip lib

18 Nov 2016, 19:20

guest3456 wrote:that probably explains why it hung
How so? Does it hang if you omit OnExit? Does it hang if you register an OnExit function which just calls Exit?
i didn't know how to trigger the exit sequence with the debugger
Do it the same way as always. By attempting to exit.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Two questions while trying to convert Gdip lib

18 Nov 2016, 19:29

lexikos wrote:
guest3456 wrote:that probably explains why it hung
How so? Does it hang if you omit OnExit? Does it hang if you register an OnExit function which just calls Exit?
OnExit("Exit") and i cannot close the script. 'hang' is the wrong word. just unable to close so maybe i thought it was 'hung'

Code: Select all

onexit("exit")  ;// or:  onexit, exit
return

f7::
  msgbox f7
return

f8::
  exitapp
return
obviously there is no func named "exit" so i guess its falling back to the built in func

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Two questions while trying to convert Gdip lib

18 Nov 2016, 20:57

That's not supposed to happen.

When I tested earlier, it was with a non-persistent script. In that case, Exit is the same as ExitApp - i.e. it terminates the script immediately.

For a persistent script, Exit would be expected to terminate the thread which called the function. For OnExit functions, the script is supposed to exit unless the function returns true. If the function exits, it can't return true. It turns out that I didn't handle the "exit" status correctly, and in v2 the result is that Exit acts like return true.
obviously there is no func named "exit" so i guess its falling back to the built in func
As I said, Exit is a function. No one said it had to be user-defined.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Two questions while trying to convert Gdip lib

18 Nov 2016, 22:10

i think most of the gdip examples had gui's so that would explain the persistent status


Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 20 guests