[Mono-dev] [PATCH] Cache errno for serial port

Miguel de Icaza miguel at novell.com
Mon Feb 18 20:19:01 EST 2008

Hello Carlos,

> The attached patch adds a 'serial_errno' variable in
> mono/support/serial.c, to cache the last error related to serial port
> functions.
> At first I tried to just create a function directly retrieving errno,
> but it was getting a different value from the original (probably some
> code modified it after the pinvoke call?).
> This is needed to a simple but better error reporting in the
> System.IO.Ports.SerialPort class.

I think you can use DllImport's built-in SetLastError/GetLastError
framework for this.

Just add this to the DllImport definitions:

	[DllImport ("something", SetLastError=true)]

And then in the calling code, call:

	Marshal.GetLastWin32Error ()

This will contain the errno value.

More information about the Mono-devel-list mailing list