ReadFile, DCB and OVERLAPPED

  • Thread starter Thread starter Empi
  • Start date Start date
E

Empi

Hi,

Several questions regarding serial I/O.

1) I got confused regarding the DCB flags.
On msdn, these flags (fBinary; fParity; fOutxCtsFlowfErrorChar etc) are
defined as 32 bitsvariable,
while on MSpress book MS Compact Framework, I find a DCB on which each
flag gets an int (DWORD).
What does coredll.dll really expect?
Did the compramise in order to accept both structures (using the dcb
length) in order to help c# ? (no trivial support for defining bit flags).

2) How can I pass null to ReadFile when OVERLAPPED is not really used?
I've found several ReadFile samples that simply define an OVERLAPPED,
passing a ref to it without setting anything in it.
Can't I kust pass a null? (trying to do so gave a compiler error
regarding this parameter (fifth)).

Thanks.
 
1) I got confused regarding the DCB flags.
On msdn, these flags (fBinary; fParity; fOutxCtsFlowfErrorChar etc) are
defined as 32 bitsvariable,
while on MSpress book MS Compact Framework, I find a DCB on which each
flag gets an int (DWORD).
What does coredll.dll really expect?

The docs are clear that each is a bit in a 32-bit DWORD, so that is what
must go into the API.
Did the compramise in order to accept both structures (using the dcb
length) in order to help c# ? (no trivial support for defining bit flags).

I don't see a compromise (thout I'm also not looking at whatever book you
have). Managed code can use bit fields in the BitVector32 class, so that's
what I'd likely choose for this, but I can't say what they did use. The
other option would be boolean accessors that all hit the same 32-bit (uint
or int) value at different offsets.
2) How can I pass null to ReadFile when OVERLAPPED is not really used?
I've found several ReadFile samples that simply define an OVERLAPPED,
passing a ref to it without setting anything in it.

Define the P/Invoke to take an IntPtr and pass it IntPtr.Zero or as a
int/uint and pass it 0. NULL in native code is #defined as 0.
Can't I kust pass a null? (trying to do so gave a compiler error
regarding this parameter (fifth)).

No. Managed code has a different definition of null than native. They are
not equivalent.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com
 
To add to what Chris said, you can find example code on www.opennetcf.org,
or (also) in my book. The Compact Framework 2 (VS 2005) has a built-in
SerialPort object (System.IO.Ports), so unless you are using CF1, you
probably should stick with it.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 
Back
Top