char exePath[LEN_PATH]={0};
GetModuleFileName(NULL,exePath,LEN_PATH); // 得到exe文件的绝对路径
strrchr( exePath, '\\')[0]= '\0';
GetModuleFileName(NULL,exePath,LEN_PATH); // 得到exe文件的绝对路径
strrchr( exePath, '\\')[0]= '\0';
printf("exePath: %s\n",exePath);
exePath 为程序入口的路径
比如test1:
int main()
{
FILE *fd = fopen("test1.txt","w");
fclose(fd);
char exePath[LEN_PATH]={0};
GetModuleFileName(NULL,exePath,LEN_PATH); // 得到exe文件的绝对路径
strrchr( exePath, '\\')[0]= '\0';
printf("exePath: %s\n",exePath);
return 0;
}
test2:
int main()
{
int x;
x = system("test1.exe");
printf("x:%d\n",x);
system("pause");
return 0;
}
运行test2.exe得到如下结果,获得的是test2.exe路径,不是test1.exe