Solved

Interop.Messenger: Retrieving handle for already running MSN Messenger Application for use in VB.NET

Posted on 2004-08-24
7
342 Views
Last Modified: 2008-01-09
I have run numerous searches on Google and EE but still can't figure this out. First let me clarify that this is not part of a project, but rather something I am doing just out of plain curiosity. Now, here is the problem: I want to retrieve the currently running MSN Messenger process (assuming it is already running of course :) and somehow cast it into a Messenger.MessengerApp object. So far I have been able to get a Process object using Process.GetProcessesByName("msnmsgr") but cannot figure out how to cast/convert to MessengerApp.  Can anyone shed some light? Thanks
0
Comment
Question by:nikolaros
  • 3
  • 2
7 Comments
 
LVL 5

Expert Comment

by:thenrich
ID: 11894017
Why not use the GetObject function?

GetObject(,"Not sure what classname goes here)

should work.
Else your trying to make mountain out of a mole-hill.
0
 

Author Comment

by:nikolaros
ID: 11898735
Hello! Thanks for your reply.

Definitely I'm trying to make mountain out of a mole-hill. I could simply kill the currently running MSN Messenger process and start Messenger from within my code. This is what you suggested more or less. This would involve creating a new MessengerApp object in my VB.NET code and would look something like this:

myApp = CType(CreateObject("Messenger.MessengerApp"), Messenger.MessengerApp)

I have already used similar code to automate Word documents and it works fine. #But# in my case I do not want to create a new MessengerApp object, but rather associate it with the already running MSN Messenger process. You might want to do this if for instance you don't want to have to shut down Messenger when your program starts, in order to restart Messenger. You can think of it as a dynamic (sort of) runtime link.

After further thought I think it is impossible to do what I want (at least not the way I imagined it). A couple of points to support this:

1. As far as I know, if you are importing unmanaged COM libraries, Visual Studio creates a wrapper in order to be able to use them from within your managed code. However, when you start Messenger as a standalone process, this wrapper is not there.

2. Since Messenger and my VB.NET program will be running as different processes, they will be located in different address spaces. Hence it cannot be possible to cast code in the "Messenger" space into an object within my program.


Conclusions:

I don't have enough experience with Windows programming!

I was probably asking how to do something apparrently impossible (as most experienced programmers out there should be able to tell straight away).

I'm sure I am missing a few points from the overall picture, so please if you have any comments (or a different opinion) do post. There are 100 points yet to be awarded ;)
0
 
LVL 5

Accepted Solution

by:
thenrich earned 100 total points
ID: 11901763
You are missing the point. The GetObject function will get the currently running instance of any application that is regestered and has a COM or .NET interface. Messanger does cause I've done what you've described. If you wanted to start your own you'd use the:

CreateObject("Messenger.MessengerApp")

I told you to use:

GetObject(,"Messenger.MessengerApp")

0
 

Author Comment

by:nikolaros
ID: 11903685
Checked the GetObject documentation. Should do the trick if only I could find out the correct Class String. Using Messenger.MessengerApp as the Class String gives "cannot create activex object" exception. So do all the classes I have tried so far. Is there a way to determine the COM class of an application from its Handle?
0
 

Author Comment

by:nikolaros
ID: 11903718
Just to make sure we are trying out the same things, can you post the code for your entire function?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now