- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到的问题:CreateFile 返回 0x194 的句柄。 ReadFileEx 表示此句柄无效。 (错误 6。)有什么想法吗?传入的参数是“C:\testfile.txt”,这是我用记事本制作的有效文本文件。尽管在过去的 12 年里我一直是一名 C++ 程序员,但这是我第一次使用“windows.h”或线程编写任何东西。
#include "stdafx.h"
#include "stdio.h"
#include "windows.h"
using namespace System;
int main(int argc, char **argv)
{
if (argc != 2)
{
printf("To display a file, you must enter the filename as the only command argument.");
scanf("\n");
return 0;
}
HANDLE file;
int nameLen = (strlen(argv[1]) + 1);
wchar_t *filename = new wchar_t[nameLen];
if (filename == 0)
{
printf("To display a file, you must enter the filename as the only command argument.");
scanf("\n");
return 0;
}
memset(filename, 0, nameLen);
::MultiByteToWideChar(CP_ACP, NULL, argv[1], -1, filename, nameLen);
file = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (file == NULL)
{
printf("A valid filename is required.");
scanf("\n");
return 0;
}
char *buffer;
buffer = new char[1024];
OVERLAPPED overlapped;
overlapped.Offset = overlapped.OffsetHigh = 0;
ReadFileEx(file, &buffer, 1024, &overlapped, NULL);
WaitForSingleObject(&file, 0);
if (GetLastError() != ERROR_SUCCESS)
{
printf("A valid file is required., Error: %d", GetLastError());
scanf("\n");
return 0;
}
printf("%s", buffer);
scanf("\n");
delete buffer;
return 0;
}
最佳答案
我的猜测是改变ReadFileEx(&file, &buffer, 1024, &overlapped, NULL);
到ReadFileEx(file, &buffer, 1024, &overlapped, NULL);
关于c++ - 使用来自 CreateFile 的有效句柄来自 ReadFileEx 的无效句柄错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7690734/
我想在串行端口上为异步I/O使用ReadFileEx/WriteFileEx函数,而不需要为APC使用lpCompletionRoutine参数。 1-lpCompletionRoutine参数是否可
我使用 winapi ReadFileEx 异步加载 30 兆字节的数组 天哪,它运行得非常好——我已经读完了 免费的,我的计算不会减慢,只是数组很神奇 在后台加载并且没有降低游戏帧的速度(尽管我 使
我正在尝试从子进程的 stderr 中读取。数据是使用 sprintf(stderr, "some debug info\n") 创建的文本行。我将 ReadFileEx 与完成例程一起使用。我不知道
我正在使用 ReadFileEx 从文件中读取扇区对齐的 block (使用 CreateFile 和 FILE_FLAG_NO_BUFFERING 标志打开),记录调用前的开始时间和完成例程中的结束
我正在编写一个类 (PipeReader) 来处理 Windows 上的命名管道。该类使用异步 IO 从管道读取。 到目前为止,我一直在没有事件循环的线程中使用该类,我不得不等待 IO 完成使用 Sl
Win32 ReadFileEx 定义为: BOOL WINAPI ReadFileEx( __in HANDLE hFile, __out_opt LPVOID lpBuffe
ReadFileEx's documentation说: Accessing the input buffer while a read operation is using the buffer m
我正在玩 IOCP。我正在尝试编写简单的应用程序,异步从主线程中的文件读取数据。但是我在 ReadFileEx 函数中遇到错误(ERROR_INVALID_PARAMETER),但似乎我做得很好。我究
我正在尝试使用 Win32 API 创建一个子线程,该子线程从 STD_INPUT_HANDLE 读取并将其读取的字节推送到套接字中。因为我希望在退出时能够安全地关闭该线程,所以我使用 ReadFil
我遇到的问题:CreateFile 返回 0x194 的句柄。 ReadFileEx 表示此句柄无效。 (错误 6。)有什么想法吗?传入的参数是“C:\testfile.txt”,这是我用记事本制作的
出于某种原因,在调用 ReadFileEx 后,我的回调没有收到正确的 OVERLAPPED 结构的地址。什么会导致这种情况? 更新——例子: #include #include void __s
有没有什么方法可以在不创建新线程的情况下使用 APC 完成例程异步读取和写入控制台?就像命名管道一样。 问题是在控制台的情况下,FILE_FLAG_OVERLAPPED 被 CreateFile 函数
我有一个长期运行的基于控制台的应用程序 Sender,它使用非缓冲输出(例如 cout wait_handles; wait_handles.push_back(handles[h_Die_Sig]
HasOverlappedIoCompleted()不适用于以 ReadFileEx() 开头的异步 I/O和 WriteFileEx() .底部的代码片段演示了这一点。在此示例中,ReadFileE
我是一名优秀的程序员,十分优秀!