Visual C++ Developer Center >
Visual C++ Forums
>
Visual C++ General
>
sharing a HWND with another process
sharing a HWND with another process
- Hi..
I'm making a browser plugin that launches a process with CreateProcess, and sets the HWND of the plugin window as an environment variable. The new process gets the HWND and draws there. So far this works, my process can draw on the browser, but when I try to set the WNDPROC to receive events, I get ERROR_ACCESS_DENIED from SetWindowLongPtr (and also GetWindowLongPtr).
Do I need to do something to the HWND on the host process to allow the child to use it?
thanks
(also, what's the right forum to ask this? none of the forums listed seemed to be right)
Answers
- Hi,
Sorry for late reply.
To subclass a window created by another process with GWLP_WNDPROC, your code must be in the same process space with the target process, so DLL injecting is the only way I know.
Quotes<<is that "standard" behavior?
Drawing is the job of Windows GDI or others, we can paint to the window once we get its handle "HWND", it has no need of "in the same process space with the target process".
Sincerely,
Wesley
Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer bypete275 Monday, November 09, 2009 10:42 PM
All Replies
- Are you running on Vista or above?What is the IE version you're writing the plugin for?
«_Superman_»
Microsoft MVP (Visual C++) - I'm running XP, it's a firefox plugin based on "npsimple" (a "hello world" type example of np plugins, http://git.webvm.net/?p=npsimple)
will there be different access issues on vista/above? - There will definitely be security issues in Vista because you're browser is spawning another process.
«_Superman_»
Microsoft MVP (Visual C++) - well, my process is spawning, and I have access to the hard drivers and all that, so that's cool. I just can't get events on the window
According to the documentation of SetWindowLongPtr Function:
Calling SetWindowLongPtr with the GWLP_WNDPROC index creates a subclass of the window class used to create the window. An application can subclass a system class, but should not subclass a window class created by another process.
But it's not complete, SetWindowLongPtr() will check whether you are changing the wndproc of the window created by another process, if yes, it will ignore the calling and just return NULL.
Technically, DLL injecting can do the trick, but hooking other processes is not recommended and supported here.
Sincerely,
Wesley
Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- is there a way to maybe forward the events from the host process? also, the fact that I can draw to the window of another process, is that "standard" behavior? (since I can't get events from it, it sounds like it might be a glitch or side effect of something else, and it could get "fixed" in the future).
thanks - Hi,
Sorry for late reply.
To subclass a window created by another process with GWLP_WNDPROC, your code must be in the same process space with the target process, so DLL injecting is the only way I know.
Quotes<<is that "standard" behavior?
Drawing is the job of Windows GDI or others, we can paint to the window once we get its handle "HWND", it has no need of "in the same process space with the target process".
Sincerely,
Wesley
Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer bypete275 Monday, November 09, 2009 10:42 PM


