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. Java 学习 时间格式化(SimpleDateFormat)与历法类(Calendar)用法详解

    基于Android一些时间创建的基本概念 获取当前时间 方式一: Date date = new Date(); Log.e(TAG, "当前时间="+date); 结果: E/T ...

  2. eclipse总结source folder和Deployment Assembly部署

    在src下创建多级目录 然后右键build path-->use as source folder 就可以直接将多级普通文件夹转换成source folder build path下也可以直接n ...

  3. Erlang学习记录:运算符

    数学运算符 说明 详细 符号 加减乘 +-* 浮点数除 结果为浮点数 / 整数除 除数和被除数都必须是整数,结果为整数 div 整数取余 rem 逻辑运算符 说明 符号 详细 and 前后两个值都为真 ...

  4. 【JZOJ6273】欠钱

    description analysis 读懂题就可知\(b\)的收益即为\(a\)到\(b\)这一条链上边权的最小值 那么就是动态维护一个森林,询问链上最小值,同时必须满足儿子走向父亲 明显\(LC ...

  5. dp转图论——cf1070A好题

    dp的状态转移很像一张有向图:每个状态为一个点,每中转移方案是一条有向边 本题要求是求出最小的数,那我们用状态[i,j]表示模i,数位和为j,那么从每个点出发的十条有向边代表[0,9]十个数 从每个状 ...

  6. jedis3.1.0在weblogic(jdk1.6)中无法运行

    文章目录 错误 探索 总结 错误 在tomcat中运行是没有问题的,可是在weblogic中是不能够运行的,weblogic中的jdk客户要求是1.6的. 如果更换版本jedis2.9.0是没有问题的 ...

  7. Docker系列(四):Docker容器互联

    基于Volume的互联 为什么需要Volume docker文件系统是分层的,下面的是全部是只读的,最上面的是可写层,容器中的进程如果修改了某个文件,比如修改了下层的某个文件,其实是在最顶层复制下层文 ...

  8. 4_3.springboot2.x之默认访问首页和国际化

    1.默认访问首页 1.引入thymeleaf和引入bootstrap <!--引入thymeleaf--> <dependency> <groupId>org.sp ...

  9. spark 应用场景1-求年龄平均值

    原文引自:http://blog.csdn.net/fengzhimohan/article/details/78535143 该案例中,我们将假设我们需要统计一个 10 万人口的所有人的平均年龄,当 ...

  10. nodejs的安装和环境配置

    在安装npm的时候可能会报错, 可以按准过cnpm时淘宝在国内的npm镜像 命令如下:npm install -g cnpm --registry=https://registry.npm.taoba ...