ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

GetWindowsDirectoryA and GetSystemDirectory

2019-07-21 14:54:14  阅读:230  来源: 互联网

标签:cout GetSystemDirectory 路径 GetWindowsDirectoryA 文件夹 UINT 缓冲区 长度


#include <iostream>
#include <Windows.h>

using std::cout;
using std::endl;

// 获取Windows文件夹的路径
//UINT GetWindowsDirectory(LPTSTR lpBuffer,UINT uSize)

//获取systrm32文件夹的路径
//UINT GetSystemDirectory(LPTSTR lpBuffer,UINT uSize)

//这两个函数的使用方法很简单,和以前一样有两种方法来确定缓冲区的长度:
//1、Windows定义了一个文件路径的最长长度的常量MAX_PATH(值为260),我们可以用它来建立字符串缓冲区;
//2、给缓冲区传入NULL,调用函数成功后将返回缓冲区的长度。


int main()
{
    char* buf = nullptr;
    // 调用成功后,返回缓冲区的长度,返回windows文件夹的路径
    UINT Size = GetWindowsDirectory(NULL,0);
    buf = new char [Size];
    cout << Size << endl;
    if(0 != GetWindowsDirectoryA(buf,Size))
        cout << "WindowsDirectory path is :" << endl << buf << endl;
    else
        cout << "failed. GetLastError() :" << GetLastError() << endl;
    delete buf;
    buf = nullptr;
    cout << endl;

    // 调用成功后,返回缓冲区的长度,返回系统路径
    Size = GetSystemDirectory(NULL,0);
    buf = new char [Size];
    cout << Size << endl;
    if(0 != GetSystemDirectoryA(buf,Size))
        cout << "WindowsDirectory path is :" << endl << buf << endl;
    else
        cout << "failed. GetLastError() :" << GetLastError() << endl;
    delete buf;
    buf = nullptr;
    cout << endl;

    system("pause");
    return 0;
}

 

 

【转】:https://blog.csdn.net/liangjisheng/article/details/67642491

标签:cout,GetSystemDirectory,路径,GetWindowsDirectoryA,文件夹,UINT,缓冲区,长度
来源: https://www.cnblogs.com/hshy/p/11221181.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有