I’m trying to override the behavior of an external function in user32.dll because I don’t want a certain window to show up.
What I’m trying to do is this:
[DllImport("user32.dll")]
public extern override IntPtr GetSystemMenu(IntPtr hMenu, bool bRevert)
{
return new IntPtr();
}
but this won’t work because I get the following errors:
… no suitable method found to override
and
… cannot be extern and declare a body
Is there any way to simulate what I’m trying to do?
If the source code that calls
GetSystemMenuis within your control then you can provide an alternativeGetSystemMenuwhich delegates to the real one most of the time, but does something different for your special case.If the source code that calls
GetSystemMenuis outside your control then you will need to use hooks. In this situation you need to modify howuser32.GetSystemMenubehaves which is entirely outside your codebase.