?
Solved

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

Posted on 2004-08-24
7
Medium Priority
?
356 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

777 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