Page 1 of 1

Createport not working with RapaGUI

Posted: Fri Apr 23, 2021 3:31 pm
by amyren
I tried using CreatePort() in my program for the purpose of detecting if the program was ran twice.
But it fail to create a port at all, and triggers the error.
The errorname is "Unable to open Window"

Is there another option for this purpose when using RapaGUI?

Re: Createport not working with RapaGUI

Posted: Fri Apr 23, 2021 5:33 pm
by plouf
example program from manual works here.

what os ? sample program with your problem ?

Re: Createport not working with RapaGUI

Posted: Fri Apr 23, 2021 10:26 pm
by amyren
I run it on windows 10.

For a working example, open the RapaGUI Dialogs.hws example and put this piece of code just before the main loop.

Code: Select all

ExitOnError(False)
	CreatePort("TEST")
	code=GetLastError()
	If code<>0
			SystemRequest("Warning", "Program is already running", "OK",#REQICON_ERROR)
	EndIf
ExitOnError(True)

Re: Createport not working with RapaGUI

Posted: Sat Apr 24, 2021 5:02 am
by plouf
you are checking against ANY error and not if "port has failed"

a more propriety approach should be that way

Code: Select all

ExitOnError(False)

	CreatePort("TEST")

	code=GetLastError()
	If code=#ERR_PORTNOTAVAIL
		SystemRequest("Warning", "Program is already running", "OK",#REQICON_ERROR)
	EndIf
ExitOnError(True)

Re: Createport not working with RapaGUI

Posted: Sat Apr 24, 2021 12:57 pm
by amyren
Thanks for the lesson, it led me to read a bit more about error codes:)

Unfortunately it still will not work. The problem is that GetLastError() will never get that specific error code, it returns the 1010 code instead. Which is "Unable to open window"

Code: Select all

ExitOnError(False)
	CreatePort("TEST")
	code=GetLastError()
	DebugPrint(code)
	If code=#ERR_PORTNOTAVAIL
		SystemRequest("Warning", "Program is already running", "OK",#REQICON_ERROR)
	EndIf
ExitOnError(True)

Re: Createport not working with RapaGUI

Posted: Sat Apr 24, 2021 1:09 pm
by plouf
unable to open window is an error BEFORE your check
this error trigerer BEFORE your check so its last error as long as no NEW error added and became the new "last"

try my example egain, create a executable with this code and execute it twice

Code: Select all

ExitOnError(False)

	CreatePort("TEST")

	code=GetLastError()
	If code=#ERR_PORTNOTAVAIL
		SystemRequest("Warning", "Program is already running", "OK",#REQICON_ERROR)
	EndIf
ExitOnError(True)
Repeat
	Wait(10)
Forever

Re: Createport not working with RapaGUI

Posted: Sat Apr 24, 2021 2:48 pm
by airsoftsoftwair
CreatePort() needs RapaGUI 2.0. See here: viewtopic.php?f=10&t=3282