我正在尝试为我的代码设置一个特定的目录,它是一个 MFC 项目。已经编写了对话框代码(在 Visual Studio C++ 中),现在我将在不同的操作系统中使用此代码的 .exe 文件,并在我想要的目录中替换此文件。为了达到这个目标,我使用了GetModuleFileName函数。因此,按照这些建议,我将这段代码包含到我的代码的 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 文件。