Hooking a Richedit

Dec 25, 2008 at 12:45 AM

I have a problem, and i am not sure, if i can use your library this way.

I want to get the text from a Richedit as it is beeing added. I have c++ code from a tutorial that works, and i want to port it to c#.

In detail i want to:
1. intercept all message to the richedit
2. filter for EM_STREAMIN messages
3. Install my own EditStreamCallback function for this message and call the original message handler in the richedit.
4. my EditStreamCallback calls the original callback func, so nothing should be lost.

My problem is at the point where i want to install the hook for the messages. In the c++ code it is been done like that:
        HWND hwndChat = ::FindWindowEx(hWnd, NULL, _T("RichEdit20W"), NULL);
        MyWindow::OldRichWndProc = (WNDPROC)::GetWindowLongPtr(hwndChat, GWL_WNDPROC);
        ::SetWindowLongPtr(hwndChat, GWL_WNDPROC, (LONG_PTR)MyWindow::MyRichWndProc);

What i am doing:
        [DllImport("user32.dll", EntryPoint = "GetWindowLong")]
        private static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex);
        private delegate IntPtr EditStreamCallback(IntPtr dwCookie, IntPtr pbBuff, IntPtr wParam, ref IntPtr lParam);
        IntPtr myRichWndProc(IntPtr hwnd, IntPtr msg, IntPtr wParam, ref IntPtr lParam){...}

OldRichWndProc = GetWindowLongPtr(hwndChat, GWL_WNDPROC);//hwndChat is the valid hwnd(checked this)
LocalHook ChatBoxHook = LocalHook.Create(OldRichWndProc, new EditStreamCallback(myRichWndProc), this);

should i be using SetWindowLongPtr? Or should this code be working, and i am just missing something?

thx in advance,