Restored from previous forum. Originally posted by Roxxler.
Hi,
here once again the procedure OwnWBStartup() with a little change.
For information how the procedure works see the old one.
Changes in the procedure:
1. the line "Shared MyWBArg" is replaced with "Shared MyWBArg, oldlockbefore"
another shared variable to store the old dir which was the current dir
before we change it
2. the line "CurrentDir_(MyWBArg()\filelock)" is replaced with this one:
"oldlockbefore.l=CurrentDir_(MyWBArg()\filelock)"
this command sets our programdir as currentdir and stores the dir which
was the old currentdir in our variable
Changes in the example program:
1. the line "CurrentDir_(oldlockbefore)" is insert before the line
"ReplyMsg_(message)"
with this we set the currentdir back to the dir which was the current dir
before our program runs and changed it
Why this ?
You know this: download a program archive from aminet etc. unpacking it
and start the program to have a look. after that you want delete the
program directory and this failed with an error like "Cannot delete,
because object is in use". In many many times the reason is that
the program dir ist still the currentdir.
To avoid this i have changed the procedure.
Procedure.l OwnWBStartup()
owntask.l=FindTask_(0)
prcli.l=PeekL(owntask+172)
If prcli=0
messageport.l=owntask+92
WaitPort_(messageport)
wbstartupmessage.l=GetMsg_(messageport)
If wbstartupmessage0
Structure WBArgs
filelock.l
namearg.s
EndStructure
NewList MyWBArg.WBArgs()
Shared MyWBArg, oldlockbefore
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())
oldlockbefore.l=CurrentDir_(MyWBArg()\filelock)
EndIf
Else
ProcedureReturn 0
EndIf
ProcedureReturn wbstartupmessage
EndProcedure
ExecBase.l=OpenExecLibrary_(36)
DosBase.l=OpenDosLibrary_(36)
If ExecBase0 And DosBase0
message.l=OwnWBStartup()
If message=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")
CurrentDir_(oldlockbefore)
ReplyMsg_(message)
EndIf
Else
PrintN("Cannot open exec/dos.library")
EndIf
End
Greetings ..
Roxxler
Update Procedure OwnWBStartup()
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Roxxler.
your are right. I have done something stupid
Replace the line:
"Shared MyWBArg, oldlockbefore" with
"Shared MyWBArg, oldlockbefore.l"
and also replace the line:
"oldlockbefore.l=CurrentDir_(MyWBArg()\filelock)" with
"oldlockbefore=CurrentDir_(MyWBArg()\filelock)"
After that the procedure will run, but note
that there is still the bug i wrote about.
If you compile the procedure the first time the
executable is 2184 bytes long (with the changes
above). This executable will crash. Just compile
it once again and the executable is 2168 bytes
long. This will run. Strange ?!?!?!
At the moment i am not lucky with PureBasic. It makes
me silly You wrote a program, everything went fine,
no enforcerhits or such things, then add another procedure
or subprogram (which runs alone without any problems) and
suddenly there are enforcerhits. Sometimes you put the
procedure before another and this will cause an enforcerhit,
you put it behind another then there is no enforcerhit ?!?!?
No help, nothing. My activity at the moment is not to write
programs, it is just something like "write some lines and then
try to avoid enforcerhits", nothing more. Anyway, we need an
update of the Amiga version as soon as possible.
Greetings ..
Roxxler
Hi,i get a pe is diffirend than before
should declared as
Shared MyWBArg, oldlockbefore.l
however anyway its fails this prgram ???
propgram failde #80000004
chechkwbstartup is ok
christos
p.s. thanks a lot for the examples
your are right. I have done something stupid
Replace the line:
"Shared MyWBArg, oldlockbefore" with
"Shared MyWBArg, oldlockbefore.l"
and also replace the line:
"oldlockbefore.l=CurrentDir_(MyWBArg()\filelock)" with
"oldlockbefore=CurrentDir_(MyWBArg()\filelock)"
After that the procedure will run, but note
that there is still the bug i wrote about.
If you compile the procedure the first time the
executable is 2184 bytes long (with the changes
above). This executable will crash. Just compile
it once again and the executable is 2168 bytes
long. This will run. Strange ?!?!?!
At the moment i am not lucky with PureBasic. It makes
me silly You wrote a program, everything went fine,
no enforcerhits or such things, then add another procedure
or subprogram (which runs alone without any problems) and
suddenly there are enforcerhits. Sometimes you put the
procedure before another and this will cause an enforcerhit,
you put it behind another then there is no enforcerhit ?!?!?
No help, nothing. My activity at the moment is not to write
programs, it is just something like "write some lines and then
try to avoid enforcerhits", nothing more. Anyway, we need an
update of the Amiga version as soon as possible.
Greetings ..
Roxxler