System.Runtime.InteropServices.DllImportAttribute Class

Base Types

Assembly

mscorlib

Library

RuntimeInfrastructure

Summary

Indicates that the target method of this attribute is an export from an unmanaged shared library.

Description

This attribute provides the information needed to call
a method exported from an unmanaged shared library. This attribute provides the name of the
shared library file, the name of the method within that library, the calling convention, and character set of the
unmanaged function.

Compilers are required to not preserve this type
in metadata as a custom attribute. Instead, compilers are required to emit it
directly in the file format, as described in Partition II of the CLI
Specification. Metadata consumers, such as the Reflection API, are required to
retrieve this data from the file format and return it as if it were a custom
attribute.

See Also

A CharSet value that controls function name modification and indicates how the String arguments to the method will be
marshaled.

Description

This field is set to one of the CharSet values to indicate the
required modifications to the name of the imported function and to the String arguments of the
function. The default value for System.Runtime.InteropServices.DllImportAttribute.CharSet is System.Runtime.InteropServices.CharSet.Ansi.

If System.Runtime.InteropServices.DllImportAttribute.CharSet is set to System.Runtime.InteropServices.CharSet.Unicode, all string arguments
are converted to Unicode characters before being passed to the unmanaged
implementation. If the
field is set to System.Runtime.InteropServices.CharSet.Ansi the string characters
are converted to ANSI characters. If System.Runtime.InteropServices.DllImportAttribute.CharSet is set to System.Runtime.InteropServices.CharSet.Auto, the String and function name
conversion is platform dependent.

The System.Runtime.InteropServices.DllImportAttribute.CharSet field might
also be used to determine which version of a function is imported from the
specified shared library by modifying the provided name of the function.
The name modification is platform specific, and includes
additional characters to indicate the character set.

The default value of this field is
System.Runtime.InteropServices.CharSet.Ansi.

Description

See Also

A Boolean
value indicating whether the name of the
entry point in the unmanaged library is modified to correspond to the CharSet value specified in
the System.Runtime.InteropServices.DllImportAttribute.CharSet field.