关于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. const的引用

    const的引用 对常量的引用:把引用绑定到const对象上,就像绑定到其他对象上一样,不能被用作修改它所绑定的对象: ; const int &r1 = ci;//正确:引用及其对应的对象都 ...

  2. 【转】python 退出程序的方式

    [转]python 退出程序的方式 python程序退出方式[sys.exit() os._exit() os.kill() os.popen(...)] 知乎说明 http://www.zhihu. ...

  3. python zip文件压缩和解压

    压缩 import shutil zipOutputName = "1234" # 输出1234.zip fileType = "zip" # 文件类型zip ...

  4. addEventListener() 方法,事件监听

    知识点1:addEventListener() 方法,事件监听,可以使用 removeEventListener() 方法来移除事件的监听. 语法 element.addEventListener(e ...

  5. python类的内建方法

    研究email源码学到的 class test(): """Class for generating text/* type MIME documents."& ...

  6. python二叉树练习

    #coding=utf8 node_list=[5,3,6,2,4,None,8,1,None,None,None,7,9] class Node: def __init__(self,item): ...

  7. 【转】HashMap实现原理及源码分析

    哈希表(hash table)也叫散列表,是一种非常重要的数据结构,应用场景极其丰富,许多缓存技术(比如memcached)的核心其实就是在内存中维护一张大的哈希表,而HashMap的实现原理也常常出 ...

  8. applet jre冲突问题

    erp中用到applet,jre为1.6,开发用到jdk1.8,有冲突 安装jre1.6,再安装jdk8,将jdk1.8文件夹复制后卸载1.8,然后重新黏贴,将javahome定向到1.8文件夹

  9. RS485 通信接收时丢失0x11等数据

    RS485通信接收方,丢弃掉了值为 0x11 的数据. 怀疑 0x11 被转义,没有按照原始数据接收, 查看ASCII码对应表 0x11 代表 “本文结束”, 因此丢弃是有可能的. 要想接收原始数据而 ...

  10. python多线程threading下载示例

    #coding:utf-8 # windows中测试不通过,下载的图片不完整 # 通过多线程下载图片 import requests import threading class downloader ...