1、Windows下的获得当前可履行文件的路径和当前工程目录。
(1)获得当前可履行文件路径:
#include <shlwapi.h>
#pragma comment(lib,"shlwapi.lib")
wchar_t szExePath[MAX_PATH] = {0};
GetModuleFileNameW(NULL,szExePath,sizeof(szExePath));
PathRemoveFileSpecW(szExePath);
(2)如果想获得当前工程的路径的话可使用下面的函数:(1)获得当前可履行文件路径:
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
size_t GetCurrentExcutableFilePathName( char* processdir,char* processname,size_t len)
{
char* path_end;
if(readlink("/proc/self/exe",processdir,len) <=0)
return ⑴;
path_end = strrchr(processdir,'/');
if(path_end == NULL)
return ⑴;
++path_end;
strcpy(processname,path_end);
*path_end = '