简体   繁体   English

在 C# 中,我有一个 IntPtr 到 WIN32 WndProc。 调用它的语法是什么?

[英]In C#, I have a IntPtr to a WIN32 WndProc. What is the syntax for calling it?

I'm subclassing a native window (the edit control of a combobox...)我正在继承本机窗口(组合框的编辑控件......)

oldWndProc = SetWindowLong(HandleOfCbEditControl, GWL_WNDPROC, newWndProc); oldWndProc = SetWindowLong(HandleOfCbEditControl, GWL_WNDPROC, newWndProc);

In my subclassing wndproc, I'll have code like this, right, but I can't figure out the syntax for calling the oldWndProc.在我的 wndproc 子类中,我会有这样的代码,对,但我无法弄清楚调用 oldWndProc 的语法。

    int MyWndProc(int Msg, int wParam, int lParam)
    {
         if (Msg.m ==  something I'm interested in...)
         {
              return something special
         }
         else
         {
              return result of call to oldWndProc  <<<<   What does this look like?***
         }

    }

EDIT: The word "subclassing" in this question refers to the WIN32 API meaning, not C#.编辑:这个问题中的“子类化”一词是指 WIN32 API 的含义,而不是 C#。 Subclassing here doesn't mean overriding the .NET base class behavior.这里的子类化并不意味着覆盖 .NET 基类行为。 It means telling WIN32 to call your function pointer instead of the windows current callback.这意味着告诉 WIN32 调用您的函数指针而不是 Windows 当前回调。 It has nothing to do with inheritence in C#.它与 C# 中的继承无关。

You'll call CallWindowProc by P/Invoke.您将通过 P/Invoke 调用CallWindowProc Just define the parameters as int variables (as it looks like that's how you defined them in the SetWindowLong call), so something like this:只需将参数定义为 int 变量(因为它看起来就像你在 SetWindowLong 调用中定义它们的方式),所以是这样的:

[DllImport("CallWindowProc"...] public static extern int CallWindowProc(int previousProc, int nativeControlHandle, int msg, int lParam, int wParam); [DllImport("CallWindowProc"...] public static extern int CallWindowProc(int previousProc, int nativeControlHandle, int msg, int lParam, int wParam);

Remember, that for marshaling, int, uint and IntPtr are all identical.请记住,对于编组,int、uint 和 IntPtr 都是相同的。

You should use CallWindowProc to call that oldWndProc pointer.您应该使用 CallWindowProc 来调用该 oldWndProc 指针。

[DllImport("user32")]
private static extern int CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, int Msg, int wParam, int lParam);

站点将对您所有的互操作/p-invoke 工作( SetWindowLong )非常有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM