C# 我无法继承通过DllImport导入的方法。怎么办?
我有一个父类,其中包含一些导入的方法,如下所示:C# 我无法继承通过DllImport导入的方法。怎么办?,c#,interop,C#,Interop,我有一个父类,其中包含一些导入的方法,如下所示: class Parent { [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); } 然后我有另一个从父类继承的类 class Child : Parent { GetForegroundWindow(); // intellisense cannot find it } 这是否意味着我必须围绕父类中导入的GetFor
class Parent
{
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
}
然后我有另一个从父类继承的类
class Child : Parent
{
GetForegroundWindow(); // intellisense cannot find it
}
这是否意味着我必须围绕父类中导入的GetForeGroundIndow()方法创建一个包装器方法,以便在子类中继承和使用它?将GetForeGroundIndow调用放在某个类方法内部,而不是直接放在类中 class Child : Parent { void Foo() { GetForegroundWindow(); } } 类子:父 { void Foo() { GetForegroundWindow(); } }
您应该能够从派生类型调用该方法。可能是因为您直接在类内部调用该方法,而不是从方法内部调用?