Indicates whether unmanaged methods that have HRESULT or retval return values are directly translated or whether HRESULT or retval return values are automatically converted to exceptions.
Assembly: mscorlib (in mscorlib.dll)
Set the field to true to directly translate unmanaged signatures with HRESULT or retval values; set it to false to automatically convert HRESULT or retval values to exceptions. By default, the field is true.
When true, the resulting method signature returns an integer value that contains the HRESULT value. In this case, you must manually inspect the return value and respond accordingly in your application.
When you set the field to false, the resulting method signature contains a void return type instead of an integer (HRESULT) return type. When the unmanaged method produces an HRESULT, the runtime automatically ignores a return value of S_OK (or 0) and does not throw an exception. For HRESULTs other than S_OK, the runtime automatically throws an exception that corresponds to the HRESULT. Note that the DllImportAttribute attribute only performs this conversion to methods that return an HRESULT.
You might decide to change the default error reporting behavior from HRESULTs to exceptions in cases where exceptions better fit the error reporting structure of your application.
This field is similar to the PreserveSigAttribute; however, in contrast to the field, the default value for the attribute is false.
In some cases, Visual Basic developers use the DllImportAttribute, instead of using the Declare statement, to define a DLL function in managed code. Setting the field is one of those cases.
The following code example uses the DllImportAttribute to import the unmanaged SHAutoComplete function once with the field set to true and again with the field set to false. This code example causes the SHAutoComplete function to generate any errors with an exception one time and an HRESULT the next.
.NET FrameworkSupported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
Portable Class LibrarySupported in: Portable Class Library
.NET for Windows Store appsSupported in: Windows 8
Supported in: Windows Phone 8.1
Supported in: Windows Phone Silverlight 8.1
Supported in: Windows Phone Silverlight 8
Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)