_pgmptr、_wpgmptr_pgmptr, _wpgmptr

可执行文件的路径。The path of the executable file. 已弃用;使用 _get_pgmptr_get_wpgmptrDeprecated; use _get_pgmptr and _get_wpgmptr.


extern char *_pgmptr;  
extern wchar_t *_wpgmptr;  


当程序从命令解释器 (Cmd.exe) 中运行时,_pgmptr 将自动初始化为可执行文件的完整路径。When a program is run from the command interpreter (Cmd.exe), _pgmptr is automatically initialized to the full path of the executable file. 例如,如果 Hello.exe 在 C:\BIN 中,而且 C:\BIN 在路径中,则执行时将 _pgmptr 设置为 C:\BIN\Hello.exe。For example, if Hello.exe is in C:\BIN and C:\BIN is in the path, _pgmptr is set to C:\BIN\Hello.exe when you execute:

C> hello   

当程序不是从命令行中运行时,_pgmptr 可能将初始化为程序名称(不带文件扩展名的基名称)或文件名称、相对路径或完整路径。When a program is not run from the command line, _pgmptr might be initialized to the program name (the file's base name without the file name extension) or to a file name, relative path, or full path.

_wpgmptr_pgmptr 的宽字符版本,可与使用 wmain 的程序一起使用。_wpgmptr is the wide-character counterpart of _pgmptr for use with programs that use wmain.

一般文本例程映射Generic-Text Routine Mappings

Tchar.h 例程Tchar.h routine 未定义 _UNICODE 和 _MBCS_UNICODE and _MBCS not defined 已定义 _MBCS_MBCS defined 已定义 _UNICODE_UNICODE defined
_tpgmptr _pgmptr _pgmptr _wpgmptr


变量Variable 必需的标头Required header
_pgmptr, _wpgmptr_pgmptr, _wpgmptr <stdlib.h><stdlib.h>


下面的程序说明 _pgmptr 的使用。The following program demonstrates the use of _pgmptr.

// crt_pgmptr.c  
// compile with: /W3  
// The following program demonstrates the use of _pgmptr.  
#include <stdio.h>  
#include <stdlib.h>  
int main( void )  
   printf("The full path of the executing program is : %Fs\n",   
     _pgmptr); // C4996  
   // Note: _pgmptr is deprecated; use _get_pgmptr instead  

您可通过将 _wpgmptr 更改为 %Fs 并将 %S 更改为 main,从而使用 wmainYou could use _wpgmptr by changing %Fs to %S and main to wmain.

请参阅See Also

全局变量Global Variables