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。

Common Language Runtime 會根據下列演算法處理 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)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱