GetSystemDirectory和CreateFile

小练习:

#include <Windows.h>
#include <stdio.h>

int main()
{

    HANDLE hFile;
    DWORD dwWritten;
    TCHAR szSystemDir[MAX_PATH];
    GetSystemDirectory(szSystemDir,MAX_PATH);

    printf("%s\n",szSystemDir);

    hFile = CreateFile(L"systemroot.txt",
        GENERIC_WRITE,
        0,NULL,CREATE_ALWAYS,
        FILE_ATTRIBUTE_NORMAL,
        NULL);
    if(hFile != INVALID_HANDLE_VALUE)
    {
        if(!WriteFile(hFile,szSystemDir,lstrlen(szSystemDir),&dwWritten,NULL))
        {
            return GetLastError();
        }
    }
    CloseHandle(hFile);
    system("pause");
    return 0;
}
时间: 2024-08-08 11:01:37

GetSystemDirectory和CreateFile的相关文章

CreateFile函数详解(确实很详细)

CreateFile The CreateFile function creates or opens the following objects and returns a handle that can be used to accessthe object: files pipes mailslots communications resources disk devices(Windows NT only) consoles directories(open only) CreateFi

CreateFile FileSeek FileRead 直接读取数据

[html] view plain copy unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, FileCtrl; type TForm1 = class(TForm) Button1: TButton; DriveComboBox1: TDriveComboBox; memosd: TMemo; proc

CreateFile函数详解

CreateFile函数详解 CreateFile The CreateFile function creates or opens the following objects and returns a handle that can be used to accessthe object: files pipes mailslots communications resources disk devices(Windows NT only) consoles directories(open

C/C++ 文件操作之CreateFile、ReadFile和WriteFile

1. CreateFile 这个函数的功能是创建或者打开一个文件或者I/O设备,通常使用的I/O形式有文件.文件流.目录.物理磁盘.卷.终端流等.如执行成功,则返回文件句柄. INVALID_HANDLE_VALUE 表示出错,会设置 GetLastError . 函数的声明定义: HANDLE WINAPI CreateFile( _In_ LPCTSTR lpFileName, _In_ DWORD dwDesiredAccess, _In_ DWORD dwShareMode, _In_o

CreateFile使用方法和样例

函数原型: HANDLE CreateFile( LPCTSTR lpFileName, //指向文件名称的指针 DWORD dwDesiredAccess, //訪问模式(写/读) DWORD dwShareMode, //共享模式 LPSECURITY_ATTRIBUTES lpSecurityAttributes, //指向安全属性的指针 DWORD dwCreationDisposition, //怎样创建 DWORD dwFlagsAndAttributes, //文件属性 HANDL

用CreateFile打开串口超过com10就不能打开,解决办法

10以下的串口可以这样打开 CreateFile( "COM5", // address of name of the communications device fdwAccess, // access (read-write) mode 0, // share mode NULL, // address of security descriptor OPEN_EXISTING, // how to create 0, // file attributes NULL // handl

CreateFile,WriteFile,ReadFile

注意: CreateFile 跟 fopen 不同,打开文件时不区分 文本方式 或 二进制 方式 ReadFile 或 WriteFile 都是对二进制数据进行操作 HANDLE WINAPI CreateFile( __in LPCTSTR lpFileName, // 文件路径 __in DWORD dwDesiredAccess, // 访问权限,GENERIC_READ | GENERIC_WRITE __in DWORD dwShareMode, // 共享模式,NULL | FILE

CreateFile,ReadFile等API详解(或者说MSDN的翻译)

一.*****CreateFile***** 这个函数可以创建或打开一个对象的句柄,凭借此句柄就可以控制这些对象:控制台对象.通信资源对象.目录对象(只能打开).磁盘设备对象.文件对象.邮槽对象.管道对象.    函数原型:HANDLE CreateFile(LPCTSTR lpFileName,                         // file name对象路径名DWORD dwDesiredAccess,                      // access mode控

004 CreateFile API 使用 和学习 MSDN的方法重点

Evernote Export body,td { font-family: 微软雅黑; font-size: 10pt } Edit CreateFile中文翻译 CreateFile中文翻译 函数功能 API 函数原型 参数解析 lpFileName dwDesiredAccess dwShareMode lpSecurityAttributes dwCreationDisposition dwFlagsAndAttributes hTemplateFile 返回值 备注 需求  这次的课程