Prev: Data type enforcement in DataGridView
Next: using a String Builder a actual parameter and LPTSTR as formal parameter in unmanaged code
From: Peter Duniho on 29 Apr 2010 22:12 Tony Johansson wrote: > Hi! > > Does any of those Win32 API functions throw Exceptions that I can catch in > my managed code or do they use the GetLastError which cause that I have to > use the Marshal.GetLastWin32Error ? No Win32 functions throw exceptions. For those functions that don't return HRESULTs, you'll need to use GetLastWin32Error(). For those that do return HRESULTs, you can use the PreserveSig field of the DllImportAttribute, setting it to false to have the marshaler convert HRESULT error codes to exceptions. Pete
From: Tony Johansson on 30 Apr 2010 03:01 "Peter Duniho" <no.peted.spam(a)no.nwlink.spam.com> skrev i meddelandet news:ujP0gqA6KHA.4940(a)TK2MSFTNGP05.phx.gbl... > Tony Johansson wrote: >> Hi! >> >> Does any of those Win32 API functions throw Exceptions that I can catch >> in my managed code or do they use the GetLastError which cause that I >> have to use the Marshal.GetLastWin32Error ? > > No Win32 functions throw exceptions. For those functions that don't > return HRESULTs, you'll need to use GetLastWin32Error(). For those that > do return HRESULTs, you can use the PreserveSig field of the > DllImportAttribute, setting it to false to have the marshaler convert > HRESULT error codes to exceptions. > > Pete You say For those that do return HRESULTs, you can use the PreserveSig field of the DllImportAttribute, setting it to false to have the marshaler convert HRESULT error codes to exceptions. Why is it not possible to use the the returned HRESULT ? //Tony
From: Peter Duniho on 30 Apr 2010 11:39
Tony Johansson wrote: > [...] > You say > For those that do return HRESULTs, you can use the PreserveSig field of the > DllImportAttribute, setting it to false to have the marshaler convert > HRESULT error codes to exceptions. > > Why is it not possible to use the the returned HRESULT ? What makes you think it's not? I only said you _can_ set the PreserveSig field to false, not that you _must_. |