Le réseau pour les développeurs > Forums - Accueil > Building Development and Diagnostic Tools for .Net > Getting a reference of an object present in another .net application.
Poser une questionPoser une question
 

TraitéeGetting a reference of an object present in another .net application.

  • dimanche 28 juin 2009 12:34kumar B Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    Hi, 
    For automation purpose i had to get the reference of an object/Control(for e.x a textbox) which is open in another .net application. I was able to retrieve the handle of that .net applcation form. but i was not able to obtain the reference of that form. 
    I tried to using control.FromHandle(handle) function. but it returns a null for the handle i passed since the handle is not associated to the application I am running.
    I also tried to add the handle to my application with the following code.

            Dim nw As New NativeWindow
            nw.AssignHandle(&H100300A)
    '&H100300A is a valid windows handle for an application which is open
            Dim c As Control = Control.FromHandle(nw.Handle)

    but c returned nothing.
    Is there any way using which i can get the reference of an object in another .net appliction from my application.
    Thanks in advance.
    • Modifiékumar B dimanche 28 juin 2009 16:31
    •  

Réponses

  • jeudi 2 juillet 2009 14:38p.b.a Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     Traitée
    Kumar, 

    To get the window managed object itself you will have to be running in the same process as the application that has the UI, Control.FromHandle will give you back the window (managed) object only if the window is in the process where you're making the call from. If you're out of proc to automate the controls you have to use the Win32 API functions like WindowFromPoint, ChildWindowFromPoint, SendMessage /PostMessage and that's what White does. The project is open source (apache license) and even if you cannot use it as a whole you can still link to parts of it (and give them the credit due). 

    If you have control over the target application an alternative would be to make it load your automation assembly - you will be inproc hence able to use the winforms api.

    HTH
    Paul
    • Marqué comme réponsekumar B lundi 6 juillet 2009 11:13
    •  

Toutes les réponses

  • mardi 30 juin 2009 14:19p.b.a Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    You can use this project - http://white.codeplex.com/ to automate your rich client applications.
  • jeudi 2 juillet 2009 11:50kumar B Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    HI p.b.a,
    Thanks for your reply.But this could not resolve the issue becuasethe environment which I am using is .net 2.0, but the prerequisite of WHITE project is .net 3.0. So was not able to work. 


  • jeudi 2 juillet 2009 14:38p.b.a Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     Traitée
    Kumar, 

    To get the window managed object itself you will have to be running in the same process as the application that has the UI, Control.FromHandle will give you back the window (managed) object only if the window is in the process where you're making the call from. If you're out of proc to automate the controls you have to use the Win32 API functions like WindowFromPoint, ChildWindowFromPoint, SendMessage /PostMessage and that's what White does. The project is open source (apache license) and even if you cannot use it as a whole you can still link to parts of it (and give them the credit due). 

    If you have control over the target application an alternative would be to make it load your automation assembly - you will be inproc hence able to use the winforms api.

    HTH
    Paul
    • Marqué comme réponsekumar B lundi 6 juillet 2009 11:13
    •  
  • lundi 6 juillet 2009 11:14kumar B Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    Thanks for the reply