IOBYFILE.C---overlapped I/O with a signaled file handle
2015-07-25 09:58
274 查看
#include<windows.h>
int ReadSometion()
{
BOOL rc;
HANDLE hFile;
DWORD numread;
OVERLAPPED overlap;
char buf[512];
//open the file for overlapped reads
hFile = CreateFile("C:\\WINDOWS\\WINFILE.EXE",
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING,
FILE_FLAG_OVERLAPPED, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
return -1;
}
//initialize the overlapped structure
memset(&overlap, 0, sizeof(overlap));
overlap.Offset = 1500;
//request the data
rc = ReadFile(hFile, buf, 300,
&numread, &overlap);
if (rc)
{
//the data was read successfully
}
else
{
//Was the operation queued?
if (GetLastError() == ERROR_IO_PENDING)
{
//we could do something else for awhile here....
WaitForSingleObject(hFile, INFINITE);
rc = GetOverlappedResult(hFile, &overlap, &numread, FALSE);
}
else
{
//Something went wrong
}
}
CloseHandle(hFile);
return TRUE;
}
int ReadSometion()
{
BOOL rc;
HANDLE hFile;
DWORD numread;
OVERLAPPED overlap;
char buf[512];
//open the file for overlapped reads
hFile = CreateFile("C:\\WINDOWS\\WINFILE.EXE",
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING,
FILE_FLAG_OVERLAPPED, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
return -1;
}
//initialize the overlapped structure
memset(&overlap, 0, sizeof(overlap));
overlap.Offset = 1500;
//request the data
rc = ReadFile(hFile, buf, 300,
&numread, &overlap);
if (rc)
{
//the data was read successfully
}
else
{
//Was the operation queued?
if (GetLastError() == ERROR_IO_PENDING)
{
//we could do something else for awhile here....
WaitForSingleObject(hFile, INFINITE);
rc = GetOverlappedResult(hFile, &overlap, &numread, FALSE);
}
else
{
//Something went wrong
}
}
CloseHandle(hFile);
return TRUE;
}
相关文章推荐
- Xamarin.Android开发实践(十六)
- Android Drawable 那些不为人知的高效用法
- Xamarin.Android开发实践(十五)
- Xamarin.Android开发实践(十四)
- 第一个app-进阶二::1、EditText退格::2、焦点转移--更人性化
- android SoundPool调用pause stop方法使用注意问题
- iOS 调试
- 编写高质量iOS与OS X代码的52个有效方法上
- Xamarin Android 绑定jar库同时将so库打包进去
- Xamarin.Android开发实践(十三)
- Xamarin.Android开发实践(十二)
- Xamarin.Android开发实践(十一)
- IOS学习整理(一)视图层次结构与视图控制器
- Xamarin.Android开发实践(十)
- Xamarin.Android开发实践(九)
- Android BLE开发之Android手机与BLE终端通信
- Xamarin.Android开发实践(八)
- Xamarin.Android开发实践(七)
- Android笔记-2-TextView的属性详解
- Xamarin.Android开发实践(六)