简体   繁体   中英

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);

In my subclassing wndproc, I'll have code like this, right, but I can't figure out the syntax for calling the 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#. Subclassing here doesn't mean overriding the .NET base class behavior. It means telling WIN32 to call your function pointer instead of the windows current callback. It has nothing to do with inheritence in C#.

You'll call CallWindowProc by P/Invoke. 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:

[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.

You should use CallWindowProc to call that oldWndProc pointer.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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