|
How do I detect end of file using CFile..
e.g CFile infile;
while( ???????????????? )
{
// do something
}
Thanks.
|
|
|
|
|
See the documentation of CFile::Read() . If its return value is less than the amount of bytes requested, you've reached EOF. This method can also throw a CFileException , whose m_cause member contains the cause of the exception. Compare it with CFileException::endOfFile to check for attempts to read past EOF.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
CFile has no eof function. To test for eof you should check the return value from the read function. if the return value is less than the number of bytes you requested to be read, then the end of file has been reached.
Gary Kirkham
A working Program is one that has only unobserved bugs
I thought I wanted a career, turns out I just wanted paychecks
|
|
|
|
|
Hi, does anyone knows how to handle events from dynamically created ActiveX controls ?
In my particular case, I've created an aray of MSComm controls. I use it to control many modems on the PC. I can open the com ports, send data and everything works fine. My problem is when it comes to handling the OnComm event. I have no idea about how to do that.
If anyone have an example or a reference of how to manage event from dynamic ActiveX, it would be apretiated.
Tank you.
|
|
|
|
|
Does anyone know of some good articles about developing in VC++ with a project-based architecture using MFC? With MDI and SDI, you can either have a single-document or multiple documents opened at one time. I need something like Visual Studio where you have a single project opened, but mutiple files and potentially several control bars (like the Workspace, Output, etc.).
I know this has been covered somewhere, perhaps even on CP.
|
|
|
|
|
Well, one model to use could be the way VC6 does it (some other irrelevant info is also there):
http://www.codeproject.com/macro/openvc.asp[^]
Basically the workspace is a CDocument derived class and probably manages all the rest of it. I don't have the time to do a search on CP, but there are probably plenty of articles on doing similar things here.
Chris Richardson
You can stash and you can seize
In dreams begin, responsibilities U2 - Acrobat[^]
Stop being PC and accounting for everyone and his momma's timeframe. Just enjoy your - Rohit Sinha in the content-challenged thread
|
|
|
|
|
|
My Class A has a function named
SaveSelectedItems()
I'm trying to call that function from Class B.
when I call it I get the message SaveSelectedItems, undeclared identifier. I'm not sure how this could be done.
|
|
|
|
|
Class B will need an instance of Class A, or the function in Class A will need to be declared as static.
|
|
|
|
|
In your class B function where you are calling this Class A function, create an instance of class A and use that instance to call SaveSelectedItems()
|
|
|
|
|
Thank you for your reply.
|
|
|
|
|
help confused:
i want to realize a vectorgraph editor like proxysource design.
how to do it?
|
|
|
|
|
I read your bio and you are not even close to being able to write such a program. Proxysource design was probubly written by a team of programers, and or it took a very long time (and experence).
If you are serious about writing such a program I suggest you use it and study how it appears to work (for clues), then work on it a piece at a time.
Write down what you need to learn in order to reach your goal(s), what you need to learn. I would start with the graphical aspect of the problem (GDI), if you can not draw the objects (part of the front end) then you can use that imformation to write the code generation part.
You might try SorceForge.net to see if any body is working on a case tool and either join the development team or study what they are doing.
Could I write it in a reasonable amount of time? No!
Could I write it? Yes!
Trust in the code Luke. Yea right!
|
|
|
|
|
I have been using a modeless dialog for indicating the progress of a task. In the dialog is a CProgressCtrl, and a cancel button. I have recently added a CListCtrl as well.
Everything works fine as long as you do not move the dialog, or click in the list control. Once you do this, things start to get wierd. Usually, there is a 2-3 second delay when clicking on something, or moving the window. During this delay, nothing is happening with the task that the dialog is showing the progress of. It should be continuing on, but nothing happens. The screen does not draw correctly either.
Each time I manually break, the stack points to my function that is pumping messages (it gets called periodically during the task). The PeekMessage seems to be "stuck" for some reason. Again, this only happens if the dialog is moved, or when clicking on a control within the dialog.
Any ideas on why this may be happening? Any work-arounds?
<br />
while (::PeekMessage (&msg, NULL, 0,0, PM_NOREMOVE)) {<br />
<br />
if (pbrcv != NULL && msg.message == WM_MYMSG1){<br />
*pbrcv = true;<br />
}<br />
if (!AfxGetApp()->PumpMessage()) {<br />
::PostQuitMessage(0);<br />
return false;<br />
}<br />
} <br />
LONG lIdle = 0;<br />
while (AfxGetApp()->OnIdle (lIdle++))<br />
;<br />
}<br />
Thanks,
DaveQ
|
|
|
|
|
I assume you have a single-threaded program. When you click on one of the controls on the modeless dialog, it is not receiving enough of the CPU to carry out what needs to be done (e.g, paint). When it does get a timeslice, things probably appear "jumpy."
The PeekMessage() solution you have employed is an antiquated and largely unused 16-bit Windows solution (but still used because it is "well known"). It's bad for several reasons. The most important one is that it puts, in the time-critical main loop, a function whose overhead is substantial. Another problem is, since there is a modeless dialog active, there is no IsDialogMessage() call there to handle it. Go with a worker thread.
|
|
|
|
|
Thank you for replying.
Unfortunately, the worker thread isn't something I'm going to be able to do. It's difficult to explain why. I did try putting the dialog in a GUI thread, but got the same result. I think what may be happening is the message that helps keep the task running properly is getting "eaten" by something??
The PeekMessage loop that I showed earlier is there to keep the GUI alive, but the filter is set to read all messages. I thought that the task message (call it WM_USER + 100) would be left alone since I specified PM_NOREMOVE, but it is acting as if the message is not being left in the queue.
I may have to do something cheesy like prevent the window from being moved if I can't find the problem.
Thanks for your help.
|
|
|
|
|
Here's a weird one... I have the following calls for performing asynchronous I/O on a USB device (control logic for device type abstraction stripped away):
if(!m_waiting_for_read)
{
io_complete = DeviceIoControl( m_device_handle,
ioctl_code,
control_buffer,
control_buffer_size,
buffer,
read_size,
&bytes_read,
m_read_asynch_info )
? true : false );
}
else
{
io_complete = GetOverlappedResult( m_device_handle,
m_read_asynch_info,
&bytes_read,
FALSE )
? true : false;
}
m_waiting_for_read = false;
if(!io_complete)
{
// Read failed, or need to wait for asynchronous result
DWORD result = GetLastError();
if(result == ERROR_IO_PENDING)
m_waiting_for_read = true;
else
HandleDeviceIOReadError(status);
}
else
HandleBytesRead( buffer, bytes_read );
Seems sensible...in normal operation:
1. DeviceIoControl returns 0 (io not complete)
2. GetLastError returns ERROR_IO_PENDING
next iteration:
3. GetOverlappedResult returns 1 (io complete)
But here's the bizarre behavior I'm seeing:
1. DeviceIoControl returns 0 (io not complete)
2. GetLastError returns ERROR_IO_PENDING
next iteration:
3. GetOverlappedResult returns 0 (io not complete)
4. GetLastError returns ERROR_SUCCESS
What am I to make of this? Strangely, GetOverlappedResult did set bytes_read to something (bytes_read was set to zero before the call; after the call it was 0x0d, which happens to be the number of bytes that were read on the previous read cycle, which followed the good 1-2-3 pattern. bytes_read cannot be considered to be valid since GetOverlappedResult returned 0, but it is still strange that it's being set. In any case...after GetOverlappedResult returns 0, GetLastError should return ERROR_IO_PENDING or some other actual error, but not ERROR_SUCCESS. Should I interpret ERROR_SUCCESS to mean that the I/O is still pending and call GetOverlappedResult again? If that were the case, why didn't it return ERROR_IO_PENDING?
Thanks in advance,
Brian
|
|
|
|
|
Hi, I get bored that of many variable types that were declired by Microsoft for Visual C++. But still I love programing and have energy to fight with that lots of details included in programing.
So I need a good tutorial to learn variable types, type casting and window API return values. The most I hate and need to learn to show different types of variables for example in an messagebox or edit area. sprintf does allow everting to format as a string? or what else professionals use?
every word that you infor me would pleasent of you?
goog works...
karanba
|
|
|
|
|
Aside from the built-in (i.e., intrinsic) types, you can peruse the various .H files for a plethora of typdef statements, function prototypes, etc.
|
|
|
|
|
How can I get and set time out for winsock?(non-mfc)
Please sent me a piece of code.
thanx.
karanba
|
|
|
|
|
One solution is setsockopt(). You may change the send and/or receive timeout for non-blocking I/O.
// For send
SO_SNDTIMEO
// For receive
SO_RCVTIMEO
Kuphryn
|
|
|
|
|
|
As per the documentation in the source, by defining USE_MALLOC_LOCK, you get thread safe versions of the routines.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
|