①GetModuleFileName:获取模块的完整路径
The GetModuleFileName function retrieves the full path and filename for the executable file containing the specified module.
DWORD GetModuleFileName( HMODULE hModule, // handle to module to find filename for LPTSTR lpFilename, // pointer to buffer to receive module path DWORD nSize // size of buffer, in characters
);
- hModule
- Handle to the module whose executable filename is being requested. If this parameter is NULL,GetModuleFileName returns the path for the file used to create the calling process. lpFilename
- Pointer to a buffer that is filled in with the path and filename of the given module. nSize
- Specifies the length, in characters, of the lpFilename buffer. If the length of the path and filename exceeds this limit, the string is truncated.
Return Values
If the function succeeds, the return value is the length, in characters, of the string copied to the buffer.
If the function fails, the return value is zero. To get extended error information, callGetLastError.
Remarks
If a module is loaded in two processes, its module filename in one process may differ in case from its module filename in the other process.
②system, _wsystem
Execute a command.
int system( const char *command);
int _wsystem( const wchar_t *command);
Parameter
command
Command to be executed
Remarks
The system function passes command to the command interpreter, which executes the string as an operating-system command.system refers to theCOMSPEC andPATH environment variables that locate the command-interpreter file (the file named CMD.EXE in Windows NT). Ifcommand is NULL, the function simply checks to see whether the command interpreter exists.
③GetCurrentDirectoryA()
获取当前的工作目录,注意,当你用VC编译源码的时候,该函数获取的工作目录是包含.cpp文件的目录,而当你编译完成之后去运行可执行文件的时候,获取的工作目录却是包含可执行文件的目录。
//将一个路径与一个文件名合成路径
PathCombineW(&pszPath, pszPrefix, *(LPCWSTR *)file_name)
//检查路径的前缀
PathIsPrefixW(pszPrefix, &pszPath)
//路径去文件名
PathRemoveFileSpecW(&pszPath)
//另一个创建目录的函数
SHCreateDirectoryExW(0, pszPath, 0)