Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem about injecting a dll to another process and use it to send menu message issues.

Problem about injecting a dll to another process and use it to send menu message issues.

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kcynic
    wrote on last edited by
    #1

    I write a simple dll and inject to another process, i communicate with the target process by sending message via a named pipe. But now, the problem is that, although i can retrieve a top-level window of the target process,i will get no response if i send menu messages to it(the hwnd i retrieved, using EnumWindows, no matter i send the messages in the callback functions of EnumWindows or not, the results are the same). So, i think, the hwnd handle i retrieved was not the target hwnd handle witch was responsible to such activity. But, how could i get the right hwnd to handle these menu messages? Thanks

    M 1 Reply Last reply
    0
    • K kcynic

      I write a simple dll and inject to another process, i communicate with the target process by sending message via a named pipe. But now, the problem is that, although i can retrieve a top-level window of the target process,i will get no response if i send menu messages to it(the hwnd i retrieved, using EnumWindows, no matter i send the messages in the callback functions of EnumWindows or not, the results are the same). So, i think, the hwnd handle i retrieved was not the target hwnd handle witch was responsible to such activity. But, how could i get the right hwnd to handle these menu messages? Thanks

      M Offline
      M Offline
      Malli_S
      wrote on last edited by
      #2

      i will get no response if i send menu messages to it(the hwnd i retrieved, using EnumWindows, no matter i send the messages in the callback functions of EnumWindows or not, the results are the same) Can you please post some code lines (sending menu messages) ?

      [Delegates]      [Virtual Desktop]      [Tray Me !]
      -Malli...! :rose:****

      K 1 Reply Last reply
      0
      • M Malli_S

        i will get no response if i send menu messages to it(the hwnd i retrieved, using EnumWindows, no matter i send the messages in the callback functions of EnumWindows or not, the results are the same) Can you please post some code lines (sending menu messages) ?

        [Delegates]      [Virtual Desktop]      [Tray Me !]
        -Malli...! :rose:****

        K Offline
        K Offline
        kcynic
        wrote on last edited by
        #3

        I wrote enumwindows callback function like following:
        BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
        {
        DWORD procId;
        GetWindowThreadProcessId(hwnd,&procId);
        log_message("Main window search callback function is called.");
        if(procId==(DWORD)lParam){

              ....the message would to be send here
             
               return FALSE;
             }
        

        return TRUE;
        }

        I send the menu message in two ways: 1. HMENU trayMenu = GetMenu(hwnd); if(trayMenu!=NULL){//usually equal to NULL, and according to the failure in method 2(send msg no response) i think i got the wrong hwnd handle HMENU subMenu = GetSubMenu(trayMenu,0); if(subMenu!=NULL){ DWORD menuItemId=GetMenuItemID(subMenu,0); if(menuItemId!=-1) SendMessage(hwnd,WM_COMMAND,menuItemId,0); } } 2.Because i can get the menu resource id, and, this code is implemented in a injected dll to the target process, so, there is a second method here: HMENU trayMenu = LoadMenu(GetModuleHandle(NULL),MAKEINTRESOURCE(IDM_MENU)); if(trayMenu!=NULL){//successfully always ...the other code looks the same with the method 1, but the target process's specified routine will not be actived, because its no response.

        M 1 Reply Last reply
        0
        • K kcynic

          I wrote enumwindows callback function like following:
          BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
          {
          DWORD procId;
          GetWindowThreadProcessId(hwnd,&procId);
          log_message("Main window search callback function is called.");
          if(procId==(DWORD)lParam){

                ....the message would to be send here
               
                 return FALSE;
               }
          

          return TRUE;
          }

          I send the menu message in two ways: 1. HMENU trayMenu = GetMenu(hwnd); if(trayMenu!=NULL){//usually equal to NULL, and according to the failure in method 2(send msg no response) i think i got the wrong hwnd handle HMENU subMenu = GetSubMenu(trayMenu,0); if(subMenu!=NULL){ DWORD menuItemId=GetMenuItemID(subMenu,0); if(menuItemId!=-1) SendMessage(hwnd,WM_COMMAND,menuItemId,0); } } 2.Because i can get the menu resource id, and, this code is implemented in a injected dll to the target process, so, there is a second method here: HMENU trayMenu = LoadMenu(GetModuleHandle(NULL),MAKEINTRESOURCE(IDM_MENU)); if(trayMenu!=NULL){//successfully always ...the other code looks the same with the method 1, but the target process's specified routine will not be actived, because its no response.

          M Offline
          M Offline
          Malli_S
          wrote on last edited by
          #4

          Try to find out whether you are retrieving ID of the right menu item. Call GetMenuString() for that item and debug print it. If you send the message for menu item which consists of submenu, that won't help you (application doesn't display out the submenu as a result).

          [Delegates]      [Virtual Desktop]      [Tray Me !]
          -Malli...! :rose:****

          K 1 Reply Last reply
          0
          • M Malli_S

            Try to find out whether you are retrieving ID of the right menu item. Call GetMenuString() for that item and debug print it. If you send the message for menu item which consists of submenu, that won't help you (application doesn't display out the submenu as a result).

            [Delegates]      [Virtual Desktop]      [Tray Me !]
            -Malli...! :rose:****

            K Offline
            K Offline
            kcynic
            wrote on last edited by
            #5

            im sorry to reply so latter. i have gone to another city. and i know them problem now, i got the right menu, menuitems and menuIDs, but sent the menu message to a wrong hwnd. The program has more than one toplevel hwnd, so, i retieve all its top level hwnds and send menu message it them. then, when i got the right hwnd, the message would send successfully.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups