INF: Using _pgmptr to Get the Full Path of Executing Program

ID Number: Q47037

5.10 6.00 6.00a 6.00ax 7.00 | 5.10 6.00 6.00a

MS-DOS | OS/2

Summary:

In Microsoft C versions 5.0, 5.1, 6.0, 6.0a, 6.0ax, and C/C++ version

7.0, the variable _pgmptr is not defined in an include file. It is

declared in CRT0DAT.ASM, which is part of the C startup code. This

code is linked to any module that contains a main() function. To use

_pgmptr, you must first declare it as an external far character

pointer, as follows

extern char far *_pgmptr;

Because _pgmptr is automatically initialized at startup to point to

the full path of the executing program, only this declaration is

required to make the full path available to your program.

More Information:

The following program demonstrates the usage of _pgmptr:

#include <stdio.h>

extern char far *_pgmptr;

void main(void)

{

printf ("The full path of the executing program is : %Fs\n", _pgmptr);

}

In OS/2 real mode or MS-DOS 3.x, argv[0] also contains a pointer to

the full path of the executing program. In OS/2 protected mode,

argv[0] contains only the information typed at the command line to

invoke the program. Therefore, in OS/2 protected mode, using _pgmptr

is the only way to easily access the executing program's full path

string.

Additional reference words: 5.00 5.10 6.00 6.00a 6.00ax 7.00