Get program's name from WB

5 posts / 0 new
Last post
mritter0
mritter0's picture
Offline
Last seen: 2 years 6 months ago
Joined: 2014-04-21 21:15
Get program's name from WB

When starting my program from a Shell I can get the program's name via argv[0]. (What it is on disk)

How do I get when started from WB? I do this to check where started from:

  1. ThisProcess=(struct Process *)IExec->FindTask(NULL);
  2. if (ThisProcess->pr_CLI)
  3. {
  4. FromShell=TRUE;
  5. ......
  6. }
  7. else
  8. {
  9. FromShell=FALSE;
  10. ......
  11. }

I would like to get it from ThisProcess if possible.

Edit: Entire path would be good, too. Can get name from that if need to.

salass00
salass00's picture
Offline
Last seen: 6 months 2 weeks ago
Joined: 2011-02-03 11:27
Re: Get program's name from WB

If argc is 0 then your program was started from WB and argv will contain a pointer to a WBStartup structure.

  1. if (argc == 0) {
  2. // from WB
  3. struct WBStartup *wbmsg = (struct WBStartup *)argv;
  4. // ...
  5. } else {
  6. // from shell
  7. // ...
  8. }

wbmsg->sm_ArgList[0] will always point to your program similar to argv[0].

To convert the wbarg into a path you need to do:

  1. TEXT pathbuf[1024];
  2. struct WBArg *wbarg = &wbmsg->sm_ArgList[0];
  3. IDOS->DevNameFromLock(wbarg->wa_Lock, pathbuf, sizeof(pathbuf), DN_FULLPATH);
  4. IDOS->AddPart(pathbuf, wbarg->wa_Name, sizeof(pathbuf));
OldFart
OldFart's picture
Offline
Last seen: 3 months 2 weeks ago
Joined: 2010-11-30 14:09
Re: Get program's name from WB

@mritter0:

I don't know if that information is available through 'ThisProcess', but I use(d) these steps:
a: check whether argc is 0 as this indicates WB-started, in which case:
b: argv[0] holds a pointer to struct WBStartUp, which in turn:
c: in member 'sm_ArgList' holds a pointer to an array of struct WBArg, which in turn:
d: provides the members wa_Lock and wa_Name.

The first occurrance of struct WBArg containing the lock to the full fath of the program (IIRC) as well as the name of the program.

IIRC. I used to use something like this, but don't shoot me if I got it all wrong, as I haven't had my coffee yet:

  1. ((struct WBArg *)((struct WBStartup *)argv[0])->sm_ArgList)->wa_Lock
  2. ((struct WBArg *)((struct WBStartup *)argv[0])->sm_ArgList)->wa_Name

Hope this helps.

Regards
OldFart

EDIT: problem was addressed to already

trixie
trixie's picture
Offline
Last seen: 6 months 4 weeks ago
Joined: 2011-02-03 13:58
Re: Get program's name from WB

@mritter0

You may want to read this.

AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2

mritter0
mritter0's picture
Offline
Last seen: 2 years 6 months ago
Joined: 2014-04-21 21:15
Re: Get program's name from WB

Thanks, guys.

I had one of those 2:00AM "oh duh!" moments and figured out my problem. I was close. But I did pick up an idea from the examples!

Log in or register to post comments