| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | profile |
At 28.05.96 Tom Brown squeezed among other things this out of his/her keyboard:
TB> Now, I want to add the ability to find out where the .EXE was executed
TB> from and default to this path. This is Mike Bilow's idea and it seems
I do it this way, too. Here is the code:
------------------------- Schnipp -------------------------
/**************************************************************************
*
* Name : getPath
*
* Description: get the path to the program
*
* Parameters : prog - (IN) argv[0]... not used, i has to change it
* path - (OUT) path to exe with ending '\'
* On ERROR: NULL-string
* file - (OUT) pure name of the exe without extension
* On ERROR: NULL-string
*
* Return : [none]
*
*************************************************************************/
void getPath(char *prog, char *path, char *file)
{
APIRET rc = 0;
PPIB pib = NULL;
PTIB tib = NULL;
ULONG len = 0;
char filePath[CCHMAXPATH] = "",
*p = NULL,
*p2 = NULL;
strcpy(path, ""); // on error return
strcpy(file, ""); // empty strings
rc = DosGetInfoBlocks(&tib, &pib);
rc += DosQueryModuleName(pib->pib_hmte,
CCHMAXPATH,
filePath);
if (rc != 0)
return;
p = strrchr(filePath, '\\'); // find last backslash
if (p == NULL)
return;
p++;
len = p - filePath; // length of the path
memcpy(path, filePath, len); // copy path with slash
path[len] = '\0';
p2 = strrchr(p, '.'); // find last extension (.EXE)
if (p2 == NULL)
return;
len = p2 - p; // namelength
memcpy(file, p, len);
file[len] = '\0';
} /****************** End of getPath() ******************/
------------------------- Schnapp -------------------------
Hope, it helps.
Until the next mail...,
Stefan.
http://www.ruhr.de/home/acme2/
PGP fingerprint = 95 1E A4 B5 ED FB 78 EC 8C B9 D5 36 20 FB 23 68
!Achtung: Neuer Key!
---
* Origin: ACME Development +49-231-523397 (VFC,OS/2) (2:2444/1404)SEEN-BY: 50/99 270/101 620/243 711/401 409 410 413 430 808 809 934 955 SEEN-BY: 712/407 515 517 628 713/888 800/1 @PATH: 2444/1404 8000 5 24/888 396/1 270/101 712/515 711/808 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.