Use MSN to use in VS.NET? Is it very wonderful? But this is true, the following steps will gradually teach you how to embed the MSN into the VS.NET.
Referrence
Since there is a bug in VS.NET, you cannot directly reference the Messenger ActiveX components. You need to manually modify the two methods in the code generated by TLBIMP, then recompile, the specific method is as follows:
1 Generate a Messenger InteroP component using TLBIMP.EXE
Tlbimp msmgs.exe /out:Messenger.dll (Default Path: C: / Program Files / Messenger)
2 Confluence this InteroP component, then save it as an IL file:
ILDASM / TEXT Messenger.dll /out:Messenger.il
3 Use any text editor to open this IL file, then change the following code (change the PRIVATE attribute of the class to public):
Change .Class Private Auto Ansi Sealed DMSGROBJECTEVENTS_SINKHELPER for .Class Public Auto Ansi Sealed DMSGROBJECTEVENTS_SINKHELPER
Change. Class Private Auto Ansi Sealed DMSGROBJECTEVENTS_EVENTPROVIDER
For .CLASS PUBLIC AUTO ANSI Sealed DMSGROBJECTEVENTS_EVENTPROVIDER
4 compile this IL file
ILASM / DLL MESSENGER.IL
5 Now we can reference the compiled DLL file in the project.
Create an external program (CREATING AN Add-in)
Select New Projects / Other Project / Scalability Project / Visual Studio .NET Adds, the Wizard dialog box appears.
1 Select "Creating an Add Up Using Visual C #"
2 Select the development environment that uses this procedure, I have chosen.
3 give your external program a nice name.
4 Choose your hobby.
5 Do you generate the "About" information in the Help menu.
6 Select "Finish"
Create a tool window
We need to make this add-in into a tool window. How to do it? We can use Microsoft to provide an example of making tool windows in .NET.
1 Reference ActiveX control generated by vsuserControlhost.
2 Add the following code to the onConnection method in the connection.cs file in this procedure.
Object objtemp = null;
2. String Guidstr = "{716238D9-8ED3-48AA-A7A0-A73CA6FDF1EF}";
3.
4. Envdte.window WindowToolWindow =
5. ApplicationObject.windows.createtoolwindow
6. AddinInstance,
7. "vSuserControlhost.vsuserControlhostctl",
8. "Messenger", GuidStr, Ref objtemp);
9.
10. WindowToolWindow.visible = true;
11.
12. vSuserControlhostlib.ivsuserControlhostctl ObjControl =
13. (vSuserControlhostlib.ivsuserControlhostl) Objtemp;
14.
15. ObjControl.hostuserControl
16. System.Reflection.Assembly.GetexecutingAssembly (). Location, "msgaddin.hostuserControl");
MSN programming
Now we have entered the programming of MSN itself. Select "Add User Control" in Projects. The processing of user controls and the way of processing of the Windows form are the same. Then add a "Send" button, "Edit" box and a listview on this "User Control". We need two members in the user control class:
initialization
Messenger.msgrobjectclass msg;
Messenger.imsgruser;
Messenger.imsgrusers;
Add the following code in the constructor
Msg = new Messenger.msgrobjectClass ();
Try
{
/ / Check if the MSN is already logged in
IF (msg.localState == Messenger.mstate.mstate_offline)
{
Messenger.MessengerappClass APP =
NEW MESSENGER.MESSENGERAPPCLASS ();
app.imessengerapp_launchlogonui ();
// Waiting for login to complete
While (msg.localState! = Messenger.mstate.mstate_Online)
System.Threading.Thread.Sleep (5000);
}
// Get a list of users
Users = msg.get_list (Messenger.mlist.mlist_contact);
For (int i = 0; i { Messenger.imsgruser u = users.Item (i); UserList.Item (New ListViewItem (u.friendlyname))))); } // Get new information notifications Msg.OnTextReceived = NEW MESSENGER.DMSGROBJECTEVENTS_ONTEXTRECEVEVENTHANDLER (this.onTextRecieved); / / Get user status change notification Msg.onuserstateChanged = new Messenger.dmsgrobjectEvents_onuserstateChangeDeventHandler (this.onuserstatechanged); } // abnormal processing Catch (Exception E) { Messagebox.show (E.MESSAGE); }