thôi,tự xây dựng vậy
Mã:
/* Get Path Folder */
bool GetFolderPath_FromFullPath(__in TCHAR* tszPathIn,__out TCHAR* tszDirectory)
{
lstrcpy(tszDirectory,tszPathIn);
int ileng = lstrlen(tszDirectory);
int i;
for ( i = ileng -1;i>=0;i--)
{
if (tszDirectory[i] == _T('\\'))
{
tszDirectory[i] = _T('\0');
break;
}
}
if (i == 0)
{
tszDirectory = NULL;
return false;
}
return true;
}
bool GetCurrentFolder(__out TCHAR* tszPathOut,__in int iMaxPath)
{
TCHAR tszPathCurrentFile[MAX_PATH];
if (GetModuleFileName( NULL, tszPathCurrentFile, iMaxPath) == FALSE)
{
return false;
}
if (GetFolderPath_FromFullPath(tszPathCurrentFile,tszPathOut) == false)
{
tszPathOut = NULL;
return false;
}
return true;
}
Mình test tiếp với hàm _tgetcwd cũng hệt như hàm GetCurrentdirectory vậy,cũng ko lấy đúng đường dẫn của chương trình chạy nếu sử dụng hộp thoại run để chạy
Mã nguồn PHP:
#include <direct.h>#include <tchar.h>#include <Windows.h>/* Get Path Folder */bool GetFolderPath_FromFullPath(__in TCHAR* tszPathIn,__out TCHAR* tszDirectory){ lstrcpy(tszDirectory,tszPathIn); int ileng = lstrlen(tszDirectory); int i; for ( i = ileng -1;i>=0;i--) { if (tszDirectory[i] == _T('\\')) { tszDirectory[i] = _T('\0'); break; } } if (i == 0) { tszDirectory = NULL; return false; } return true;}bool GetCurrentFolder(__out TCHAR* tszPathOut,__in int iMaxPath){ TCHAR tszPathCurrentFile[MAX_PATH]; if (GetModuleFileName( NULL, tszPathCurrentFile, iMaxPath) == FALSE) { return false; } if (GetFolderPath_FromFullPath(tszPathCurrentFile,tszPathOut) == false) { tszPathOut = NULL; return false; } return true;}int main(){ TCHAR tszCurrentDirectory[MAX_PATH]; TCHAR tszFUn[MAX_PATH]; if (_tgetcwd(tszCurrentDirectory,MAX_PATH) == NULL) { return -1; } if (GetCurrentFolder(tszFUn,MAX_PATH) == false) { MessageBox(0,tszCurrentDirectory,_T("Error GetCurrentFolder"),0); return -2; } MessageBox(0,tszCurrentDirectory,tszFUn,0); return 0;}
Thêm 1 cách sử dụng nữa: sử dụng Commandline
Mã nguồn PHP:
bool GetCurrentDirectory_CommandLine(__out TCHAR* tszPathOut,__in int iMaxPath){ TCHAR* tszCommandLine = GetCommandLine(); int ileng = lstrlen(tszCommandLine); for (int i = 0;i<ileng;i++) { tszCommandLine[i] = tszCommandLine[i+1]; } if (GetFolderPath_FromFullPath(tszCommandLine,tszPathOut) == false) { tszPathOut = NULL; return false; } return true;}
Thông qua phân tích dữ liệu Google từ 86 quốc gia, mới đây, một công ty tại Anh đã công bố bảng xếp hạng kích tấc "cậu nhỏ" của các nước trên thế giới. Kết quả, hầu hết các nước xếp ở nhóm đầu của...
"Chim" của chàng trai Việt thuộc...