獲取工程運行路徑源代碼
string GetProgramDir()
{
char exeFullPath[MAX_PATH]; // Full path
string strPath = "";
GetModuleFileName(NULL,exeFullPath,MAX_PATH);
strPath=(string)exeFullPath; // Get full path of the file
int pos = strPath.find_last_of('\\', strPath.length());
return strPath.substr(0, pos); // Return the directory without the file name
}
執行結果:
ocx:會是IE路徑安裝路徑
EXE:exe所在文件夾
獲取工程當前路徑源代碼
string GetCurrentDir(const string &path){
string ls_FileName;
LPTSTR lpBuffer;
UINT uSize;
HANDLE hHeap;
uSize=(GetCurrentDirectory(0,NULL))*sizeof(TCHAR);
hHeap=GetProcessHeap();
lpBuffer=(LPSTR)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,uSize);
GetCurrentDirectory(uSize,lpBuffer);
ls_FileName = (string) lpBuffer;
ls_FileName.append(path);
return ls_FileName;
}
執行結果:
ocx:會是用戶桌面
EXE:運行該exe工程的文件夾路徑
debug:(工程名AAA)