C# - Capturing Windows Messages from a specific application

前端 未结 2 2024
醉酒成梦
醉酒成梦 2020-12-29 15:43

I\'m writing a C# application which needs to intercept Window Messages that another applications is sending out. The company who wrote the application I\'m

相关标签:
2条回答
  • 2020-12-29 16:32

    Turns out I also needed to send the other application a PostMessage asking it to send my application the Window Messages.

    PostMessage((int)_hWnd, _windowsMessages[0], SHOCK_REQUEST_ACTIVE_CALLINFO, (int)_thisHandle);
    PostMessage((int)_hWnd, _windowsMessages[0], SHOCK_REQUEST_ALL_REGISTRATIONINFO, (int)_thisHandle);
    PostMessage((int)_hWnd, _windowsMessages[0], SHOCK_REQUEST_CALL_EVENTS, (int)_thisHandle);
    PostMessage((int)_hWnd, _windowsMessages[0], SHOCK_REQUEST_REGISTRATION_EVENTS, (int)_thisHandle);
    

    Not pretty code, but good enough to prove it works which is all I need for now :)

    0 讨论(0)
  • 2020-12-29 16:46

    I think the problem is with your P/Invoke definition for RegisterWindowMessage(). pinvoke.net suggests using the following:

    [DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)]
    static extern uint RegisterWindowMessage(string lpString);
    

    Using uint as the return value instead of IntPtr should make the difference. Typically you want to use IntPtr when the return value is a handle (such as an HWND or HANDLE), but when the return value can be directly converted to a C# type it is better to use that type.

    0 讨论(0)
提交回复
热议问题