CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2009
    Posts
    6

    Question I've a question about SetWindowHookEx

    hello
    I've a question..
    It may be involved in how callback function works
    anyway what I wonder is.. why we should use dll when using SetWindowHookEx
    I'm meaning global hooking.. when callback function(HOOKFUNC) is called in other process by OS
    the address is function is matched into memory address of the process ?
    if A process used SetWindowHookEx with paramater 7h
    (suppose 7h is the address of HOOKFUNC), when HOOKFUNC is called in B process (maybe
    there occured message from B process), Does the address of HOOKFUNC (7h) match to the memory address of B process ? if it's true I'm likely to know why HOOKFUNC should be dll..
    but isn't it possible that OS calls HOOKFUNC which is defined in exefile of A process no matter
    what process provided a message? I leaned each process can't access other's memory.. but
    'cause it's OS that calls HOOKFUNC, I think it may be possible to access the address of HOOKFUNC in A process.. anyway the point is that why in gloabl hooking, HOOKFUNC should
    be in dll..
    thanks

    P.S: 'cause english is not mother tongue, it's hard to explain my problem.. plz take time
    to catch meaning..

  2. #2
    Join Date
    Aug 2008
    Posts
    18

    Re: I've a question about SetWindowHookEx

    No need that ur procedure in dll
    it may contain in ur own process also

  3. #3
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: I've a question about SetWindowHookEx

    You need the function inside the DLL because in another process your local code can not be seen, it's the process address space issue. Operating system lets each process see the whole memory as a private view, no one can use another processes memory from it's own address space.
    The hook DLL get loaded in other processes, thus becomes local there, and that's how it can trap the messages in that address space.
    Regards,
    Ramkrishna Pawar

  4. #4
    Join Date
    Jul 2009
    Posts
    6

    Question Re: I've a question about SetWindowHookEx

    Quote Originally Posted by Krishnaa View Post
    You need the function inside the DLL because in another process your local code can not be seen, it's the process address space issue. Operating system lets each process see the whole memory as a private view, no one can use another processes memory from it's own address space.
    The hook DLL get loaded in other processes, thus becomes local there, and that's how it can trap the messages in that address space.
    you seem to know the answer what I need
    I almost understood what you told but.. I learned that callback function is called by OS not process. then doesn't it mean other processes doesn't need to access HOOKFUNC directly ? thus
    they don't need to know the address of HOOKFUNC..
    that's what I imagined.. but according to your reply
    even if callback function is called by OS, process
    also should know the address of callback function?
    if it's true my question will be cleared..
    thanks for your reply

  5. #5
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: I've a question about SetWindowHookEx

    The hook callback function is called inside the target process, yes offcource by the OS, but you need to understand that this "OS" is running inside the process too, and that OS component is GDI32.DLL, it has the mechanism to load the hook function DLL inside all required processes, and then make call to the hook callback function inside that process.

    When you ask "process should know the address?" I would answer "Yes", because the GDI32 hook mechanism needs to know this, and it knows it as you mentioned that while setting the hook. But the other part of target process never knows and need not know what's going on.
    Regards,
    Ramkrishna Pawar

  6. #6
    Join Date
    Jul 2009
    Posts
    6

    Smile Re: I've a question about SetWindowHookEx

    Quote Originally Posted by Krishnaa View Post
    The hook callback function is called inside the target process, yes offcource by the OS, but you need to understand that this "OS" is running inside the process too, and that OS component is GDI32.DLL, it has the mechanism to load the hook function DLL inside all required processes, and then make call to the hook callback function inside that process.

    When you ask "process should know the address?" I would answer "Yes", because the GDI32 hook mechanism needs to know this, and it knows it as you mentioned that while setting the hook. But the other part of target process never knows and need not know what's going on.
    Very thanks!!
    You seem to be a creator of the windows
    thanks again and have a nice day

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured