一、GetCurrentDirectory
The GetCurrentDirectory function retrieves the current directory for the current process.
DWORD GetCurrentDirectory( DWORD nBufferLength, // size of directory buffer LPTSTR lpBuffer // directory buffer );
本人生成happy.exe, 为了方便说明,将其放到d:/
进入dos:
d:
happy "d:/else" // 假如存在else 目录
运行结果:
CurrentDirectory: D:/
Set current directory to d:/Else
CurrentDirectory: d:/Else
二、GetModuleFileName
The GetModuleFileName function retrieves the fully qualified path for the specified module.
To specify the process that contains the module, use the GetModuleFileNameEx function.
DWORD GetModuleFileName( HMODULE hModule, // handle to module LPTSTR lpFilename, // path buffer DWORD nSize // size of buffer );
Parameters
-
hModule
- [in] Handle to the module whose path is being requested. If this parameter is NULL, GetModuleFileName retrieves the path for the current module.
// 如下代码, 假如其在 d:/Project/Test/MFC/MFC/dir.cpp 里