Link to home
Start Free TrialLog in
Avatar of nikolaros
nikolaros

asked on

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

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
Avatar of thenrich
thenrich

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.
Avatar of nikolaros

ASKER

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 ;)
ASKER CERTIFIED SOLUTION
Avatar of thenrich
thenrich

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
Just to make sure we are trying out the same things, can you post the code for your entire function?