[英]I cannot inherit methods imported via DllImport. What to do?
我有一個父類,有一些導入的方法,如下所示:
class Parent
{
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
}
然后我有另一個繼承自這個Parent類的類
class Child : Parent
{
GetForegroundWindow(); // intellisense cannot find it
}
這是否意味着我必須圍繞父類中導入的GetForegroundWindow()方法創建一個包裝器方法,以便在子類中繼承和使用它?
將GetForegroundWindow調用放在某些類方法中,而不是直接在類中。
class Child : Parent { void Foo() { GetForegroundWindow(); } }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.