关于GetSystemDirectory function,参考:https://msdn.microsoft.com/en-us/library/windows/desktop/ms724373(v=vs.85).aspx

以下代码摘自Getting System Information(https://msdn.microsoft.com/en-us/library/windows/desktop/ms724426(v=vs.85).aspx)。

IDE: Microsoft Visual Studio Community 2017 15.5.2

操作系统:Windows 7 x64

  1. #include "stdafx.h" /* IDE自行创建的 */
  2.  
  3. #include <windows.h>
  4.  
  5. #define INFO_BUFFER_SIZE 21
  6.  
  7. int main(int argc, char **argv)
  8. {
  9. TCHAR infoBuf[INFO_BUFFER_SIZE];
  10. UINT RetSize;
  11.  
  12. RetSize = GetSystemDirectory(infoBuf, INFO_BUFFER_SIZE);
  13. // RetSize = 0;
  14. if ((RetSize != ) && (RetSize <= INFO_BUFFER_SIZE)) {
  15. // If the function succeeds, the return value is the length, in TCHARs, of the string copied to the buffer,
  16. // not including the terminating null character.
  17.  
  18. // Display the system directory.
  19. printf("System Directory: %ls", infoBuf);
  20. }
  21. else if (RetSize > INFO_BUFFER_SIZE) {
  22. // If the length is greater than the size of the buffer,
  23. // the returnv alue is the size of the buffer required to hold the path,
  24. // including the terminating null character.
  25. printf("The size of the buffer is not enough, need %d TCHARs at least. \n", RetSize);
  26. }
  27. else {
  28. // If the function fails, the return value is zero. To get extended error information, call GetLastError.
  29. printf("Get system directory failed with error: %d", GetLastError());
  30. }
  31.  
  32. getchar();
  33.  
  34. return ;
  35. }

可以修改INFO_BUFFER_SIZE的值,改变程序的运行结果。

也可以去掉RetSize = 0;前面的注释,模拟错误(实际上不是错误,我只是用来测试if语句的条件)。

不知道是否存在BUG???

  1.  

C++ GetSystemDirectory()的更多相关文章

  1. GetWindowsDirectoryA and GetSystemDirectory

    #include <iostream> #include <Windows.h> using std::cout; using std::endl; // 获取Windows文 ...

  2. C# Windows API

    API:应用程序接口(API:Application Program Interface)应用程序接口(API:application programming interface)是一组定义.程序及协 ...

  3. Windows API 函数列表 附帮助手册

    所有Windows API函数列表,为了方便查询,也为了大家查找,所以整理一下贡献出来了. 帮助手册:700多个Windows API的函数手册 免费下载 API之网络函数 API之消息函数 API之 ...

  4. asp.net mvc4 简单的服务器监控开发之C#获取服务器CPU、RAM、TCP等系统信息(上)

    一.背景 前段时间服务器出了点问题,加上学业愈来愈紧张,写博文分享的时间越来越少.虽然不是第一次在博客园上写经验,但是近期分享的博文得到了不少的朋友支持和指正,在这里内心非常感激和开心.希望以后能认真 ...

  5. C语言操作注册表 写入 读取信息

    #include <stdio.h>#include <windows.h>int main(void){char regname[]="Software\\Micr ...

  6. 转:Delphi 6 实用函数

    来自: daocaoren0824, 时间: -- ::, ID: 再给你一份 程序员实用函数 {▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎} {▎ ▎} {▎ 大 ...

  7. DELPHI实现关闭指定进程,自身防杀

    偶然翻到很久以前用DELPHI写的一个小程序,实现功能是在后台默默关闭符合条件的进程,并隐藏自身.编写目的是为了防止办公电脑运行游戏. 实现原理是: 1.程序运行后将自身以不同的名称一式三份存到系统各 ...

  8. C#:获取环境信息

    外部环境数据1.需要管理员权限2.需要安装office2003以上完整版3.需要安装flash reader 10.0以上4.需要安装adodb reader;Adobe Acrobat X Pro; ...

  9. WinPipe后门程序代码示例(仅限技术交流)

    具体怎么编译,生成执行程序,不懂得先学习C++程序代码编译和集成开发环境. 多的不说了,只有两个代码文件,一个头文件,一个源文件.不多说了,直接上干货. (恶意使用,或者商用,后果自负,与本人无关.) ...

随机推荐

  1. react-踩坑记录——iconfont

    选取图标,添加至购物车后,下载代码. 后将下载了的文件夹改名,放入css文件夹中.在组件中使用到的时候按路径引入“iconfont.css”文件即可. 使用

  2. PL/SQL 加字段 修改数据库之后 之后记得保存脚本

  3. C++ 仿函数

    先考虑一个简单的例子:假设有一个vector<string>,你的任务是统计长度小于5的string的个数,如果使用count_if函数的话,你的代码可能长成这样: 1 bool Leng ...

  4. Spring Bean自动检测

    1-自动检测bean 需要用到<context:component-scan> 注意:a) 需要include进来xmlns:context命名空间:base-package指的是我们要扫 ...

  5. 【运维】略谈Raid级别

    *何为Raid?          Raid就是磁盘阵列(Redundant Arrays of Independent Disks,RAID),有"独立磁盘构成的具有冗余能力的阵列&quo ...

  6. WINDOWS系统中常用网络命令及命令实例详解

    一.查询DNS.IP,mac地址及DHCP服务的情况 二.查看ARP表:MAC地址与IP地址的映射表 三.查看共享资源 四.查看局域网内的主机名 五.查看用户列表  六.路由跟踪命令 七.查看共享资源 ...

  7. linux c 时间函数

    1. time() 函数提供了 秒 级的精确度 time_t time(time_t * timer) 函数返回从UTC1970-1-1 0:0:0开始到现在的秒数 2. struct timespe ...

  8. 我理解的vue生命周期

    说些题外话,引出vue的生命周期. 比如人出生到寿终正寝,这是人的一个生命周期.他会经历出生,婴儿时期,童年时期,少年时期,青年,中年,老年,到 end.然后,每个时期都会有一定的历史任务在等着去完成 ...

  9. ansible笔记(11):初识ansible playbook(二)

    ansible笔记():初识ansible playbook(二) 有前文作为基础,如下示例是非常容易理解的: --- - hosts: test211 remote_user: root tasks ...

  10. luasocket 安装记录 (FS1.4)

    说明:FS 1.4 使用的lua 5.2 ,需要使用luasocket 3.0 以上. 本文以FS 1.4 && luasocket 3.0 为基础,记录安装使用过程. 一.下载 &a ...