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#
  4. How to cast an object using its handle?

How to cast an object using its handle?

Scheduled Pinned Locked Moved C#
csharptutorialasp-netjson
8 Posts 3 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.
  • M Offline
    M Offline
    MAP Tiger
    wrote on last edited by
    #1

    Hi Is there any possibility that I could cast an object through its handle. For example, I have to do an estimation of objects and finally I get the handle of that object through GetWindow API call, now I know its type but how to retrieve that object and cast it for that specific type? I am implementing it using a dll file. Regards,

    Mujtaba Panjwani Tiger Softwares Software Designer and Developer VB.NET, C#, ASP.NET, VFP

    M D 2 Replies Last reply
    0
    • M MAP Tiger

      Hi Is there any possibility that I could cast an object through its handle. For example, I have to do an estimation of objects and finally I get the handle of that object through GetWindow API call, now I know its type but how to retrieve that object and cast it for that specific type? I am implementing it using a dll file. Regards,

      Mujtaba Panjwani Tiger Softwares Software Designer and Developer VB.NET, C#, ASP.NET, VFP

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      What kind of handle - an HWND? If so, there is no built in association between an HWND and an object. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      M 1 Reply Last reply
      0
      • M MAP Tiger

        Hi Is there any possibility that I could cast an object through its handle. For example, I have to do an estimation of objects and finally I get the handle of that object through GetWindow API call, now I know its type but how to retrieve that object and cast it for that specific type? I am implementing it using a dll file. Regards,

        Mujtaba Panjwani Tiger Softwares Software Designer and Developer VB.NET, C#, ASP.NET, VFP

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        AFAIK, you cannot do that. The best you can do is send messages to that handle. The object doesn't exist in the managed environment, so there's no way to cast it to be a managed object.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        M 1 Reply Last reply
        0
        • M Mark Salsbery

          What kind of handle - an HWND? If so, there is no built in association between an HWND and an object. Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          M Offline
          M Offline
          MAP Tiger
          wrote on last edited by
          #4

          Hi Thanks for the reply. Yes, it is an HWND. To make it more clearer, the handle is of a IE's statusbar32 object, for which I know only the handle, now I want to manipulate its objects and add/remove other Microsoft Common Controls so I was thinking of a way to cast that object to comctl's statusbarclass and then manipulate it instead of throwing Messages and creating pane window etc. using API calls as I am not very good in that. Hope I was clearer to specify my scenario and you would have the solution to it. Regards,

          Mujtaba Panjwani Tiger Softwares Software Designer and Developer VB.NET, C#, ASP.NET, VFP

          M 1 Reply Last reply
          0
          • D Dave Kreskowiak

            AFAIK, you cannot do that. The best you can do is send messages to that handle. The object doesn't exist in the managed environment, so there's no way to cast it to be a managed object.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            M Offline
            M Offline
            MAP Tiger
            wrote on last edited by
            #5

            Hi Thanks for the reply. Actually I already considered that but that seems very complicated as I am willing to create another control and append it to the control whose handle is known to me. i.e. add label control into statusbar control of IE. I hope you have a solution to this. Regards,

            Mujtaba Panjwani Tiger Softwares Software Designer and Developer VB.NET, C#, ASP.NET, VFP

            D 1 Reply Last reply
            0
            • M MAP Tiger

              Hi Thanks for the reply. Yes, it is an HWND. To make it more clearer, the handle is of a IE's statusbar32 object, for which I know only the handle, now I want to manipulate its objects and add/remove other Microsoft Common Controls so I was thinking of a way to cast that object to comctl's statusbarclass and then manipulate it instead of throwing Messages and creating pane window etc. using API calls as I am not very good in that. Hope I was clearer to specify my scenario and you would have the solution to it. Regards,

              Mujtaba Panjwani Tiger Softwares Software Designer and Developer VB.NET, C#, ASP.NET, VFP

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              MAP Tiger wrote:

              I know only the handle, now I want to manipulate its objects

              You'll have to use APIs unless there's some other programming model built into IE, which I wouldn't know :) Mark .

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              M 1 Reply Last reply
              0
              • M MAP Tiger

                Hi Thanks for the reply. Actually I already considered that but that seems very complicated as I am willing to create another control and append it to the control whose handle is known to me. i.e. add label control into statusbar control of IE. I hope you have a solution to this. Regards,

                Mujtaba Panjwani Tiger Softwares Software Designer and Developer VB.NET, C#, ASP.NET, VFP

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                There is no way to cast that handle to an object, .NET managed, COM, or otherwise. AFAIK, IE doesn't expose any method to do what you want.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008

                1 Reply Last reply
                0
                • M Mark Salsbery

                  MAP Tiger wrote:

                  I know only the handle, now I want to manipulate its objects

                  You'll have to use APIs unless there's some other programming model built into IE, which I wouldn't know :) Mark .

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  M Offline
                  M Offline
                  MAP Tiger
                  wrote on last edited by
                  #8

                  Hi OK fine, so the final solution seems to be working with SendMessages and P/Invoke calls. Would you be able to help me in converting the following C++ project to C# http://www.codeproject.com/KB/atl/IEStatusBarPane.aspx?msg=2840047#xx2840047xx[^] Regards,

                  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