帮忙给讲讲怎么样使用readfile();

baichunyu123 2005-04-30 08:33:43
我想请教一个问题:怎么样用readfile(0;接收下位机传来的数据?接收后怎么显示在编辑况中?刚学习vc++,请高手帮忙呀?入给做好相送的更是感激不尽.qq:414452927
...全文
121 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
baichunyu123 2005-06-16
  • 打赏
  • 举报
回复
baichunyu123@eyou.com 谢谢你了
gamezealot 2005-05-03
  • 打赏
  • 举报
回复
你的邮箱是什么,我发给你~
baichunyu123 2005-04-30
  • 打赏
  • 举报
回复
你做好的有吗?给发过来一个让我看看
baichunyu123 2005-04-30
  • 打赏
  • 举报
回复
还有你给我说说我的哪些函数写代码写在哪里?
baichunyu123 2005-04-30
  • 打赏
  • 举报
回复
请问线程是是什么?我不知道怎么使用线程呀?楼上的那位哥哥帮忙帮到底呀
gamezealot 2005-04-30
  • 打赏
  • 举报
回复
楼主的意思我明白,我做过这个:但你想想你怎么知道下位机的数据什么时候能发过来,所以要写一个线程来监视是否有数据。一般的做法:
把这个代码放到线程中
bResult = ReadFile(hFile, &inBuffer, nBytesToRead, &nBytesRead, NULL) ; //参数当然是你自己的参数
当inbuffer不为空的时候:
做下相应的字符串转化,然后把它显示到编辑框(显示这个应该很简单,自己查资料吧)
baichunyu123 2005-04-30
  • 打赏
  • 举报
回复
谢谢大家的热情帮助,我的目的只是想从下位机接收一串数据,然后把它在编辑框中显示出来
thisisll 2005-04-30
  • 打赏
  • 举报
回复
MSDN上的内容
ReadFile
This function reads data from a file, starting at the position indicated by the file pointer. After the read operation has been completed, the file pointer is adjusted by the number of bytes actually read.

BOOL ReadFile(
HANDLE hFile,
LPVOID lpBuffer,
DWORD nNumberOfBytesToRead,
LPDWORD lpNumberOfBytesRead,
LPOVERLAPPED lpOverlapped);
Parameters
hFile
[in] Handle to the file to be read. The file handle must have been created with GENERIC_READ access to the file. This parameter cannot be a socket handle.
lpBuffer
[out] Pointer to the buffer that receives the data read from the file.
nNumberOfBytesToRead
[in] Number of bytes to be read from the file.
lpNumberOfBytesRead
[out] Pointer to the number of bytes read. ReadFile sets this value to zero before doing any work or error checking.
lpOverlapped
[in] Unsupported; set to NULL.
Return Values
Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.

The ReadFile function returns when one of the following is true: the number of bytes requested has been read or an error occurs.

If the return value is nonzero and the number of bytes read is zero, the file pointer was beyond the current end of the file at the time of the read operation.

Remarks
If part of the file is locked by another process and the read operation overlaps the locked portion, this function fails.

Accessing the input buffer while a read operation is using the buffer may lead to corruption of the data read into that buffer. Applications must not read from, write to, reallocate, or free the input buffer that a read operation is using until the read operation completes.

When reading from a communications device, the behavior of ReadFile is governed by the current communication time-outs as set and retrieved using the SetCommTimeouts and GetCommTimeouts functions. Unpredictable results can occur if you fail to set the time-out values. For more information about communication time-outs, see COMMTIMEOUTS.

The ReadFile function may fail and return ERROR_INVALID_USER_BUFFER or ERROR_NOT_ENOUGH_MEMORY whenever there are too many outstanding asynchronous I/O requests.

When a synchronous read operation reaches the end of a file, ReadFile returns TRUE and sets *lpNumberOfBytesRead to zero. Windows CE does not support asynchronous read operations on files. The following sample code tests for end-of-file for a synchronous read operation:
例子
// Attempt a synchronous read operation.
bResult = ReadFile(hFile, &inBuffer, nBytesToRead, &nBytesRead, NULL) ;
// Check for end of file.
if (bResult && nBytesRead == 0, )
{
// we’re at the end of the file
}

zhangnanonnet 2005-04-30
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=195409
gamezealot 2005-04-30
  • 打赏
  • 举报
回复
应该写一个线程来做这个工作。
具体用到的函数:
CreateEvent, WaitForSingleObject, SetEvent,ResetEvent等...具体看msdn上的用法。
uoyevoli 2005-04-30
  • 打赏
  • 举报
回复
哈,想帮你啊,只是你的问题不清不楚的。看不太懂你要干什么啊。

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧