DllImport property Preservesig

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hi

The doc says the following text within "". Does this text mean that if an
error occur and this property is set to false an exception is throw from the
Windows32 API ?

"This field indicates whether unmanaged methods that have HRESULT or retval
return values are directly translated or automatically converted to
exceptions.

True: The method returns a value that contains the HRESULT.

False: The method automatically converts HRESULT or retval values to
exceptions.

When you set the PreserveSig field to False, the resulting method signature
contains a void return type instead of an integer (HRESULT) return type.

The default value for this field is True."
 
Hi

The doc says the following text within "". Does this text mean that if an
error occur and this property is set to false an exception is throw from the
Windows32 API ?

"This field indicates whether unmanaged methods that have HRESULT or retval
return values are directly translated or automatically converted to
exceptions.

True: The method returns a value that contains the HRESULT.

False: The method automatically converts HRESULT or retval values to
exceptions.

When you set the PreserveSig field to False, the resulting method signature
contains a void return type instead of an integer (HRESULT) return type.

The default value for this field is True."

Technically, I believe the flag means the .Net code provided by the
DllImport to call the method will intercept the HRESULT and convert it
to a thrown exception. It is a layer between your managed caller and
the unmanaged method that generates the exception.
 
Back
Top