GetCurrentDirectory Function
来源:互联网 发布:大学生java实训学校 编辑:程序博客网 时间:2024/06/07 06:19
Retrieves the current directory for the current process.检索应用程序的当前工作目录。
Syntax
DWORD WINAPI GetCurrentDirectory( __in DWORD nBufferLength, __out LPTSTR lpBuffer);
Parameters 参数
The length of the buffer for the current directory string, in TCHARs. The buffer length must include room for a terminating null character.
缓冲区的长度为当前工作目录,缓冲区的长度必须包括一个终止空字符。
A pointer to the buffer that receives the current directory string. This null-terminated string specifies the absolute path to the current directory.To determine the required buffer size, set this parameter to NULL and thenBufferLength parameter to 0.
一个得到当前工作目录字符的缓冲区的指针。这个结尾的字符串确定绝对的路径到当前工作目录。为了确定要求的缓冲区的大小,设置这个参数为空并且nBufferLength参数为0。
Return Value
If the function succeeds, the return value specifies the number of characters that are written to the buffer, not including the terminating null character.
If the function fails, the return value is zero. To get extended error information, callGetLastError.
If the buffer that is pointed to by lpBuffer is not large enough, the return value specifies the required size of the buffer, in characters, including the null-terminating character.
Remarks
Each process has a single current directory that consists of two parts:
磁盘指示符,要么是驱动器后面加上冒号,要么是形如\\服务器名称\分享名称。
To set the current directory, use the SetCurrentDirectory function.
In certain rare cases, if the specified directory is on the current drive, the function might omit the drive letter and colon from the path. Therefore, the size that is returned by the function might be two characters less than the size of the specified string, not including the terminating null character. This behavior might occur in edge situations such as in a services application. If you need the drive letter, make a subsequent call toGetFullPathName to retrieve the drive letter.
Example Code
The directory at the end of the active path is called the current directory; it is the directory in which the active application started, unless explicitly changed. An application can determine which directory is current by calling theGetCurrentDirectory function.
An application can change the current directory by calling the SetCurrentDirectory function.
The following example demonstrates the use of GetCurrentDirectory andSetCurrentDirectory.
#include <windows.h> #include <stdio.h>#include <tchar.h>#define BUFSIZE MAX_PATH void _tmain(int argc, TCHAR **argv) { TCHAR Buffer[BUFSIZE]; DWORD dwRet; if(argc != 2) { _tprintf(TEXT("Usage: %s <dir>\n"), argv[0]); return; } dwRet = GetCurrentDirectory(BUFSIZE, Buffer); if( dwRet == 0 ) { printf("GetCurrentDirectory failed (%d)\n", GetLastError()); return; } if(dwRet > BUFSIZE) { printf("Buffer too small; need %d characters\n", dwRet); return; } if( !SetCurrentDirectory(argv[1])) { printf("SetCurrentDirectory failed (%d)\n", GetLastError()); return; } _tprintf(TEXT("Set current directory to %s\n"), argv[1]); if( !SetCurrentDirectory(Buffer) ) { printf("SetCurrentDirectory failed (%d)\n", GetLastError()); return; } _tprintf(TEXT("Restored previous directory (%s)\n"), Buffer);}
- GetCurrentDirectory function
- GetCurrentDirectory Function
- GetCurrentDirectory
- GetCurrentDirectory()
- GetModuleFileName& GetCurrentDirectory
- GetCurrentDirectory 理解
- GetModuleFileName& GetCurrentDirectory
- GetCurrentDirectory & GetModuleFileName
- GetCurrentDirectory,SetCurrentDirectory
- GetCurrentDirectory获得当前目录
- GetCurrentDirectory的使用(SDK)
- GetCurrentDirectory和SetCurrentDirectory函数
- GetCurrentDirectory的一个问题
- GetCurrentDirectory 与GetModuleFileName
- GetCurrentDirectory 和 GetModuleFileName 区别
- GetCurrentDirectory 和 GetModuleFileName区别
- GetCurrentDirectory、SetCurrentDirectory和GetModuleFileName
- GetCurrentDirectory和SetCurrentDirectory
- 在一个FORM中如何实现多个ACTION动作
- 重装系统
- Java Console I/O Java控制台输入与输出
- 直接选择排序 知识点小结
- linux系统下文件的权限
- GetCurrentDirectory Function
- 电脑漏电的解决
- linux文件
- git初体验
- 中层领导(管理能力)
- 文章0:Nginx整体分析
- 截取数字
- 黑马程序员_java网络编程
- 29c3ctf web100 regexdb writeup