createfile头文件_createfileapk_createfile

电脑杂谈  发布时间:2017-02-23 14:04:00  来源:网络整理

下面的代码CreateFile返回错误值87,参数错误。

如果我把PhysicalDrive0改成PhysicalDriver0,返回错误2,找不到设备。

应该怎么改呢?

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
	HANDLE hFile=CreateFile("\\\\.\\PhysicalDrive0",GENERIC_READ|GENERIC_WRITE,
		FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
	if(INVALID_HANDLE_VALUE==hFile){
		printf("open error %d\n",GetLastError());
	}
    return 0;
}

CREATE_ALWAYS改为OPEN_ALWAYS。

CREATE_ALWAYS:Createsanewfile.Ifthefileexists,thefunctionoverwritesthefileandclearstheexistingattributes;

OPEN_ALWAYS:Opensthefile,ifitexists.Ifthefiledoesnotexist,thefunctioncreatesthefileasifdwCreationDispositionwereCREATE_NEW

同楼上,那个文件是不是,已经存在了。createfile或者该路径不支持创建文件。

按照两位的提示,我把代码改成了下面的这个样子。运行还是返回错误代码2.还需要改哪里呢?

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
int main() {
	HANDLE hFile=CreateFile("\\\\.\\PhysicalDriver1",GENERIC_READ,
		FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
	if(INVALID_HANDLE_VALUE==hFile){
		printf("open error %d\n",GetLastError());
	}
    return 0;
}

同楼上,那个文件是不是,已经存在了。或者该路径不支持创建文件。

我把CreateFile的第一个参数改成下面这个样子,这回错误代码变成了3.这到底是为什么呢?

HANDLEhFile=CreateFile("\\Device\\Harddisk0",GENERIC_READ,

FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-34048-1.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...