Results 1 to 4 of 4

Thread: how to get control handle from dll

  1. #1
    Join Date
    May 2012
    Posts
    97

    how to get control handle from dll

    Is it possible to get a control handle of a particular control in the windows dialog when i inject a dll into the dialog? I have tried the same but it didnt work and for that I have also searched Microsoft articles via winAPI but did not get any successful results? I am not able to find the main dialog handle as well? Can anyone please teach me how to do the same. Thanks in advance.

  2. #2
    Join Date
    Jun 2006
    Posts
    625

    Re: how to get control handle from dll

    You can try to call FindWindows, which is explained more here on this link, with the name of window to get the handle on the main dialog window or even if you call the classname, which should be known by you, with Spy++ you can easily grab it as an argument. After that you can call EnumChildWindows, code for it is here, to search for the handles to the controls within the main dialog.

  3. #3
    Join Date
    Jan 2006
    Posts
    605

    Re: how to get control handle from dll

    You can also use IntPtr type to pass Handle. IntPtr type is being used in the Control.Handle Property, if you can see for example. C# functions that is the API can used by C++ classes but it can used directly in C#. You can use C++/CLI wrapper that calls C++ classes directly and exposes .NET interface to C# client, which will be the best way to use C++ code. Although C++/CLI is a better way, there are other way to C wrapper for C++ classes and using it from C#

  4. #4
    Join Date
    May 2008
    Posts
    2,393

    Re: how to get control handle from dll

    Check out the below sample code that will help you to get started:

    Code:
    #define Title 0x130
    
    BOOL CALLBACK EnumChildProc
    (
      HWND hwnd,
      LPARAM lParam
    )
    {
      TCHAR szWindowText[256];
      HWND* lpHwndReceiver = (HWND*)lParam;
      
      GetWindowText
      (
        hwnd,
        szWindowText,
        sizeof(szWindowText)
      );
      
      if (_tcscmp(szWindowText, TEXT("start")) == 0)
      {
        LONG_PTR lValTemp = GetWindowLongPtr
        (
          hwnd,
          GWLP_ID
        );
        
        if (lValTemp == Title)
        {
          *lpHwndReceiver = hwnd;
          return FALSE;
        }
      }
      
      return TRUE;
    }
    
    void GetStartButton1(HWND& hWndStartButtonReceiver)
    {
     hWndStartButtonReceiver = NULL;
     
     HWND hWndShellTrayWindow = NULL;
     
     hWndShellTrayWindow = FindWindow(TEXT("Shell_TrayWnd"), NULL);
     
     if (hWndShellTrayWindow)
     {
       EnumChildWindows
       (
         hWndShellTrayWindow,
         EnumChildProc,
         (LPARAM)&hWndStartButtonReceiver
       );
     }
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {    
        HWND hWndStartButton = NULL;
        
        GetStartButton1(hWndStartButton);
         
        return 0;
    }

Similar Threads

  1. Would an 850 PSU can handle with GTX 580 in SLI
    By Antton in forum Monitor & Video Cards
    Replies: 5
    Last Post: 18-03-2011, 10:17 PM
  2. How to handle the virus
    By Sandal wood in forum Networking & Security
    Replies: 3
    Last Post: 03-02-2011, 06:37 PM
  3. How to handle .net passport
    By Eleeazar in forum Windows Software
    Replies: 3
    Last Post: 12-11-2009, 07:11 PM
  4. How to Handle the Error Control Operator in PHP
    By Fragman in forum Software Development
    Replies: 3
    Last Post: 10-09-2009, 01:19 PM
  5. How to handle exception in VBA
    By afidelino in forum Software Development
    Replies: 3
    Last Post: 03-09-2009, 03:30 PM

Posting Permissions

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