DebugActiveProcess() and hooking

This is a discussion on DebugActiveProcess() and hooking within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to hook into another process to increase functionality (no malintent here), and I've come up with the following ...

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    DebugActiveProcess() and hooking

    I'm trying to hook into another process to increase functionality (no malintent here), and I've come up with the following code:

    Code:
    hFind=FindWindow("myWindowClass",NULL);
    GetWindowThreadProcessId(hFind,&dwProcID);
    		if (!DebugActiveProcess(dwProcID))
    			exit(1);
    
    		hChildFind=FindWindowEx(hFind,NULL,"EDIT",NULL);
    		GetWindowText(hChildFind,chName,255);
    DebugActiveProcess() returns non-zero, so I must have the hook. However, I still can't retrieve the edit control text, ie, I still don't have full access to the other process's windows. Is this the right approach?

    EDIT: Another problem: the target process exits when the debugger process does. I searched, but can't find out how to detach the hook. Any ideas?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    You only use DebugActiveProcess if you want to do assembler level modification and analysis, you don't need to use it (and shouldn't use it) for simple modification of edit controls.

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Sorry Elixia, but it simply won't work! I can't access any child windows of any other processes using these techniques. There must some way, other than .dll hooking.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    I got it to work. It seems GetWindowText() is a bit of a doozy, and doesn't always send the message. I sent WM_GETTEXT explicitly and it works fine.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    That'll be because GetWindowText only works on the current process.

    As specified in the developer network CD, and on Microsoft's website:

    "This function cannot retrieve the text of an edit control in another application."

    "This behavior is by design. It allows applications to call GetWindowText without hanging if the process that owns the target window is hung"

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21