Procedure CheckWBStartup()

AmigaOS specific forum
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Roxxler.

Hi,

here another procedure: CheckWBStartup(). It is nearly the same like the
procedure OwnWBStartup() i have posted before. OwnWBStartup() replaces
the WBStartup() function of PureBasic, this one not; WBStartup() returns
also the pointer to the wbstartupmessage if the program is started
from wb and this pointer will use by this procedure.

If you want informations how the procedure works see OwnWBStartup().
It is the same except that we don't have to find our task and that
we don't have to take the wbstartupmessage ourselfs, because all
this will be done by WBStartup(). Also we don't have to set the
program dir as currentdir, this will do the InitToolType(0) after
WBStartup() for us and also the tooltype 0 is initialized with the
tooltypes of our program icon.

You see, that this procedure is much easier as OwnWBStartup(),
because we don't have to open the dos.library and exec.library,
we don't set the currentdir and we don't have to take and to reply the
wbstartupmessage at the program end. But there is one little
big thing which goes wrong with this (see Note).

There is one parameter for the procedure: wbstartupmessage
This is the pointer we receive from WBStartup().
The procedure return -1 if the pointer was >0 which means
that the program is started from WB; else it returns 0
which means that the pointer was 0 and the program was started from CLI.

NOTE (for Fred and all others):
This procedure will cause an enforcer hit and the problem is that i don't
know why !!! So please help. The enforcer hit is a long read from 0.
The program will run without any problems, but a program which causes
an enforcer hit is a bad program.
I have found out the following:
If i remove the InitToolType(0) after the WBStartup() command there is
no enforcerhit, but then the program dir is not set as currentdir (ok, i
can do this myself or in the procedure). Also the tooltypes of the
program icon are not initialized.
If i place the InitToolType(0) BEFORE the WBStartup() command then there
is also no enforcerhit, but then there is still the currentdir not set
and also, once again, the tooltypes are not initialized.
The strange thing is that i used the procedure also in another program
which is much bigger and there is no enforcerhit with a InitTooltype(0)
directly after the WBStartup() function in conjunction with this procedure.
This is the reason why i have post the procedure OwnWBStartup() first.

Maybe it is a bug from PureBasic, i don't know. It makes me silly :)))
not to know why and when i know why, how to change this to run correctly.


Procedure.b CheckWBStartup(wbstartupmessage.l)
If wbstartupmessage>0
Structure WBArgs
filelock.l
namearg.s
EndStructure
NewList MyWBArg.WBArgs()
Shared MyWBArg
numargs.l=PeekL(wbstartupmessage+28)
ptrwbarg.l=PeekL(wbstartupmessage+36)
For i.w=1 To numargs
AddElement(MyWBArg())
MyWBArg()\filelock=PeekL(ptrwbarg)
MyWBArg()\namearg=PeekS(PeekL(ptrwbarg+4))
ptrwbarg+8
Next i
FirstElement(MyWBArg())
ProcedureReturn -1
Else
ProcedureReturn 0
EndIf
EndProcedure

wbmessage.l=WBStartup()
InitToolType(0)
If CheckWBStartup(wbmessage)=0
PrintN("This program ist started from CLI")
Else
numofarg.w=CountList(MyWBArg())
text$="The program is started from WB"+Chr(10)
text$+"Program name is »"+MyWBArg()\namearg+"«"+Chr(10)
text$+"There are "+Str(numofarg)+" argument(s) (the first is the started program)."+Chr(10)+Chr(10)
text$+"Here the arguments:"+Chr(10)
Repeat
text$+MyWBArg()\namearg+Chr(10)
Until NextElement(MyWBArg())=0
EasyRequester("Info",text$,"ok")
EndIf
End

Greetings ..
Roxxler