On Monday 02 November 2009, you wrote:
> Hi Jeroen,
>
> I'm using fox toolkit on MS VC 6.
> I'm facing some problem with addInput() function.
>
> I've done the following
> 1. opened a file descriptor (FILE *) using fopen function.
> 2. Linked the file descriptor to an ID_FILE using addInput with flags
> INPUT_READ|INPUT_WRITE|INPUT_EXCEPT
> 3. added code in message map to link SEL_IO_WRITE and ID_FILE to a function
> OnFile
> 4. added button. on pressing the button, some data is written on the file.
>
> When data s being written on the file, I am expecting the function OnFile to
> be called, but that is not the case.
>
> I am attaching a copy the VC workspace. Please let me know whats wrong.
>
> Thanks and regards,
> -Kranthi
>
Kranthi,
No, this wouldn't work on Windows. And neither would it work on Linux.
First, when you call fopen(), the caller doesn't get an operating system
handle, but a pointer (FILE*). A FILE is a C-library thing which performs
buffered I/O.
To get a file handle, you will need to call open() (unbuffered I/O) or fish
the file handle from FILE* by calling fileno().
This would be enough on Linux.
However, on Windows, POSIX is itself another layour on top of the WIN32 API.
The POSIX layer on Windows does *not* return WIN32 kernel handles!!
To be able to wait on a HANDLE using addInput(), you should pass a NT kernel
handle, such as something returned directly by WIN32 APIs, not POSIX APIs.
Internally, FOX uses MsgWaitForMultipleObjects() as the system call to wait
on various handles. All these handles have to be WIN32 kernel handles, such
as are returned by WIN32 system calls (e.g. CreateEvent, CreateThread, etc).
Doing asynchronous I/O is possible on Windows, but its not so straightforward;
in fact, I'd recommend instead to create a separate I/O thread, let the I/O
thread do simple synchronous I/O, and let the main thread wait on the I/O thread
instead.
But if you absolutely insist... The first thing is to forget about POSIX system
calls, and instead use WIN32 API's exclusively.
In a nutshell, you can't actually wait on a file handle under Windows; you must
associate an Event object with a particular file I/O operarion through an OVERLAPPED
structure passed along with ReadFile or ReadFileEx.
I won't type up the entire story here on how to do it; first, it would take rather
long, and second, its been done by more knowledgable people already.
If you want to get the entire scoop, surf over to MSDN and search for:
"Synchronization and Overlapped Input and Output"
I also recommend "Code Guru" as a source for example code dealing with all sorts
of Windows programming issues.
Hope this helps,
- Jeroen
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference_______________________________________________
Foxgui-users mailing list
Foxgui-users@...
https://lists.sourceforge.net/lists/listinfo/foxgui-users