VB call the MSN 6.2 API function __ function

Source: Internet
Author: User
Tags goto
The reason to understand this is that a friend of mine in the morning Let me read a section on MSN Development Program, now unable to run, I opened the project found to be written for 4.7, while his computer installed 6, 2, because I also used 6.2 so I looked in VB, found that the messenger Type is missing Library. But with the Messenger API type library, it might be an alternative to the Messenger type library, but it's not as comprehensive as the previous Messenger type library, At least I now find that it can not modify the local myfriendlyname, do not understand why make it read-only, Mystatus is writable.

Here is a simple VB distance to explain how to call it:

The first of course is referencing the object Messenger API Type library.

Then declare an object Messengerapi.messenger:

Private WithEvents Omsn as Messengerapi.messenger

The things we need are all here, a brief introduction to several:

Mycontacts:imessengercontacts objects
Myfriendlyname: The current nickname
MYGROUPS:IMESSENGERGROUPSS objects
Myphonenumber: Return phone number
MyProperty: No use now
Myserviceid: Return service ID should be {9b017612-c9f1-11d2-8d9f-0000f875c541}]
myServiceName: Return service name should be. NET Messenger Service
Mysigninname: Return the current signature, email address
Mystatus: Returns the current state, Mistatus the enumeration value

In fact, the local properties are the same as those obtained through Primaryservice

Do a few simple demos:

The first is a login demo, using the Messengerapi.messenger signin or Autosignin method:

Public Sub signin (ByVal bauto as Boolean, Optional ByVal ssigninname As String, Optional ByVal Spassword As String)
On Error GoTo Errorhandle
If Bauto = True Then
Omsn.autosignin
Else
Manualsignin:
Omsn.signin 0, Ssigninname, Spassword
End If

Exit Sub
Errorhandle:
Dim Mconstants as Msgrconstants
Mconstants = Err. Number
If mconstants = Msgr_e_fail Then
GoTo Manualsignin
ElseIf mconstants = msgr_e_already_logged_on Then
' Has landed
End If
End Sub

Get All Users list:

MyContacts object through Messenger (it is read-only)

It is actually a Imessengercontacts object, and the Imessengercontacts class is a collection of imessengercontact classes that hold contact information in Imessengercontact.

So you can traverse the contacts like this.

Dim Ocontacts as Imessengercontacts
Dim Ocontact as Imessengercontact
Dim Icount as Integer
Dim I as Long
Set ocontacts = omsn.mycontacts
icount = Ocontacts.count
For i = 0 to ICount-1
Set ocontact = Msgrcontacts.item
List1.AddItem Msgrcontact.friendlyname & VbTab & ("& Getstatusdesc (Msgrcontact.status) &")
Next

The GETSTATUSDESC function is used to return the status text description:

Private Function Getstatusdesc (estatus as Mistatus) as String
Select Case Estatus
Case Mistatus_away
Getstatusdesc = "Go away."
Case Mistatus_be_right_back
Getstatusdesc = "Come back soon"
Case Mistatus_busy
Getstatusdesc = "in Busy"
Case Mistatus_idle
Getstatusdesc = "In a daze"
Case Mistatus_invisible
Getstatusdesc = "Stealth"
Case Mistatus_local_connecting_to_server
GETSTATUSDESC = "Linking Server"
Case Mistatus_local_disconnecting_from_server
Getstatusdesc = "Disconnect from server"
Case Mistatus_local_finding_server
Getstatusdesc = "Searching for servers"
Case Mistatus_local_synchronizing_with_server
Getstatusdesc = "Synchronizing with server"
Case Mistatus_offline
Getstatusdesc = "Offline"
Case Mistatus_on_the_phone
Getstatusdesc = "On Answer call"
Case Mistatus_online
Getstatusdesc = "Online"
Case Mistatus_out_to_lunch
Getstatusdesc = "Dining Out"
Case Mistatus_unknown
Getstatusdesc = "Unknown"
End Select
End Function

Get group list:

method to get the contact person, just change the object.

Dim Ogroups as Imessengergroups
Dim Ogroup as Imessengergroup
Set ogroups = omsn.mygroups
For each ogroup in ogroups
List1.AddItem Ogroup.name
Next

The following is the association of groups and users:

Understand the above method, this is easy to implement, the Imessengergroup class object contains a collection of Imessengercontact class objects.

Dim Ogroups as Imessengergroups
Dim Ogroup as Imessengergroup
Dim Ocontacts as Imessengercontacts
Dim Ocontact as Imessengercontact
Set ogroups = omsn.mygroups
For each ogroup in ogroups
Set ocontacts = ogroup.contacts
For each ocontact in ocontacts
List1.AddItem Ogroup.name & "" & Ocontact.signinname
Next
Next

In the introduction of services:

is also the use of the kind of truth:

Dim Oservices as Imessengerservices
Dim Oservice as Imessengerservice
Set oservices = omsn.services
Set Oservice = Oservices.primaryservice
MsgBox Oservice.myfriendlyname & Getstatusdesc (oservice.mystatus) & Oservice.mysigninname & Oservice.serviceid & Oservice.servicename

How do I feel now primaryservice is not very meaningful, imessengerservices in a primaryservice available, or read-only.

Of course, each object may have some corresponding methods are not introduced, I introduced these through the Object Browser can be seen, and there are objects or members I have not learned to use, now is just a general understanding, I hope to see this article people also have a little preliminary understanding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.