- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 ReadFile 函数。这是我的代码:
#define BUFFERSIZE 5
int main(int argc, char* argv[])
{
OVERLAPPED overlapIn = {};
HANDLE tHandle;
char buf[BUFFERSIZE] = {};
DWORD lpNumberOfBytesRead;
tHandle = CreateFile(
L"\\\\.\\D:",
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (tHandle == INVALID_HANDLE_VALUE)
{
DWORD error = GetLastError();
assert(0);
}
if (ReadFile(tHandle, &buf, BUFFERSIZE - 1, &lpNumberOfBytesRead, NULL) == 0)
{
int error = GetLastError();
printf("Terminal failure: Unable to read from disk.\n GetLastError=%d\n", error);
CloseHandle(tHandle);
return 1;
}
GetLastError 函数返回代码 87,即 ERROR_INVALID_PARAMETER。
很明显,其中一个参数是错误的,但我不知道是哪个参数,因为我尝试按照文档中所写的方式执行所有操作。
最佳答案
这在 documentation for CreateFile 中有描述:
Volume handles can be opened as noncached at the discretion of the particular file system, even when the noncached option is not specified in CreateFile. You should assume that all Microsoft file systems open volume handles as noncached.
MSDN article on File Buffering描述了非缓存句柄的要求:
File access sizes, including the optional file offset in the OVERLAPPED structure, if specified, must be for a number of bytes that is an integer multiple of the volume sector size. For example, if the sector size is 512 bytes, an application can request reads and writes of 512, 1,024, 1,536, or 2,048 bytes, but not of 335, 981, or 7,171 bytes.
File access buffer addresses for read and write operations should be physical sector-aligned, which means aligned on addresses in memory that are integer multiples of the volume's physical sector size. Depending on the disk, this requirement may not be enforced.
严格的代码应该检查有问题的文件系统的扇区大小,然后使用 this approach分配内存。但是,根据我的经验,扇区大小始终小于或等于分配粒度,因此您可以只使用 VirtualAlloc() 就可以了。分配内存块。
关于c - ReadFile 函数返回 ERROR_INVALID_PARAMETER,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31697229/
为了测试并确保我已经把所有东西都放下了,以便以后可以开始扩展,我正在尝试创建一个文件句柄,将给定的字节缓冲区写入该文件句柄,然后读取部分该文件放入新的测试缓冲区。 我有代码: const size_t
这是我的问题: a method readLine that reads a line from the file specified in fileName and returns the
我被认为是一个菜鸟,我在互联网上搜索了几个小时来解决我的问题,但仍然没有运气。 我真的很想了解java,如果你能解释一些细节,我将非常感激。 问题出在这一行 ReadFile file = ReadF
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我正在编写一个程序,通过 USB 通过虚拟 com 端口与电机驱动器通信。我正在使用 windows.h file-io 与其通信(CreateFile、WriteFile、ReadFile)。我可以
我的问题是关于回调函数的工作方式。 const fs = require('fs'); let fileContents = 'initial value'; fs.readFile('file.tx
我正在尝试使用 readfile 读取一个文件,将其存储到一个宽数组中,然后将其写入另一个文件。问题是,当我将它们并排放置在 HxD 中时,一些字节是正确的(例如文本),但其他一切都完全不同。我也跑不
我正在通过将 COM 端口 RD 和 TD 引脚连接在一起来测试串行端口通信。在执行以下代码之前,COM 端口已被初始化。 CString cs_Send = "F: 5000000 Hz, SF:
我正在使用 Flash 播放器播放一些 mp3 文件。在 Firefox 上它可以正常加载它们,但在 IE 上却不能。当我转到 .mp3 文件的 url 时,它显示了 mp3 的源代码(而不是提供例如
在设置在线文件管理系统时,我遇到了障碍。 我正在尝试使用此 modified version of readfile 将文件推送到客户端: function readfile_chunked($fil
这很很奇怪。 我有一个脚本可以通过浏览器将本地 zip 文件发送给用户。到目前为止,该脚本运行良好,没有任何问题。今天我的同事通知我脚本正在发送零长度文件。 一些背景信息: 在脚本出错之前没有修改服务
在我的函数中,我正在下载一个将下载保存到日志文件的文件。每当我尝试下载我上传的 Excel 文件时,Excel 都会指出它已损坏。我的本地副本工作正常。这是我的 download.php:
是否可以在大小未知且大小不断增加的远程文件上使用 PHP readfile 函数?这是场景: 我正在开发一个脚本,它可以从第三方网站下载视频,同时将视频转码为 MP3 格式。这个 MP3 然后通过 r
我正在使用 PHP readfile 函数读取文件并像这样打印它:print readfile ('anyfile')。这可行,但文件的内容长度也会添加到字符串的末尾。为什么? 最佳答案 readfi
我正在尝试解决从 PHP 脚本下载“zip”文件时遇到的问题。似乎当我使用以下代码下载文件时,下载的文件在文件开头附加了一个额外的 0A09,导致 winzip 抛出损坏错误。 kill_sessi
我是 nodejs 和回调的新手。 所以我有这段代码,当通过 HTTP 发起对服务器的请求时,我在其中读取文件: var http = require("http"); var fs = requir
当使用 readfile() 时——在 Apache 上使用 PHP——文件是立即读入 Apache 的输出缓冲区并完成 PHP 脚本执行,还是 PHP 脚本执行等到客户端完成下载文件(或服务器)超时
我正在使用 php 脚本在必要的 javascript 计时器之后提供从我的网站的下载,此 php 脚本包含在内,导致下载。但是无论我尝试什么,下载的文件都是损坏的。谁能帮我指出我哪里出错了。 这是我
我正在使用下面的代码通过单击按钮下载 csv 文件。 JS: $(document).on("click", "#CSV", function () { var csv_value = $('
我有一个 php 代码,用于根据 URL 中的 file_id 下载文件。一切正常,但我在下载扩展名为 .doc 的文件时遇到问题 这是我的代码,我做错了什么? $file = mysql_fetch
我是一名优秀的程序员,十分优秀!