Introduction to Messenger API Type Library

Windows Live Messenger

Conversation Logger

Note for version 6 and higher: The conversation windows are now windowless richedit controls, so the following code will not work. You can instead use the Contacts and History members of the IMessengerConversationWnd interface, which is also much easier.

This uses the “OnIMWindowDestroyed” event. Each time a conversation window is closed it appends (or creates new if not existant) the contents of the chatbox to “user@mymail.com.log”, user@hotmail.com being the first person in the conversation.

Private Sub objMessenger_OnIMWindowDestroyed(ByVal pIMWindow As Object)

    Dim MsgrIMWindow As IMessengerConversationWnd
    Dim MsgrContacts As IMessengerContacts
    Dim lngEdit&, lngTextLen&, m&, f As Long
    Dim strText$, strEditText$, strEmail$, strTmpText As String

    Set MsgrIMWindow = pIMWindow
    Set MsgrContacts = MsgrIMWindow.Contacts
    lngEdit = FindWindowEx(MsgrIMWindow.hWnd, 0, "edit", vbNullString)
    lngTextLen = SendMessageLong(lngEdit, WM_GETTEXTLENGTH, 0, 0)
    strText = String(lngTextLen + 1, Chr(0))

    Call SendMessageByString(lngEdit, WM_GETTEXT, lngTextLen + 1, strText)
    strEditText = Left(strText, lngTextLen)

    If MsgrContacts.Count = 0 Then
        strTmpText = Mid(strEditText, 1, InStr(strEditText, ">, "))
    Else
        strTmpText = strEditText
    End If

    If InStr(strTmpText, ">") = 0 Then
        strEmail = strTmpText
    Else
        m = InStrRev(strTmpText, "<")
        f = InStrRev(strTmpText, ">")
        strEmail = Mid(strTmpText, m + 1, f - m - 1)

    End If

    Open "C:\MsgrLogs" & strEmail & ".log" For Append As #1
        Print #1, "-----------------------------"
        Print #1, "Contacts in coversation: " & strEditText
        Print #1, Date & " @ " & Time
        Print #1, "-----------------------------"
        Print #1, MsgrIMWindow.History
        Print #1, "-----------------------------" & vbCrLf
    Close #1

End Sub

Make sure the folder “C:\MsgrLogs” exists, or you will get an error.

Declarations:

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const VK_SPACE = &H20
Public Const WM_COMMAND = &H111
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const WM_SETTEXT = &HC
Public Const WM_GETTEXT = &HD
Public Const WM_GETTEXTLENGTH = &HE

2 Responses to “Introduction to Messenger API Type Library”


  1. 1 Camila

    Hi,

    Do you know….How to add a new item to menu that shows when i right click on a group or a contact?

    thx,

  2. 2 motti

    hi,
    I have trayed to open project and ues the refrens “Messenger API Type library” in c# or visual basic but I cant open the dll file
    dos sam on now what to do?
    Thank motti

Leave a Reply