Login
Username:

Password:

Remember me



Lost Password?

Register now!
Main Menu
Who's Online
3 user(s) are online (1 user(s) are browsing Forum)

Members: 2
Guests: 1

Kalamatee, DizzyOfCRN, more...

Browsing this Thread:   1 Anonymous Users





Need help regarding PutMsg()

Joined:
2006/4/9 14:38
Group:
Member
Posts: 94
Offline
I hope somebody can help me with this one:

I have got a c programm that will start another programm with SystemTags() function. The other programm can be basicly every programm - in my case i started System:Extras/Demos/BlackHole/blackhole.
Next step would be to make this (BlackHole) programm quit.

First i tried RemTask() and well ... the programm stops but a you might guess the programm does not quit properly. Then i thought it would be a good idea to send a message to this programm which contains an IDCMP_CLOSEWINDOW event. So i checked the content of a message of this type and i ended up with an IntuiMessage that contains the following data:

msg.ExecMessage.mn_Node.ln_Succ = NULL;
msg.ExecMessage.mn_Node.ln_Pred = NULL;
msg.ExecMessage.mn_Node.ln_Name = NULL;
msg.ExecMessage.mn_Node.ln_Type = 5;
msg.ExecMessage.mn_Node.ln_Pri = 0;
msg.ExecMessage.mn_ReplyPort = my_port;
msg.ExecMessage.mn_Length = 60;
msg.Class = 0x200;
msg.Code = 0;
msg.Qualifier = 0x8000;
msg.IAddress = NULL;
msg.MouseX = 0;
msg.MouseY = 0;
msg.Seconds = 0;
msg.Micros = 0;
msg.IDCMPWindow = NULL;
msg.SpecialLink = NULL;

All variables i considered useless (read did not know or care how to initialize properly) for my purpose where set to 0 or NULL.

Next i searched for the blackhole Process with FindTask() and casted the result to pointer to a struct Process.

Then i used PutMsg() to send the above message to the Process.pr_MsgPort and guess what ... the system crashed. Not like i did expect it to work but i tried and failed.

Next thing was to search for a Window with the Title "BlackHole".
I did it like this

struct Screen scr; //WorkbenchScreen
struct Screen search_scr = NULL;
struct Window search_win = NULL
char *found = NULL;

search_scr = &scr;
while( search_scr != NULL && found == NULL)
{
search_win = search_scr->FirstWindow;
while( search_win != NULL && found == NULL )
{
if( search_win->Title != NULL )
{
found = strstr( (const char*) search_win->Title, "BlackHole" );
}

if( found == NULL )
{
search_win = search_win->NextWindow;
}
}
search_scr = search_scr->NextScreen;
}

Well ... what does happen is that i am unable to find the BlackHole window. It seems not to exist.
Could it be that my BlackHole's are somehow not attached to the the list of Windows? Unlikely because how could they be displayed on the screen if they were not there?

But if is start the BlackHole Programm before i execute my programm this happens:
- my programm start BlackHole a second time
- my programm finds the BlackHole programm that i start first
- my programm sends the message to the first BlackHole and it quits
- but the second BlackHole remains
Funny thing is, if i do the search for BlackHole again, it will be found again, the message will be send again and the system crashs. Well i would say the first BlackHole Window was not removed from the list of Window and sending a message to a not existing MsgPort causes the crash.

Wild speculations ...

To make it short...
Is there someone who could tell me how to send a IDCMP_CLOSEWINDOW Message to BlackHole and make it quit properly?

Posted on: 2016/5/20 15:17
Transfer the post to other applications Transfer


Re: Need help regarding PutMsg()

Joined:
2006/4/9 14:38
Group:
Member
Posts: 94
Offline
... works better when i do a
GetScreenData( &scr, sizeof( struct Screen ), WBENCHSCREEN, NULL );
before entering the search-loop for the window. then the BlackHole Window will be found and it exits as expected but if i start BlackHole a second time and try to quit it a second time i get the following error message:

Programm failed
Task: 0xd87956e0 - abc
Error: 0x80000002 - Hardware bus fault/address error
PC: 0xF71D0AFE
Module Exec_41_AddTail (0xF71D0AF0) Offset 0x0000000E

Any hint on this?
Maybe because the IntuiMessage is crap?

Posted on: 2016/5/20 15:34
Transfer the post to other applications Transfer


Re: Need help regarding PutMsg()

Joined:
2004/5/7 2:45
From Daoulas (Finistère, France)
Group:
Member
Posts: 650
Offline
Our Intuition library provides the WindowAction() function:

struct IntuitionBase *IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library"0);

if (((
struct Library *)IntuitionBase)->lib_Version >= 50)
    
WindowAction(search_winWAC_SENDIDCMPCLOSENULL);

CloseLibrary((struct Library *)IntuitionBase);


That's using your search_win and assuming it is valid.

BTW my tool ActivateWin allows to do what you're attempting to do, from the Shell, by doing:

ActivateWin CLOSE "BlackHole"

so you may find hints by having a look at its sources.

Posted on: 2016/5/21 0:15
_________________
Everyone knew it was impossible. Along came a fool who did not know and he did it.
Transfer the post to other applications Transfer


Re: Need help regarding PutMsg()

Joined:
2006/4/9 14:38
Group:
Member
Posts: 94
Offline
Thanks a lot!
I did not notice this function because i usually work with the old Amiga OS documentation - and it seems it was not available back in the days (or not mentioned i the documents i have). Maybe i have to reconsider my approach

After i cleand the code, an found the reason for the crash at the second run - which was a not reinitialized variable, it now works like a charm.

WindowAction is a real fantastic addition to intuition!

Again thank you for your hint!

Posted on: 2016/5/21 6:56
Transfer the post to other applications Transfer


Re: Need help regarding PutMsg()

Joined:
2004/5/7 2:45
From Daoulas (Finistère, France)
Group:
Member
Posts: 650
Offline
You're welcome. According to the docs, WindowAction() is indeed inherited from MorphOS, hence the check that the used intuition.library is at least of version 50: so this code would be compilable for aros-68k and would totally run on an Amiga executing that system, and the same program would run without crashing, but with a limited behavior, on an Amiga executing an OS inferior or equal to 3.9 because the very function of WindowAction() would then not be called at all, thanks to this check.

Your code on the contrary would be totally running —especially now that you cleaned the code and the bug — even on a very early Commodore OS, at the price of a heavier executable.

Posted on: 2016/5/22 13:06
_________________
Everyone knew it was impossible. Along came a fool who did not know and he did it.
Transfer the post to other applications Transfer


Re: Need help regarding PutMsg()

Joined:
2008/11/15 15:27
Group:
Member
Posts: 523
Offline
The quick answer is you can't. The whole idea behind this thread is flawed. System() will start an external program but there isn't a well defined standard to send a message to quit any arbitrary program. Closing a window is not the same as asking the program to quit. It will leave system resources in an undefined state. Memory, File handles open, etc. Some programs are meant to be able to run without a GUI as well as with one and could be looping or doing calculations even though the window is "closed". Some programs might have a standard ARexx command to quit, or take a ctrl-c signal to mean quit, but it isn't well-defined.

Posted on: 2016/5/22 14:11
Transfer the post to other applications Transfer


Re: Need help regarding PutMsg()

Joined:
2004/5/7 2:45
From Daoulas (Finistère, France)
Group:
Member
Posts: 650
Offline
@edwberger: I think you make things more complicated than necessary. Most programs with a GUI do wait for the user to click the close button of the window (be it to terminate or to do other things). To do so they just wait to receive the IDCMP close message that Intuition has to send them when the close button is clicked.

Whether the IDCMP close message really comes from Intuition, or comes from a program which knows about the said window, doesn't matter.

The reaction of the receiving program is up to it. The user usually expects it to quit, but you're right, some programs just close the GUI and still run in the background. And even other behaviors are possible, though I doubt it would be compatible with the User Interface Style Guide.

Now Araxes' program does exactly what Intuition does when the user clicks the close button of a window: send a message, no more, no less, and the reaction of the receiving program is the one expected on a close-button-click.

IMHO the only debatable part would be the way a program gets to know about the foreign window. But Intuition's list of windows is accessible to readers, so I can live with it really.

Posted on: 2016/5/23 0:14
_________________
Everyone knew it was impossible. Along came a fool who did not know and he did it.
Transfer the post to other applications Transfer


Re: Need help regarding PutMsg()

Joined:
2006/4/9 14:38
Group:
Member
Posts: 94
Offline
The unfreed recourse ain't a problem in my case because the programms i am about to start and quit with the above mentioned technic will have to be special programms - and have yet to be written. Therefore the programm in question will >have to< quit completely after receiving an IDCMP_CLOSEWINDOW message.

It's not like i am about to start any programm with a call to System(). I am sorry for beeing unprecise in this respect.

Posted on: 2016/5/23 11:24
Transfer the post to other applications Transfer


Re: Need help regarding PutMsg()

Joined:
2011/6/30 19:50
Group:
Member
Posts: 4095
Offline
@araxes

In case the programs are yet to be written (and by your control) it could perhaps be an option to create a named messageport and use something like this to send a message (to which the other program respond exactly as you would like)

Posted on: 2016/5/23 12:14
Transfer the post to other applications Transfer


Re: Need help regarding PutMsg()

Joined:
2006/4/9 14:38
Group:
Member
Posts: 94
Offline
I at one point in time i actually intended to use custom MessagePorts - even named Port but WindowAction() is more convenient (for now).

Posted on: 2016/5/23 13:47
Transfer the post to other applications Transfer






You can view topic.
You cannot start a new topic.
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.

[Advanced Search]


Search
Top Posters
1 paolone
paolone
4398
2 magorium
magorium
4095
3 phoenixkonsole
phoenixkonsole
3904
4 nikolaos
nikolaos
3895
5 deadwood
deadwood
2923
6 ncafferkey
ncafferkey
2743
7 mazze
mazze
2220
8 clusteruk
clusteruk
2112
9 Kalamatee
Kalamatee
2082
10 damocles
damocles
1789
© 2004-2017 AROS Exec