DefaultDllImportSearchPathsAttribute 类

定义

指定用于搜索提供平台调用函数的 DLL 的路径。

public ref class DefaultDllImportSearchPathsAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Method, AllowMultiple=false)]
public sealed class DefaultDllImportSearchPathsAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Method, AllowMultiple=false)]
[System.Runtime.InteropServices.ComVisible(false)]
public sealed class DefaultDllImportSearchPathsAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Method, AllowMultiple=false)>]
type DefaultDllImportSearchPathsAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Method, AllowMultiple=false)>]
[<System.Runtime.InteropServices.ComVisible(false)>]
type DefaultDllImportSearchPathsAttribute = class
    inherit Attribute
Public NotInheritable Class DefaultDllImportSearchPathsAttribute
Inherits Attribute
继承
DefaultDllImportSearchPathsAttribute
属性

注解

应用于程序集时,此属性指定默认用于在程序集中的任何代码中搜索为平台调用提供函数的任何 DLL 的路径。 应用于单个平台调用时,此属性将替代为程序集指定的默认搜索路径。

对于指定绝对路径的任何平台调用,将忽略此属性。

使用此属性可防止 Win32 LoadLibraryEx 函数搜索当前工作目录。 这有助于保护应用程序免受恶意软件将 DLL 置于当前工作目录中的攻击,以便当平台调用 Win32 LoadLibraryEx 函数时,函数的默认搜索顺序会查找恶意 DLL,而不是要查找的系统 DLL。

公共语言运行时根据以下算法处理对 LoadLibraryEx 函数的调用:

  1. 如果特性应用于单个平台调用,请使用该特性实例指定的值。

  2. 否则,如果特性应用于包含平台调用的程序集,请使用该属性实例指定的值。

  3. 否则,搜索程序集目录,然后使用标志调用 LoadLibraryEx 函数 LOAD_WITH_ALTERED_SEARCH_PATH

此属性对非Windows平台或 Mono 运行时没有影响。

构造函数

DefaultDllImportSearchPathsAttribute(DllImportSearchPath)

初始化 DefaultDllImportSearchPathsAttribute 类的新实例,该实例指定在搜索目标平台调用时使用的路径。

属性

Paths

获取用于指定平台调用期间 LoadLibraryEx 函数搜索路径的枚举值的按位组合。

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。

(继承自 Attribute)

方法

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。

(继承自 Attribute)
GetType()

获取当前实例的 Type

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

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

将一组名称映射为对应的一组调度标识符。

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

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。

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

提供对某一对象公开的属性和方法的访问。

(继承自 Attribute)

适用于

另请参阅