我想为我的代码设置一个特定的目录,这是一个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
跳过“我不知道为什么我看不到任何输出”:这是因为您提供的代码没有生成输出。 –