The FCL provides a set of attributes you can use to mark up your objects with information that is used by the CLR marshaling services to alter their default marshaling behavior.
This section describes the most common attributes you need when
interoperating with native Win32 DLLs. These attributes all exist in the
[DllImport (dll-name [, EntryPoint=function-name]? [, CharSet=charset-enum]? [, SetLastError=true|false]? [, ExactSpelling=true|false]? [, PreserveSig=true|false]? [, CallingConvention=callconv-enum?)] (for methods)
DllImport attribute annotates an external function that defines
a DLL entry point. The parameters for this attribute are as follows:
A string specifying the name of the DLL.
A string specifying the function name in the DLL. This is useful if you want the name of your C# function to be different from the name of the DLL function.
A CharSet enum, specifying how to marshal strings. The default value
CharSet.Auto, which converts strings to ANSI characters on Win98, and to Unicode
characters on WinNT.
true, preserves the Win32 error info. The default is
EntryPoint must exactly match the function. If
heuristics are used. The default is
true, the method signature is preserved exactly as it was defined.
false, an HRESULT transformation ...