IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> [C#] Examples
timothy
post Sep 3 2004, 03:52 PM
Post #1



Group Icon

Group: Timothy
Posts: 771
Joined: 1-September 04
From: Netherlands
Member No.: 3



I allready posted this before on MSN|Fanatic, but here we go again:

It seems there are no examples or references about the MSN Messenger 6 api for C#, (examples about MSN Messenger for C# are outdated and only useable for WM at the moment) Set the reference through Project -> Add Reference -> COM -> Messenger API Type Library 1.0 in .net 2xxx. Or in SharpDevelop right click Add reference on the Reference icon in your project browser, choose COM -> Messenger API Type Library You can also use this old guide to set the reference if you are using a very old .net version ( the DLL is called Interop.MessengerAPI.dll in MSN Messenger 6).

The examples were made in C# 2005 Beta, but should work fine on older versions:

Example 1:
A hello world example, displays your name in a box, nothing more nothing less. <click>
Example 2:
Using instances of MSN Messenger objects (used to get user details etc). <click>
Example 3:
A simple event-log example, shows you how to use MSN Messenger events in C# ( you need to create a listbox called list1 ). <click>

But you could also use SharpDevlop, its merely the same:
A hello world example, displays your name in a box, nothing more nothing less. <click>


This is all you need to know to work with the MSN Messenger 6 API in C#, have fun msn_happy.gif
Go to the top of the page
 
+Quote Post
Guest_Dan_*
post Sep 3 2004, 03:59 PM
Post #2





Guests






Thanks Timothy. Very useful information.
Go to the top of the page
 
+Quote Post
ngb
post Dec 1 2004, 01:35 PM
Post #3


Mess.bean
*

Group: Members
Posts: 3
Joined: 1-December 04
Member No.: 3,263



These examples crash on
MessengerAPI.Messenger MSN = new MessengerAPI.Messenger();
with an OutOfMemoryException

is there something else that needs to be done?
its just a declaration
Go to the top of the page
 
+Quote Post
ngb
post Dec 2 2004, 07:01 AM
Post #4


Mess.bean
*

Group: Members
Posts: 3
Joined: 1-December 04
Member No.: 3,263



QUOTE(ngb @ Dec 1 2004, 11:35 PM)
These examples crash on
MessengerAPI.Messenger MSN = new MessengerAPI.Messenger();
with an OutOfMemoryException
[right][snapback]20065[/snapback][/right]


I found out why.
I had 'do not allow windows messenger to be run' set to Enabled in gpedit.msc
apparently the api needs to get the reference from windows messenger not msn messenger.
Go to the top of the page
 
+Quote Post
redeye
post Apr 4 2005, 03:39 PM
Post #5


Mess.bean
*

Group: Members
Posts: 2
Joined: 4-April 05
Member No.: 7,075



error on example 3 (1 and 2 worked fine)>>
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in interop.messengerapi.dll

Additional information: Exception from HRESULT: 0x80040202.

the error starts on the first line and the application need to break>>

MSN.OnContactBlockChange +=new MessengerAPI.DMessengerEvents_OnContactBlockChangeEventHandler(MSN_OnContactBlockChange);
MSN.OnContactListAdd +=new MessengerAPI.DMessengerEvents_OnContactListAddEventHandler(MSN_OnContactListAdd);
MSN.OnContactRemovedFromGroup +=new MessengerAPI.DMessengerEvents_OnContactRemovedFromGroupEventHandler(MSN_OnContactRemovedFromGroup);
MSN.OnGroupAdded +=new MessengerAPI.DMessengerEvents_OnGroupAddedEventHandler(MSN_OnGroupAdded);
MSN.OnContactAddedToGroup+=new MessengerAPI.DMessengerEvents_OnContactAddedToGroupEventHandler(MSN_OnContactAddedToGroup);
MSN.OnUnreadEmailChange+=new MessengerAPI.DMessengerEvents_OnUnreadEmailChangeEventHandler(MSN_OnUnreadEmailChange);
MSN.OnSignin+=new MessengerAPI.DMessengerEvents_OnSigninEventHandler(MSN_OnSignin);
MSN.OnSignout+=new MessengerAPI.DMessengerEvents_OnSignoutEventHandler(MSN_OnSignout);
MSN.OnMyStatusChange+=new MessengerAPI.DMessengerEvents_OnMyStatusChangeEventHandler(MSN_OnMyStatusChange);


if anyone can help i'll be thank full
Go to the top of the page
 
+Quote Post
timothy
post Apr 4 2005, 08:14 PM
Post #6



Group Icon

Group: Timothy
Posts: 771
Joined: 1-September 04
From: Netherlands
Member No.: 3



did you forgot / removed the functions ?
Go to the top of the page
 
+Quote Post
kahou
post Oct 19 2005, 11:07 PM
Post #7


Mess.bean
*

Group: Members
Posts: 3
Joined: 19-October 05
Member No.: 13,607



Do you guys know how to send text with MessengerAPI in C#?
Go to the top of the page
 
+Quote Post
TheSteve
post Oct 20 2005, 01:34 AM
Post #8


The Man from Japan
******

Group: Members
Posts: 693
Joined: 9-June 05
From: Fukuoka Japan
Member No.: 9,636



You can't with the API however you can using Active Accessibility or Win32 API
Go to the top of the page
 
+Quote Post
LazyDog
post Dec 6 2005, 09:33 AM
Post #9


Mess.bean
*

Group: Members
Posts: 3
Joined: 6-December 05
Member No.: 15,006



All Links is Error
Go to the top of the page
 
+Quote Post
Hades
post Dec 6 2005, 12:24 PM
Post #10


Mess.beagle
***

Group: Members
Posts: 177
Joined: 28-September 04
From: The Netherlands
Member No.: 529



They are all working correct at my computer.
Go to the top of the page
 
+Quote Post
Saladin
post Aug 16 2006, 09:26 PM
Post #11


Mess.bean
*

Group: Members
Posts: 2
Joined: 25-July 06
Member No.: 20,247



Hi, I am using .NET 1. 1 so when I got those 'COMException' I tried to follow the 'old' guide. But when I opened the decompiled .IL file there were literally hundreds of instances of 'SinkHelper'. And the replies in the thread seemed to indicate that the code snippet is absolete for MSN version > 4.6.

Can some one give some tips as to how to change it so it works on MSN 7 and windows messenger Live?

(downloading .NET >300Mb, is that gonna fix all my problems?)
Go to the top of the page
 
+Quote Post
martijn schimmel
post Jan 14 2007, 10:19 AM
Post #12


Mess.bean
*

Group: Members
Posts: 1
Joined: 14-January 07
Member No.: 23,919



Don't know if this helps, it's pretty dirty code but functional. If somebody wants the full sourcecode, send me an email.

CODE

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace msnDesktop
{
   public partial class Form1 : Form
   {
       // create the MSN Messenger API
       MessengerAPI.Messenger MSN = new MessengerAPI.Messenger();

       public Form1()
       {
           InitializeComponent();

           MSN.OnMyStatusChange += new MessengerAPI.DMessengerEvents_OnMyStatusChangeEventHandler(MSN_OnMyStatusChange);
           MSN.OnContactStatusChange += new MessengerAPI.DMessengerEvents_OnContactStatusChangeEventHandler(MSN_OnContactStatusChange);
       }

       private void Form1_Load(object sender, EventArgs e)
       {
           try
           {
               if (MSN.MyStatus != MessengerAPI.MISTATUS.MISTATUS_OFFLINE)
               {
                   label1.Text = MSN.MyFriendlyName.ToString();
                   
                   string dpLocation = this.MSN.get_MyProperty((MessengerAPI.MCONTACTPROPERTY)2).ToString();
                   Bitmap myDisplayPicture = new Bitmap(dpLocation);
                   pictureBox1.Image = myDisplayPicture;

                   

                  MessengerAPI.IMessengerContacts Contactpersonen = (MessengerAPI.IMessengerContacts) MSN.MyContacts;

                   for (int i = 0; i < Contactpersonen.Count; i++)
                   {
                       MessengerAPI.IMessengerContact Contact = (MessengerAPI.IMessengerContact)Contactpersonen.Item(i);

                       int x = 0;

                       switch (Contact.Status.ToString())
                       {
                           case "MISTATUS_ONLINE": x = 1; break;
                           case "MISTATUS_AWAY": x = 2; break;
                           case "MISTATUS_BUSY": x = 3; break;
                           case "MISTATUS_BE_RIGHT_BACK": x = 2; break;
                           case "MISTATUS_OUT_TO_LUNCH": x = 2; break;
                           case "MISTATUS_ON_THE_PHONE": x = 2; break;
                           case "MISTATUS_IDLE": x = 4; break;
                           default: x = 0; break;
                       }

                       TreeNode node = new TreeNode();
                       node.Name = Contact.SigninName;

                       if (Contact.FriendlyName.Length > 35)
                       {
                           node.Text = Contact.FriendlyName.Substring(0, 35) + "...";
                       }
                       else
                       {
                           node.Text = Contact.FriendlyName;
                       }

                       node.ImageIndex = x;
                       node.SelectedImageIndex = x;

                       if (x != 0)
                       {
                           treeView1.Nodes["NodeOnline"].Nodes.Add(node);
                       }
                       else
                       {
                           treeView1.Nodes["NodeOffline"].Nodes.Add(node);
                       }

                       treeView1.ExpandAll();

                       SetRootText();
                   }
               }
               else
               {
                   this.Text = "Niet aangemeld";
               }

               
           }
           catch (Exception error)
           {
               MessageBox.Show(error.Message, "Foutmelding", MessageBoxButtons.OK, MessageBoxIcon.Error);
           }
       }
       private void SetRootText()
       {
           int intOnline = treeView1.Nodes[0].Nodes.Count;
           treeView1.Nodes[0].Text = "Online {" + intOnline.ToString() + "}";

           int intOffline = treeView1.Nodes[1].Nodes.Count;
           treeView1.Nodes[1].Text = "Offline {" + intOffline.ToString() + "}";
       }
       private string TranslateStatus(MessengerAPI.MISTATUS _Status)
       {
           string Status = null;

           switch (_Status.ToString())
           {
               case "MISTATUS_AWAY": Status = "Afwezig"; break;
               case "MISTATUS_ONLINE": Status = "Online"; break;
               case "MISTATUS_OFFLINE": Status = "Offline"; break;
               case "MISTATUS_BUSY": Status = "Bezet"; break;
               case "MISTATUS_BE_RIGHT_BACK": Status = "Zo terug"; break;
               case "MISTATUS_ON_THE_PHONE": Status = "Aan de telefoon"; break;
               case "MISTATUS_OUT_TO_LUNCH": Status = "Lunchpauze"; break;
               case "MISTATUS_IDLE": Status = "Niet actief"; break;
               default: Status = _Status.ToString(); break;
           }

           return Status;
       }

       void MSN_OnMyStatusChange(int hr, MessengerAPI.MISTATUS mMyStatus)
       {
           textBox1.Text = DateTime.Now.ToShortTimeString() + " - Je status is veranderd. [" + TranslateStatus(mMyStatus) + "]";
       }

       void MSN_OnContactStatusChange(object pMContact, MessengerAPI.MISTATUS mStatus)
       {
           MessengerAPI.IMessengerContact Contact = (MessengerAPI.IMessengerContact) pMContact;

           if (mStatus == MessengerAPI.MISTATUS.MISTATUS_OFFLINE)
           {
               TreeNode node = new TreeNode();
               node.Text = Contact.FriendlyName;
               node.Name = Contact.SigninName;
               node.ImageIndex = GetImageIndex(Contact.Status);
               node.SelectedImageIndex = GetImageIndex(Contact.Status);

               treeView1.Nodes[0].Nodes.Add(node);
               treeView1.Nodes[1].Nodes.RemoveAt(treeView1.Nodes[1].Nodes[Contact.SigninName].Index);
           }
           else
           {
               if (Contact.Status == MessengerAPI.MISTATUS.MISTATUS_OFFLINE)
               {
                   TreeNode node = new TreeNode();
                   node.Text = Contact.FriendlyName;
                   node.Name = Contact.SigninName;
                   node.ImageIndex = GetImageIndex(Contact.Status);
                   node.SelectedImageIndex = GetImageIndex(Contact.Status);

                   treeView1.Nodes[1].Nodes.Add(node);

                   treeView1.Nodes[0].Nodes.RemoveAt(treeView1.Nodes[0].Nodes[Contact.SigninName].Index);
               }
               else
               {
                   TreeNodeCollection nodes = treeView1.Nodes;

                   foreach (TreeNode node in nodes)
                   {
                       if (node.Name == Contact.SigninName)
                       {
                           node.ImageIndex = GetImageIndex(Contact.Status);
                           node.SelectedImageIndex = GetImageIndex(Contact.Status);
                       }
                   }
               }
           }

         SetRootText();

           string Name = null;

           if (Contact.FriendlyName.Length > 35)
           {
               Name = Contact.FriendlyName.Substring(0, 35) + "...";
           }
           else
           {
               Name = Contact.FriendlyName;
           }

           textBox1.Text = DateTime.Now.ToShortTimeString() + " - " + Name + " heeft zijn of haar status veranderd. [" + TranslateStatus(Contact.Status) + "]";
       }

       private void pictureBox2_Click(object sender, EventArgs e)
       {
           if (this.TopMost)
           {
               this.TopMost = false;
               this.ShowInTaskbar = true;
           }
           else
           {
               this.TopMost = true;
               this.ShowInTaskbar = false;
           }

           treeView1.ExpandAll();
       }

       private int GetImageIndex(MessengerAPI.MISTATUS mMyStatus)
       {
           int i =0;

           switch (mMyStatus.ToString())
           {
               case "MISTATUS_AWAY": i = 2; break;
               case "MISTATUS_ONLINE": i = 1; break;
               case "MISTATUS_OFFLINE": i = 0; break;
               case "MISTATUS_BUSY": i = 3; break;
               case "MISTATUS_BE_RIGHT_BACK": i = 2; break;
               case "MISTATUS_ON_THE_PHONE": i = 2; break;
               case "MISTATUS_OUT_TO_LUNCH": i = 2; break;
               case "MISTATUS_IDLE": i = 4; break;
               default: i = 0; break;
           }

           return i;
       }

       private void pictureBox4_Click(object sender, EventArgs e)
       {
           Application.Exit();
       }

       private void pictureBox3_Click(object sender, EventArgs e)
       {
           this.ShowInTaskbar = true;
           this.WindowState = FormWindowState.Minimized;
           this.TopMost = false;

           treeView1.ExpandAll();
       }

       private void btnOnline_Click(object sender, EventArgs e)
       {
           MSN.MyStatus = MessengerAPI.MISTATUS.MISTATUS_ONLINE;
       }

       // geeft een fatale error
       private void btnOffline_Click(object sender, EventArgs e)
       {
           MSN.MyStatus = MessengerAPI.MISTATUS.MISTATUS_OFFLINE;
       }

       private void btnAfwezig_Click(object sender, EventArgs e)
       {
           MSN.MyStatus = MessengerAPI.MISTATUS.MISTATUS_AWAY;
       }

       private void btnBezet_Click(object sender, EventArgs e)
       {
           MSN.MyStatus = MessengerAPI.MISTATUS.MISTATUS_BUSY;
       }

       private void btnZoTerug_Click(object sender, EventArgs e)
       {
           MSN.MyStatus = MessengerAPI.MISTATUS.MISTATUS_BE_RIGHT_BACK;
       }

       private void btnLunchpauze_Click(object sender, EventArgs e)
       {
           MSN.MyStatus = MessengerAPI.MISTATUS.MISTATUS_OUT_TO_LUNCH;
       }

       private void btnAanDeTelefoon_Click(object sender, EventArgs e)
       {
           MSN.MyStatus = MessengerAPI.MISTATUS.MISTATUS_ON_THE_PHONE;
       }

       private void listView1_DoubleClick(object sender, EventArgs e)
       {
           MessengerAPI.IMessengerContact ImContact = (MessengerAPI.IMessengerContact)MSN.GetContact("bien_blue45[at]hotmail[dot]com", MSN.MyServiceId);
           MSN.InstantMessage(ImContact);
       }

       private void treeView1_DoubleClick(object sender, EventArgs e)
       {
           try
           {
               TreeNode node = (TreeNode)treeView1.SelectedNode;
               
               string Email = node.Name;

               if (Email != "NodeOnline" || Email != "Offline")
               {
                   MessengerAPI.IMessengerContact ImContact = (MessengerAPI.IMessengerContact)MSN.GetContact(node.Name, MSN.MyServiceId);
                   MSN.InstantMessage(ImContact);
               }
           }
           catch (Exception error)
           {
               MessageBox.Show(error.Message, "Foutmelding", MessageBoxButtons.OK, MessageBoxIcon.Error);
           }
       }

       private void pictureBox5_Click(object sender, EventArgs e)
       {
           MSN.OpenInbox();
       }
   }
}
Go to the top of the page
 
+Quote Post
LoftyLad
post Jan 29 2008, 09:02 PM
Post #13


Mess.bean
*

Group: Members
Posts: 1
Joined: 26-January 08
Member No.: 33,279



Sending a message with C#

Gets target email from listContacts.Text
and message from txtMessage.Text


CODE
private void btnSendMsg_Click(object sender, EventArgs e)
        {
            MessengerAPI.Messenger MSN = new MessengerAPI.Messenger();

            object MsnWindow = MSN.InstantMessage(listContacts.Text);
            SendKeys.Send(txtMessage.Text + "{Enter}");
        }
Go to the top of the page
 
+Quote Post
Ricky@Sydney
post Sep 7 2008, 12:58 AM
Post #14


Mess.bean
*

Group: Members
Posts: 5
Joined: 7-September 08
Member No.: 37,303



QUOTE(TheSteve @ Oct 20 2005, 11:34 AM) [snapback]97052[/snapback]
You can't with the API however you can using Active Accessibility or Win32 API

Wow! You tackle this in 2005?

Which Win32 API? Are you thinking of SendMessage()?
Regarding Active Accessibility, do you have a code fragement?

Many thanks
Ricky
Go to the top of the page
 
+Quote Post
TheSteve
post Sep 8 2008, 02:21 AM
Post #15


The Man from Japan
******

Group: Members
Posts: 693
Joined: 9-June 05
From: Fukuoka Japan
Member No.: 9,636



QUOTE(kahou @ Oct 20 2005, 08:07 AM) [snapback]97038[/snapback]
Do you guys know how to send text with MessengerAPI in C#?


QUOTE(TheSteve @ Oct 20 2005, 10:34 AM) [snapback]97052[/snapback]
You can't with the API however you can using Active Accessibility or Win32 API



QUOTE(Ricky@Sydney @ Sep 7 2008, 09:58 AM) [snapback]175367[/snapback]
Which Win32 API? Are you thinking of SendMessage()?

I was referring to the Messenger API.

QUOTE(Ricky@Sydney @ Sep 7 2008, 09:58 AM) [snapback]175367[/snapback]
Regarding Active Accessibility, do you have a code fragement?

I do have some C++ code that you could convert to C#.
My code is here.
Some example code of how to use MSAA is available here. (look at the last post)
Go to the top of the page
 
+Quote Post
Ricky@Sydney
post Sep 9 2008, 09:51 AM
Post #16


Mess.bean
*

Group: Members
Posts: 5
Joined: 7-September 08
Member No.: 37,303



Domo Arigato, Steve-San
Go to the top of the page
 
+Quote Post
TheSteve
post Sep 10 2008, 12:39 AM
Post #17


The Man from Japan
******

Group: Members
Posts: 693
Joined: 9-June 05
From: Fukuoka Japan
Member No.: 9,636



Douitashimashite (you're welcome)
Go to the top of the page
 
+Quote Post
skolapper
post Sep 4 2009, 03:32 AM
Post #18


Mess.bean
*

Group: Members
Posts: 1
Joined: 2-September 09
From: Senegal
Member No.: 42,776



Has anybody seen examples of websites that use a 3D box as a menu? I hate the idea but Im being forced to create one. If I could find a website that is already doing it I might be able to talk the client out of it.

Thanks,
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

 



RSS Lo-Fi Version Time is now: 16th December 2018 - 10:38 PM
2004-2008 Seb Skuse, mess.be.
MessForum v6.1.4 - created for, and for use only by mess.be.