1.获得程序自身的路径:

DWORD GetModuleFileName(
HMODULE
hModule, // handle to module
LPTSTR lpFilename, // path buffer
DWORD nSize // size of buffer
);
参数说明:
hModudle :[in] Handle to the module whose path is being requested. If this parameter is NULL, GetModuleFileName retrieves the path for the current module.
lpFilename: [out] Pointer to a buffer that receives the fully-qualified path for the module. If the length of the string exceeds the size specified by the nSize parameter, the string is truncated.
nSize:[in] Specifies the length of the lpFilename buffer, in TCHARs. 返回值:

If the function succeeds, the return value is the length of the string copied to the buffer, in TCHARs.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

2. 获取windows目录

UINT GetWindowsDirectory(
LPTSTR
lpBuffer, // buffer for Windows directory
UINT uSize // size of directory buffer
);
参数说明:
lpBuffer: [out] Pointer to the buffer to receive the null-terminated string containing the path. This path does not end with a backslash unless the Windows directory is the root directory. For example, if the Windows directory is named Windows on drive C, the path of the Windows directory retrieved by this function is C:\Windows. If the system was installed in the root directory of drive C, the path retrieved is C:\
 uSize:  [in] Specifies the maximum size, in TCHARs, of the buffer specified by the lpBuffer parameter. This value should be set to MAX_PATH+1 to allow sufficient space for the path and the null terminator. 

返回值: 
f the function succeeds, the return value is the length, in TCHARs,
of the string copied to the buffer, not including the terminating null
character. If the length is greater than the size of the buffer, the return value is the
size of the buffer required to hold the path.If the function fails, the return value is zero. To get extended error
information, call GetLastError. 3. 获取系统目录
UINT GetSystemDirectory(
LPTSTR
lpBuffer, // buffer for system directory
UINT uSize // size of directory buffer
);
参数说明:
lpBuffer
[out] Pointer to the buffer to receive the null-terminated string containing the path. This path does not end with a backslash unless the system directory is the root directory. For example, if the system directory is named Windows\System on drive C, the path of the system directory retrieved by this function is C:\Windows\System.
uSize:[in] Specifies the maximum size of the buffer, in TCHARs. This value should be set to at least MAX_PATH+1 to allow sufficient space for the path and the null terminator.

返回值判断:

If the function succeeds, the return value is the length, in TCHARs, of the string copied to the buffer, not including the terminating null character. If the length is greater than the size of the buffer, the return value is the size of the buffer required to hold the path.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Windows API 第三篇的更多相关文章

  1. windows API 第22篇 WTSGetActiveConsoleSessionId

    函数原型:DWORD WTSGetActiveConsoleSessionId (VOID)先看一下原文介绍: The WTSGetActiveConsoleSessionId function re ...

  2. Windows API 第19篇 FindFirstVolumeMountPoint FindNextVolumeMountPoint

    相关函数:HANDLE FindFirstVolumeMountPoint(                                                               ...

  3. windows API 第13篇 MoveFileEx

    上一篇介绍了MoveFile,这次分析MoveFileEx,它是MoveFile的扩展函数,功能还要更加强大些.先看定义: BOOL WINAPI MoveFileEx( _In_     LPCTS ...

  4. Windows API 第六篇 GetLocalTime

    GetLocalTime获取系统时间信息.函数原型:VOID   WINAPI  GetLocalTime(    __out LPSYSTEMTIME lpSystemTime    ); 先来看S ...

  5. Windows API 第21篇 DeleteVolumeMountPoint 删除挂载点

    函数原型:BOOL DeleteVolumeMountPoint(                                                      LPCTSTR lpszV ...

  6. Windows API 第20篇 SetVolumeMountPoint 设置卷挂载点参数错误

    函数原型:BOOL SetVolumeMountPoint(                                                   IN   LPCTSTR lpszVo ...

  7. Windows API 第20篇 GetVolumeNameForVolumeMountPoint

    函数原型: BOOL GetVolumeNameForVolumeMountPoint(                                                        ...

  8. windows API 第 18篇 FindFirstVolume FindNextVolume

    函数定义:Retrieves the name of a volume on a computer. FindFirstVolume is used to begin scanning the vol ...

  9. Windows API 第17篇 GetLogicalDriveStrings 获取本机所有逻辑驱动器,以根目录的形式表示

    函数原型:DWORD GetLogicalDriveStrings(  DWORD nBufferLength,  // size of buffer                          ...

随机推荐

  1. Android开发 View的UI刷新Invalidate和postInvalidate

    Invalidate 正常刷新 /** * 使整个视图无效.如果视图可见, * {@link #onDraw(android.graphics.Canvas)} 调用此方法后将在后续的UI刷新里调用o ...

  2. drop大表

    删除大表: .给对应表的ibd文件建立硬链接,因为表的数据和索引都在该文件中. ln /home/work/status.ibd /home/work/status.ibd.hdlk .主库上删除表, ...

  3. [JZOJ3235] 数字八

    题目 题目大意 给你一个二维的图,其中.代表完好,*代表有缺陷. 现在要在图上刻一个数字\(8\),满足: 由两个矩形组成. 每个矩形中必须有空隙在内部,也就是说,至少为\(3*3\)的矩形. 上矩形 ...

  4. [JZOJ4665] 【GDOI2017模拟7.21】数列

    题目 题目大意 给你一个数列,让你找到一个最长的连续子序列,满足在添加了至多KKK个数之后,能够变成一条公差为DDD的等差数列. 思考历程 一眼看上去似乎是一道神题-- 没有怎么花时间思考,毕竟时间都 ...

  5. 校园商铺-2项目设计和框架搭建-6逐层完成SSM的各项配置

    1. 创建/src/main/resources/jdbc.properties文件 jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://l ...

  6. SDOI2018

    SD的题有点反人类啊... d1t1[SDOI2018]物理实验 感觉比较好想但不太好写,写了一半弃了 d1t2[SDOI2018]战略游戏 建出圆方树,每次建虚树,答案就是虚树上的原点个数减去询问的 ...

  7. windows下,根据端口号杀死进程

    1.cmd下,根据端口号查询进程号 C:\>netstat -ano|findstr " 2.根据进程号928,在任务管理器杀死PID为928进程 注意:默认情况下,进程选项卡里没有P ...

  8. day 67 Django基础三之视图函数

    Django基础三之视图函数   本节目录 一 Django的视图函数view 二 CBV和FBV 三 使用Mixin 四 给视图加装饰器 五 Request对象 六 Response对象 一 Dja ...

  9. 出现java.lang.NoClassDefFoundError: org/apache/commons/collections/FastHashMap错误问题解决

    首先出现这个问题,你应该是用了 BeanUtils.populate(meter,map); import org.apache.commons.beanutils.BeanUtils;并且导入了co ...

  10. 收藏的链接-Qt

    Qt编写的开源帖子集合(懒人专用) - QTCN开发网 - Powered by phpwind http://www.qtcn.org/bbs/read-htm-tid-85501.html?tds ...