windows API 第 11 篇 GetCurrentDirectory SetCurrentDirectory
GetCurrentDirectory函数获得当前文件所在的目录,并不是进程的目录(debug 和 release),它和GetCommandLine不同
这里只讲
#ifdef UNICODE
#define GetCurrentDirectory GetCurrentDirectoryW
#else
#define GetCurrentDirectory GetCurrentDirectoryA
#endif // !UNICODE
看一下定义:
//获得当前文件所在目录:
DWORD GetCurrentDirectory(
DWORD nBufferLength, // size of directory buffer
LPTSTR lpBuffer // directory buffer);
参数都比较简单,不做过多的介绍。
返回值:调用成功则返回写入lpBuffer的字符个数,不包括'\0',失败则返回0,
如果缓冲区的长度不够,则函数返回实际需要的缓冲区大小,包括'\0'。
//设置当前目录:
BOOL SetCurrentDirectory( LPCTSTR lpPathName // new directory name
);
举例说明:
char szDir1[MAX_PATH] = { 0 };
DWORD dwLen1 = GetCurrentDirectoryA(MAX_PATH, szDir1);
WCHAR *pDir2 = NULL;
DWORD dwLen2 = GetCurrentDirectory(0, pDir2);
pDir2 = new WCHAR[dwLen2];
DWORD dwLen = GetCurrentDirectory(dwLen2, pDir2);
delete []pDir2;
windows API 第 11 篇 GetCurrentDirectory SetCurrentDirectory的更多相关文章
- windows API 第22篇 WTSGetActiveConsoleSessionId
函数原型:DWORD WTSGetActiveConsoleSessionId (VOID)先看一下原文介绍: The WTSGetActiveConsoleSessionId function re ...
- windows API 第13篇 MoveFileEx
上一篇介绍了MoveFile,这次分析MoveFileEx,它是MoveFile的扩展函数,功能还要更加强大些.先看定义: BOOL WINAPI MoveFileEx( _In_ LPCTS ...
- Windows API 第六篇 GetLocalTime
GetLocalTime获取系统时间信息.函数原型:VOID WINAPI GetLocalTime( __out LPSYSTEMTIME lpSystemTime ); 先来看S ...
- Windows API 第三篇
1.获得程序自身的路径: DWORD GetModuleFileName( HMODULE hModule, // handle to module LPTSTR lpFilename, // pat ...
- Windows API 第21篇 DeleteVolumeMountPoint 删除挂载点
函数原型:BOOL DeleteVolumeMountPoint( LPCTSTR lpszV ...
- Windows API 第20篇 SetVolumeMountPoint 设置卷挂载点参数错误
函数原型:BOOL SetVolumeMountPoint( IN LPCTSTR lpszVo ...
- Windows API 第20篇 GetVolumeNameForVolumeMountPoint
函数原型: BOOL GetVolumeNameForVolumeMountPoint( ...
- Windows API 第19篇 FindFirstVolumeMountPoint FindNextVolumeMountPoint
相关函数:HANDLE FindFirstVolumeMountPoint( ...
- windows API 第 18篇 FindFirstVolume FindNextVolume
函数定义:Retrieves the name of a volume on a computer. FindFirstVolume is used to begin scanning the vol ...
随机推荐
- CSIC_716_20191108【文件的操作,以及彻底解决编码问题的方案】
关于编码的问题: 在平时编写代码,涉及到打开文件时,常常遇到字符编码的报错, 通过总结,得出以下规律 如果在操作过程中涉及到调用文本文档,一定要在文本文档开头申明编码方式(# coding:XXXX ...
- day31 类的组合及继承,文件目录规范
Python之路,Day18 = Python基础18-面向对象继承与组合 类的继承 def talk(): print("I am come from talk..a") cla ...
- hdu多校第四场1001 (hdu6614) AND Minimum Spanning Tree 签到
题意: 一个完全图,某两点边权为这两点编号之按位与,求最小生成树,输出字典序最小的. 题解: 如果点数不为$2^n-1$,则每一点均可找到一点,两点之间边权为0,只需找到该点二进制下其最左边的0是第几 ...
- spingboot linux 启动方式与脚本
java -jar XXX.jar java -jar xxx.jar & 区别:前台启动ctrl+c就会关闭程序,后台启动ctrl+c不会关闭程序 java -jar xxx.jar > ...
- 命令学习_nslookup
nslookup 域名 这是最常用最简单的用法,可以直接获得目标域名的IP地址和CNAME. 如下是A记录的返回情况 nslookup命令会采用先反向解释获得使用的DNS服务器的名称,上图中ns.gu ...
- PAT甲级——A1116 Come on! Let's C
"Let's C" is a popular and fun programming contest hosted by the College of Computer Scien ...
- <随便写> 多线程的例子
''' 一个线程在使用这个共享的时候,其他线程必须等待他结束 通过"锁"实现,作用就是防止多个线程使用这片内存空间 进程:程序的一次执行 线程:cpu运算的基本调度单位 多线程:大 ...
- ListControl 设置表格行高与字体
设置行高: CImageList m_l; m_l.Create(1,18,TRUE|ILC_COLOR32,1,0); listCtrl.SetImageList(&m_l,LVS ...
- 如何将存储在MongoDB数据库中的数据导出到Excel中?
将MongoDB数据库中的数据导出到Excel中,只需以下几个步骤: (1)首先,打开MongoDB安装目录下的bin文件夹,(C:\Program Files (x86)\MongoDB\Serve ...
- Codeforces 839D Winter is here
链接:CF839D 题目大意 给定一个数组大小为\(n(1\leq n\leq 200000)\)的数组\(a\),满足\(1\leq a_i \leq 1000000\). 选择其中任意\(len\ ...