我想爲我的代碼設置一個特定的目錄,這是一個MFC項目。已經編寫了一個對話框的代碼(在visual studio C++中),現在我將在不同的操作系統中使用該代碼的.exe文件,並將這個文件替換爲我想要的那個目錄。在這個目標到達,我用GetModuleFileName function.Therefore,按照these建議我包括這一段代碼的OnInitDialog()我的代碼功能:如何爲不同的操作系統設置可執行文件的目錄?
//function that gets the directory without the file name:
TCHAR szFilePath[_MAX_PATH];
TCHAR driveLetter[3];
TCHAR directory[MAX_PATH];
TCHAR FinalPath[MAX_PATH];
::GetModuleFileName(NULL, szFilePath, _MAX_PATH);//Retrieves the current directory for the current process.
// Add all the files and directories in the windows directory.
//VERIFY(0 < ::GetWindowsDirectory(lpszWinPath, MAX_PATH));
// Make the windows directory the current directory.
::GetCurrentDirectory(MAX_PATH, lpszOldPath);
//::SetCurrentDirectory(lpszWinPath);
::SetCurrentDirectory("C:\\Program Files");
不過,現在我沒有得到任何錯誤信息但我不知道爲什麼我看不到任何輸出。作爲一個例子,我期望在指定的目錄中創建一個.exe文件。
你在做什麼Windows目錄? – MSalters
是的,從代碼 – Braian
跳過「我不知道爲什麼我看不到任何輸出」:這是因爲您提供的代碼沒有生成輸出。 –