Get HINSTANCE of another process

This is a discussion on Get HINSTANCE of another process within the Windows Programming forums, part of the Platform Specific Boards category; Well a need came up for me to bust out with the windows programming again I'm trying to create a ...

  1. #1
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681

    Get HINSTANCE of another process

    Well a need came up for me to bust out with the windows programming again

    I'm trying to create a program that will use a hook into another program to send it keyboard messages.

    I know that I'll need to create a DLL that will handle the keyboard events and use SetWindowsHookEx to hook the DLL into the other process.

    The problem is thatI'm not sure how to get the HINSTANCE of the other process using only the image name.

    Using some code by bennyandthejets here I am able to get the HWND using the window title. While using the window title works its not ideal but thats ok for now. Is there a function that I'm missing to get the HINSTANCE from the HWND?

    Thanks

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Use GetModuleHandle() to get a handle to the process (GetModuleHandle() returns a HMODULE, but it's the same as HINSTANCE on 32 bit windows).

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Could you elaborate on what you are trying to achieve? Typically, you don't need to hook another process to send keyboard messages. Are you trying to intercept keyboard messages sent to the other process?

    Why do you need the HINSTANCE of the other process? HINSTANCEs have limited use outside the process where they were provided.

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    I'm trying to intercept and send keyboard messages to another process, even if it is not the window with focus.
    HINSTANCE is the 3rd parametered required for SetWindowsHookEx.

    Gah! Just re-read the info for that function for about the 10th time and finally got it. I don't need the handle of the process, I just need the thread id.

    bithub: GetModuleHandle does not work in this situation. I tried that awhile ago

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. init adopts zombie process?
    By password636 in forum Linux Programming
    Replies: 4
    Last Post: 07-01-2009, 10:05 AM
  2. create a child process that creates a child process
    By cus in forum Linux Programming
    Replies: 9
    Last Post: 01-13-2009, 01:14 PM
  3. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  4. Problem with forking a process
    By Unitedroad in forum C Programming
    Replies: 10
    Last Post: 10-04-2007, 01:43 AM
  5. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM

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