2012-07-24 35 views
1

我想在C#中創建一個dll文件,該文件具有一個調用Application.AddMessageFilter()的Win表單加載此DLL的靜態方法。如何調用DLL中的Application.AddMessageFilter

例如,

public Form1() 
{ 
    // initializing 
    MyDll.InvokeFilter(SomeClass); // Perfect! 
} 

而且我不希望它看起來像如下,(我甚至不認爲這個代碼將正常工作,雖然)

public Form1() 
{ 
    // initializing 

    // Send also the delegate to Application.AddMessageFilter as a parameter 
    // to let MyDll know it, which is not as good. 
    MyDll.InvokeFilterWithDelegate(SomeClass, Application.AddMessageFilter); 
} 

的事情是我不知道如何從我的Dll文件調用Application.AddMessageFilter,因爲Application類屬於Form1,而不是我的Dll庫。

我錯過了什麼?

在此先感謝。

回答

2

Application類,或更具體地System.Windows.Forms.Application不屬於「屬於Form1」,它可以在System.Windows.Forms.dll找到。在您的DLL項目中添加對它的引用。

ApplicationContexts存在潛在的問題,但調用者不可能從除主UI線程以外的其他任何東西進行調用。儘管如此,如果「SomeClass」僅僅是IMessageFilter的實現,那麼庫函數的重點是什麼?他們可以自己撥打Application.AddMessageFilter

+0

非常感謝! – 2012-07-27 01:43:31