关于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. Vue.js简单记录

    官网:https://cn.vuejs.org/ https://cn.vuejs.org/v2/api/#methods v-bind 缩写 <!-- 完整语法 --> <a v- ...

  2. JAVA配置文件/反射操作

    配置文件 1. 在src目录下新建一个file, 命名为XXX.properties 2.编写配置文件: 3. import java.util.ResourceBundle; 4. 使用如下代码读取 ...

  3. logistic回归为什么要使用sigmoid函数

    https://www.baidu.com/link?url=LnDjrhLG7Fx6YVgR9WljUILkPZrIzOR402wr2goIS-ARtDv9TwZ2VYVbY74fyVpQlE22n ...

  4. yum upgrade卡在 清理initial-setup-0.3.9.30-1.el7.centos.x86_64

    我安装CENTOS7.2,用yum -y update进行更新 卡在这里了 清理 : initial-setup-0.3.9.30-1.el7.cent 目测是一个系统bug,执行关闭命令解决: sy ...

  5. Codeforces 408D Long Path (DP)

    题目: One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n ...

  6. QML 从入门到放弃 第二卷

    第二卷如何更快速的放弃,注重的是C++和QML的交互 <1>记事本.. (1) 先测试下不在QML创建C++对象,仅仅在main.cpp添加一个属性函数供调用. 注意只使用槽函数来做到. ...

  7. Trickbot展示新技巧:密码抓取器模块

    Trickbot是一个简单的银行木马 来源 https://blog.trendmicro.com/trendlabs-security-intelligence/trickbot-adds-remo ...

  8. DAC杂谈一

    DAC种类: 有权电阻网络DAC 输出电压变化范围为:0~-(2^n-1)/2^n*Vref 当位数很高时,每个电阻都有很高精度是十分困难的. 倒T型电阻网络DAC(比如AD7520 10bit 已停 ...

  9. caffe调试

    这里说一下关于如何进行Caffe的调试: 参考:https://blog.csdn.net/tsyccnh/article/details/51679121 简要说一下步骤: (1)首先对libcaf ...

  10. bug笔记(pc)

    1.如果a标签中的href没有设置,那么点击的这个按钮的时候,这个页面会自动刷新!!! Bug:   <a href=”” class=”btn”></a>类似这种情况,点击a ...