Q47037: Using _pgmptr to Get the Full Path of the Executing Program
Article: Q47037
Product(s): See article
Version(s): 5.10 | 5.10
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | | mspl13_c
Last Modified: 8-AUG-1989
Question:
On Page Update-23 of the "Version 5.10 Update" to the Microsoft C 5.10
Optimizing Compiler, there is a description of the variable _pgmptr.
The documentation states that _pgmptr points to a string containing
the full pathname of the invoked program, but does not describe how to
use it. I can't find _pgmptr in any of the include files. Where is
_pgmptr declared and how do I use it?
Response:
The variable _pgmptr is not defined in an include file. It is declared
in CRT0DAT.ASM, which is part of the C start-up code. This code is
linked in 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;
Since _pgmptr is automatically initialized at start-up to point to the
full pathname of the executing program, this declaration is all that
is required to make the full pathname available to your program.
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 DOS 3.x, argv[0] also contains a pointer to the
full pathname 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 pathname
string.
THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.
Copyright Microsoft Corporation 1986-2002.