Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



how to get control handle from dll

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 15-06-2012
Member
 
Join Date: May 2012
Posts: 94
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.

Reply With Quote
  #2  
Old 15-06-2012
Member
 
Join Date: Jun 2006
Posts: 620
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.
Reply With Quote
  #3  
Old 15-06-2012
Member
 
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#
Reply With Quote
  #4  
Old 15-06-2012
Member
 
Join Date: May 2008
Posts: 2,383
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;
}
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "how to get control handle from dll"
Thread Thread Starter Forum Replies Last Post
Would an 850 PSU can handle with GTX 580 in SLI Antton Monitor & Video Cards 5 18-03-2011 11:17 PM
How to handle the virus Sandal wood Networking & Security 3 03-02-2011 07:37 PM
How to handle .net passport Eleeazar Windows Software 3 12-11-2009 08:11 PM
How to Handle the Error Control Operator in PHP Fragman Software Development 3 10-09-2009 02:19 PM
How to handle exception in VBA afidelino Software Development 3 03-09-2009 04:30 PM


All times are GMT +5.5. The time now is 05:17 AM.