IOCTL using <ddk/ntddser.h>

Corinna Vinschen corinna-cygwin@cygwin.com
Thu Mar 12 15:27:00 GMT 2009


On Mar 12 14:52, Bert wrote:
> Corinna Vinschen <corinna-cygwin <at> cygwin.com> writes:
> > On Mar 11 22:57, Bert wrote:
> > > I hope I'm doing something really dumb, any tips?
> > 
> > Yes.  You're mixing POSIX calls with Windows defines.  That's a no-no.
> > When you're in Rome, talk like the Romans do.
> > 
> > Corinna
> > 
> 
> Many thanks Corinna. If I understand you correctly, "talk like the Romans" means
> "just make everything pure POSIX calls", right?  

Right.

> Secondly, if that's the case, what would the purpose of the Windows defines be?
> (Apart from confusing simple folks like me :)  Put another way, if I want to use
> those defines (i.e. flee Rome and settle in Babylon), what version of ioctl
> should I call and what libs should I link in?  

The native Windows headers provide you with a means to use native
Windows calls from a Cygwin application.

In your case, either talk POSIX with the com interface 
  
  open("/dev/com4");		// Btw. "/dev/ttyS3" is preferred
  ioctl(POSIX_IOCTL_CODE);
  close;

or talk Windows

  CreateFile("COM4:", ...);
  DeviceIoControl(WIN32_IOCTL_CODE);
  CloseHandle;

but don't mix them.  You will do yourself no good.  Given that the
Cygwin DLL has to keep track of state information, that should be clear.

If you open a file with a POSIX call, stick to POSIX for handling the
file until you close it.  The Cygwin DLL will do the translations.

If you need direct control for some reason, open the file with a
Windows call and stick to Windows calls until you close the file.

> Thirdly, and I'm probably pushing it now, if you have some favorite references
> to read on the above dichotomy? I'd appreciate the pointer. Or is it *pointer?

The dichotomy is mostely in your mind.  As soon as you realize that
Cygwin is a POSIX emulation layer on top of Windows, the above should
be quite clear.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list