关于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

 #include "stdafx.h"    /* IDE自行创建的 */

 #include <windows.h>

 #define INFO_BUFFER_SIZE 21

 int main(int argc, char **argv)
{
TCHAR infoBuf[INFO_BUFFER_SIZE];
UINT RetSize; RetSize = GetSystemDirectory(infoBuf, INFO_BUFFER_SIZE);
// RetSize = 0;
if ((RetSize != ) && (RetSize <= INFO_BUFFER_SIZE)) {
// 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. // Display the system directory.
printf("System Directory: %ls", infoBuf);
}
else if (RetSize > INFO_BUFFER_SIZE) {
// If the length is greater than the size of the buffer,
// the returnv alue is the size of the buffer required to hold the path,
// including the terminating null character.
printf("The size of the buffer is not enough, need %d TCHARs at least. \n", RetSize);
}
else {
// If the function fails, the return value is zero. To get extended error information, call GetLastError.
printf("Get system directory failed with error: %d", GetLastError());
} getchar(); return ;
}

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

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

不知道是否存在BUG???

												

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. 解释局域(LAN)和广域网(WAN)之间的区别,它们之间的关系是什么?

    解释局域(LAN)和广域网(WAN)之间的区别,它们之间的关系是什么?

  2. Android自定义控件三种方式

    1.组合原生控件(继承自ViewGroup.LinearLayout.FrameLayout.RelativeLayout等)   将原生空间做组合,自定义一些事件 2.自己绘制控件(继承自View) ...

  3. python,异常处理

    # 该例子是对文件异常和类型异常分别进行的处理 try: sum = 1+' f=open('wo.txt') print(f.read()) f.close() except OSError as ...

  4. google 开源项目阅读计划

    1. glog 2. gflags 3. carto 4. ...

  5. Android JS 交互出现 Uncaught Error: Error calling method on NPObject

    由于HTML5的功能越来越强大,native app的一些功能逐步被html页面代替,不可避免的JS交互也用到的也越来越多.在第一个版本向第二个版本迭代的过程中却发生了莫名其妙的问题,第一个版本JS调 ...

  6. eMMC基础技术4:eMMC command

    1.前言 本文主要对eMMC的command进行详细介绍,主要包含如下内容: (1)command类型 (2)command格式 2.command类型 command类型 说明 bc 不带respo ...

  7. 工程师死绝的世界答案-python3版

    エンジニアが死滅シタ世界|アンドロイドとふたりぼっちで生きろ. 荒れ果てた警察署 [MISSION LEVEL: D] 难度D 题目要求: あなたは 0 から 9 の数字を 3 つ入力すると開く扉を開 ...

  8. MYSQL添加远程用户或允许远程访问

    1.用root用户登陆 格式:grant 权限 on 数据库教程名.表名 to 用户@登录主机 identified by "用户密码";             @ 后面是访问M ...

  9. lvs为何不能完全替代DNS轮询

    1)接入层架构要考虑的问题域为:高可用.扩展性.反向代理+扩展均衡 2)nginx.keepalived.lvs.f5可以很好的解决高可用.扩展性.反向代理+扩展均衡的问题 3)水平扩展scale o ...

  10. xtrabackup

    mysqldump备份方式是采用逻辑备份,其最大的缺陷就是备份和恢复速度都慢,对于一个小于50G的数据库而言,这个速度还是能接受的,但如果数据库非常大,那再使用mysqldump备份就不太适合了.而使 ...