Solved

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

Posted on 2004-08-24
7
354 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

717 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