How to cast an object using its handle?
-
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
-
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
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:
-
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
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 -
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:
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
-
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, 2008Hi 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
-
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
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:
-
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
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 -
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:
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,