Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

947 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

22 Experts available now in Live!

Get 1:1 Help Now