473,785 Members | 2,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with ReadFile()

Hi all thanks in advance for reading. I am writing a serial port app
with the help of many examples and I am not quite clear on how to get
the data back from the method call? I have pasted the read method
below, it takes a void * as the buffer. I know I need to send something
by reference but am unclear on how to do it.

What I want it the buffer to be a string that I can use or manipulte.
Can anyone help Please?

int MBSerial::ReadD ata( void *buffer, int limit )
{

if( !m_bOpened || m_hIDComDev == NULL ) return( 0 );

BOOL bReadStatus;
DWORD dwBytesRead, dwErrorFlags;
COMSTAT ComStat;

ClearCommError( m_hIDComDev, &dwErrorFlag s, &ComStat );
if( !ComStat.cbInQu e ) return( 0 );

dwBytesRead = (DWORD) ComStat.cbInQue ;
if( limit < (int) dwBytesRead ) dwBytesRead = (DWORD) limit;

bReadStatus = ReadFile( m_hIDComDev, &buffer, dwBytesRead,
&dwBytesRead , &m_OverlappedRe ad );
if( !bReadStatus ){
if( GetLastError() == ERROR_IO_PENDIN G ){
WaitForSingleOb ject( m_OverlappedRea d.hEvent, 2000 );
return( (int) dwBytesRead );
}
return( 0 );
}
return( (int) dwBytesRead );
}

Oct 11 '05 #1
2 16917

"salsipius" <sa*******@sals ipius.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
Hi all thanks in advance for reading. I am writing a serial port app
with the help of many examples and I am not quite clear on how to get
the data back from the method call?
From looking at the code below, I see two possible pieces
of information you can receive from the 'ReadData()' function:
the type 'int' value it returns (representing the actual
number of bytes read), and the data stored at the address
represented by the parameter 'buffer'.
I have pasted the read method
below, it takes a void * as the buffer. I know I need to send something
by reference
No you don't (you could, but there's no reason to).
but am unclear on how to do it.
Allocate sufficient storage to represent whatever data the
function stores there, and pass its address as the 'buffer'
parameter.

What I want it the buffer to be a string that I can use or manipulte.
Well, the 'ReadFile()' function appears to store data
at address 'buffer'. I don't know if it places a string
terminator at the end of the data or not. There's no
'ReadFile()' function in standard C++, so you'll need
to look up its documentation to see how to use it and
what it does. (If you want the data at 'buffer' to be
a string, and ReadFile doesn't terminate it with a zero,
just allocate an additional byte in your storage, and
put it there yourself. Hint: the 'bytes read' return value
will tell you where to put it.)
Can anyone help Please?
Not with the nonstandard function, not here.
The 'Hungarian notation' makes this stuff look like
Windows, if so try a Windows newsgroup, website
(e.g. www.msdn.microsoft.com), or mailing list.

-Mike

int MBSerial::ReadD ata( void *buffer, int limit )
{

if( !m_bOpened || m_hIDComDev == NULL ) return( 0 );

BOOL bReadStatus;
DWORD dwBytesRead, dwErrorFlags;
COMSTAT ComStat;

ClearCommError( m_hIDComDev, &dwErrorFlag s, &ComStat );
if( !ComStat.cbInQu e ) return( 0 );

dwBytesRead = (DWORD) ComStat.cbInQue ;
if( limit < (int) dwBytesRead ) dwBytesRead = (DWORD) limit;

bReadStatus = ReadFile( m_hIDComDev, &buffer, dwBytesRead,
&dwBytesRead , &m_OverlappedRe ad );
if( !bReadStatus ){
if( GetLastError() == ERROR_IO_PENDIN G ){
WaitForSingleOb ject( m_OverlappedRea d.hEvent, 2000 );
return( (int) dwBytesRead );
}
return( 0 );
}
return( (int) dwBytesRead );
}

Oct 11 '05 #2
salsipius wrote:
Hi all thanks in advance for reading. I am writing a serial port app
with the help of many examples and I am not quite clear on how to get
the data back from the method call? I have pasted the read method
below, it takes a void * as the buffer. I know I need to send something
by reference but am unclear on how to do it.
No you don't. void* is a pointer not a reference.

What I want it the buffer to be a string that I can use or manipulte.
Can anyone help Please?

[snip]

bReadStatus = ReadFile( m_hIDComDev, &buffer, dwBytesRead,
&dwBytesRead , &m_OverlappedRe ad );


Should be

bReadStatus = ReadFile( m_hIDComDev, buffer, dwBytesRead,
&dwBytesRead , &m_OverlappedRe ad );

no & before buffer.

john
Oct 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3448
by: bt | last post by:
I am just beginning with asp and have gotten an error that I need some help with. I posted a pair of files to an online ASP host server. The files are in the same directory; one is readfile.asp which should open the other which is a simple text file - newText.txt . Here is readfile.asp : <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html>
8
7443
by: chuck clark | last post by:
Hi, I am sorry if this is not the most appropriate group to ask this in (if not, please point me in the right direction). I am following examples from this page, http://www.vbwm.com/articles/2002/abarfield/hta01/ I have a some questions about Figure 5 (below). This hta file will view a text file when a button is pushed. 1. Why do the paths require double '\' ? like
12
6901
by: ORC | last post by:
Shouldn't 'ReadFile' block when timeouts are specified even when running in overlapped mode or am I wrong ??? Thanks Ole
2
3577
by: Good Man | last post by:
Hi there folks I've got an interesting little problem going on. On one of my projects, I have users log in to retrieve files. The files themselves are stored outside of the www directory on the server, so the only way they can be downloaded is for PHP to stream them to the user. My problem is that my downloads are always "completing" too soon, and always around 1.6 -> 1.9 MB. So, when I try to download a 50MB file, I'm told that...
2
1402
by: yodadbl07 | last post by:
Hey i made this program that uses classes and files, and im having trouble with the readfile constructor... here is the code #include <iostream.h> #include <iomanip.h> #include <fstream.h> #include <string.h> #define W setw
1
1920
by: saytri | last post by:
I have a problem with this code. I'm, doing a quiz, and the questions are stored in a binary file. My problem is how am i going to compare the answers entered by the user to the correct answers. The correct answers are stored in an array. Pls can someone help me with this code, because i'm really stuck. I think the problem is in the for loop (the code below). Thanks a lot. If you help me with examples of source code, i appreciate it a lot....
4
16724
by: HaifaCarina | last post by:
here's the complete lines of errors.. Exception in thread "main" java.util.NoSuchElementException at java.util.StringTokenizer.nextToken(StringTokenizer.java:332) at CsvTest.readFile(CsvTest.java:26) at Trial.main(Trial.java:24) I have no idea what to change here because I don't know what is wrong..please help me out... import java.io.*; import java.util.*;
4
1581
by: Paul David Buchan | last post by:
Hello, I'm attempting to write a program to read in database files (.dbf). When I do it all as a single procedure in main, everything works. However, what I really want, is to pass the database filename to a function, and have it pass back an array containing the database contents, and some parameters telling me the dimensions of the array. I've succeeded in getting my function to read in the dbf file, and it returns the dimensions of...
15
5944
by: Ketchup | last post by:
Hello everyone, I have been stuck with this problem for quite some time now. I am working in VB.NET, using framework 1.0. I have to keep the compatibility down to the original .NET framework as much as possible. I am forced to use API calls for several functions, one of which is ReadFile. The reason is because the framework seems to use ANSI versions of all API functions, limiting the MAX_PATH for filenames to about 260 chars for ...
0
9491
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10357
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10163
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.