DefaultDllImportSearchPathsAttribute 类


指定用于搜索提供平台调用函数的 DLL 的路径。Specifies the paths that are used to search for DLLs that provide functions for platform invokes.

public ref class DefaultDllImportSearchPathsAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Method, AllowMultiple=false)]
public sealed class DefaultDllImportSearchPathsAttribute : Attribute
type DefaultDllImportSearchPathsAttribute = class
    inherit Attribute
Public NotInheritable Class DefaultDllImportSearchPathsAttribute
Inherits Attribute


当应用于程序集时,此特性指定默认情况下用于在程序集的任何代码中搜索为平台调用提供函数的任何 DLL 的路径。When applied to an assembly, this attribute specifies the paths that are used by default to search for any DLL that provides a function for a platform invoke, in any code in the assembly. 当应用于单个平台调用时,此特性将重写为程序集指定的默认搜索路径。When applied to an individual platform invoke, this attribute overrides the default search paths that were specified for the assembly.

对于指定绝对路径的任何平台调用,将忽略此属性。This attribute is ignored for any platform invoke that specifies an absolute path.

使用此特性可防止 Win32 LoadLibraryEx 函数搜索当前工作目录。Use this attribute to prevent the Win32 LoadLibraryEx function from searching the current working directory. 这有助于保护应用程序免受恶意软件在当前工作目录中放置 DLL 的攻击,因此当平台调用调用 Win32 LoadLibraryEx 函数时,函数的默认搜索顺序将查找恶意 DLL,而不是它要查找的系统 DLL。This helps protect your application from attacks in which malicious software places a DLL in the current working directory, so that when a platform invoke calls the Win32 LoadLibraryEx function, the function's default search order finds the malicious DLL instead of the system DLL it was intended to find.

公共语言运行时根据以下算法处理对LoadLibraryEx函数的调用:The common language runtime handles the call to the LoadLibraryEx function according to the following algorithm:

  1. 如果将属性应用于单个平台调用,请使用该属性的实例指定的值。If the attribute is applied to an individual platform invoke, use the values specified by that instance of the attribute.

  2. 否则,如果将特性应用于包含平台调用的程序集,则使用该特性的实例指定的值。Otherwise, if the attribute is applied to the assembly that contains the platform invoke, use the values specified by that instance of the attribute.

  3. 否则,请搜索程序集目录,然后用 LOAD_WITH_ALTERED_SEARCH_PATH 标志调用 LoadLibraryEx 函数。Otherwise, search the assembly directory and then call the LoadLibraryEx function with the LOAD_WITH_ALTERED_SEARCH_PATH flag.



初始化 DefaultDllImportSearchPathsAttribute 类的新实例,该实例指定在搜索目标平台调用时使用的路径。Initializes a new instance of the DefaultDllImportSearchPathsAttribute class, specifying the paths to use when searching for the targets of platform invokes.



获取用于指定平台调用期间 LoadLibraryEx 函数搜索路径的枚举值的按位组合。Gets a bitwise combination of enumeration values that specify the paths that the LoadLibraryEx function searches during platform invokes.


在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(继承自 Attribute)



返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(继承自 Attribute)

返回此实例的哈希代码。Returns the hash code for this instance.

(继承自 Attribute)

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(继承自 Attribute)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)


_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(继承自 Attribute)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)