IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> [VB6] Introduction To The Messenger Api
Stigmata
post Sep 5 2004, 01:18 PM
Post #1


Mess.betterthanyours
Group Icon

Group: Supervisor
Posts: 1,951
Joined: 5-September 04
From: Uk
Member No.: 79



visual basic :

firstly you need to set a reference to msn messenger, you do this by going to project, references. and then choose ' Messenger API Type Libary '.
then in a form use the example code

CODE

Private msnmsgr As IMessenger

Private Sub Form_Load()
Set msnmsgr = New MessengerAPI
End Sub




Vb Script :

vb script can be used in any html document, and is very simple to use if you have some vb knowalge.

basicly after the body tag add

CODE
<OBJECT classid=clsid:B69003B3-C55E-4B48-836C-BC5946FC3B28
codeType=application/x-oleobject id=IMessenger width=0 height=0></OBJECT>


that is loading the api with your document.

then in the head tag put

CODE

<script LANGUAGE="VBScript">

this is opening the scripting area bit msn_grin.gif

after that put the code u want
CODE

Sub addcontact
IMessenger.AddContact ("i_love_the_people[img]http://forum.mess.be/admin_images/noreply.gif[/img]plasticangels.com")
End Sub


end script tag
CODE
</SCRIPT>

thats just simple visual basic, adding your contact

to make it work you need to tell it to work

so you can use many ways, such as onload and onclick

to run the script when the form loads, in the body tag put
CODE
<body onload="VBScript:addcontact">

and to run on a click
CODE
onlick="VBScript:addcontact"


quite simple realy msn_grin.gif

just change the addcontact bit to the name of the sub you have wrote msn_grin.gif


Vb.net :

Open visual studio.net 2003 and create a new project .
make a reference to Messenger API Type Library 1.0.
(to make a reference, goto project, references)
After you have added the reference you must write a decleration :
CODE
Dim WithEvents msn As MessengerAPI.Messenger

After you have write the decleration double click on your form and write the following code
CODE

msn = New MessengerAPI.Messenger

this code should look like this :
CODE

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load msn = New MessengerAPI.Messenger()
End Sub



a example of using the code would be, in a command click button
CODE

msn.MyStatus = MessengerAPI.MISTATUS.MISTATUS_BUSY

that would change your status to busy


C++ :
Tutorial made by Insano
link: http://forums.msnfanatic.info/index.php?showtopic=5799

Creating the Messenger Object:

To create the Messenger Object use the CoCreateInstance API function.

CODE


//Your FriendlyName in a MessageBox
#include <windows.h>
#include "msgrua.h"
#include "msgruaid.h"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)  
{
  IMessenger *pIMessenger = NULL; //a pointer to an IMessenger interface
  BSTR pbstrName;
  CoInitialize(0);
  CoCreateInstance(CLSID_Messenger, NULL, CLSCTX_ALL, IID_IMessenger, (void **)&pIMessenger);
  pIMessenger->get_MyFriendlyName(&pbstrName);
  MessageBoxW(NULL, (LPCWSTR)pbstrName, (LPCWSTR)pbstrName, MB_OK);
  pIMessenger->Release();
  CoUninitialize();
  ExitProcess(0);
  return 0;
}


Internally Created Objects:

These objects cannot be created using the CoCreateInstance API function. Each has a specific object creation method within the Messenger API.

CODE

//Internally Created Objects
#include <windows.h>
#include "msgrua.h"
#include "msgruaid.h"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)  
{
  IMessenger *pIMessenger = NULL;
  IDispatch *pIDispatch = NULL;
  IMessengerContacts *pIMessengerContacts = NULL;
  IMessengerContact *pIMessengerContact = NULL;
  long pCount;
  BSTR pbstrName;
  BSTR pbstrFriendlyName;
  CoInitialize(0);
  CoCreateInstance(CLSID_Messenger, NULL, CLSCTX_ALL, IID_IMessenger, (void **)&pIMessenger);
  pIMessenger->get_MyContacts(&pIDispatch);
  pIDispatch->QueryInterface(IID_IMessengerContacts,(void**)&pIMessengerContacts);
  pIDispatch->Release();
  pIMessengerContacts->get_Count(&pCount);
  pIMessengerContacts->Item(pCount-1,&pIDispatch);
  pIDispatch->QueryInterface(IID_IMessengerContact,(void**)&pIMessengerContact);
  pIMessengerContacts->Release();
  pIMessengerContact->get_SigninName(&pbstrName);
  pIMessengerContact->get_FriendlyName(&pbstrFriendlyName);
  MessageBoxW(NULL, (LPCWSTR)pbstrFriendlyName, (LPCWSTR)pbstrName, MB_OK);
  pIMessengerContact->Release();
  pIMessenger->Release();
  CoUninitialize();
  ExitProcess(0);
  return 0;
}


Handling Events:
CODE

#include <windows.h>
#include "msgrua.h"
#include "msgruaid.h"

class msn;
class MessengerEvents;
msn *pMsn;

IMessenger  *pIMessenger = NULL;

IConnectionPoint *m_pConnectionPoint;
DWORD m_dwCookie;

class msn : public IUnknown {
public:
  msn();
  ~msn();
  ULONG STDMETHODCALLTYPE AddRef();
  ULONG STDMETHODCALLTYPE Release();
  STDMETHODIMP QueryInterface(REFIID iid, void ** ppvObject);
  MessengerEvents *m_pMessengerEvents;
  DWORD m_dwRefCount;
};

class MessengerEvents : public IDispatch {
public:
  MessengerEvents(msn *pmsn);
  ~MessengerEvents();
  STDMETHODIMP QueryInterface(REFIID iid, void ** ppvObject);
  ULONG STDMETHODCALLTYPE AddRef();
  ULONG STDMETHODCALLTYPE Release();
  HRESULT STDMETHODCALLTYPE GetTypeInfoCount(unsigned int FAR* pctinfo);
  HRESULT STDMETHODCALLTYPE GetTypeInfo(unsigned int iTInfo, LCID  lcid,
                                        ITypeInfo FAR* FAR*  ppTInfo);
  HRESULT STDMETHODCALLTYPE GetIDsOfNames(REFIID riid, OLECHAR FAR* FAR* rgszNames,
                                          unsigned int cNames, LCID lcid, DISPID FAR* rgDispId);
  HRESULT STDMETHODCALLTYPE Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
                                   DISPPARAMS FAR* pDispParams, VARIANT FAR* parResult,
                                   EXCEPINFO FAR* pExcepInfo, unsigned int FAR* puArgErr);
private:
  msn *m_pmsn;
};

msn::msn()
{
  IConnectionPointContainer* pCPContainer;
 
  m_dwRefCount = 1;
  m_pMessengerEvents = new MessengerEvents(this);
  HRESULT hr = pIMessenger->QueryInterface(IID_IConnectionPointContainer,(void**)(&pCPContainer));
  m_dwCookie = 0;
  if (SUCCEEDED(hr))
  {
      hr = pCPContainer->FindConnectionPoint(DIID_DMessengerEvents, &m_pConnectionPoint);
      if (SUCCEEDED(hr))
      {
          hr = m_pConnectionPoint->Advise(m_pMessengerEvents, &m_dwCookie);
      }
     
      if (pCPContainer) pCPContainer->Release();
  }
}


msn::~msn()
{
  m_pConnectionPoint->Unadvise(m_dwCookie);
  m_pConnectionPoint->Release();
  if (m_pMessengerEvents) delete m_pMessengerEvents;
}

ULONG STDMETHODCALLTYPE msn::AddRef()
{
  return ++m_dwRefCount;
}
ULONG STDMETHODCALLTYPE msn::Release()
{
  if(!--m_dwRefCount)
      delete this;
  return m_dwRefCount;
}



STDMETHODIMP msn::QueryInterface(REFIID iid, void ** ppvObject) {
  if(ppvObject == NULL) return E_INVALIDARG;
  *ppvObject = NULL;
  if(iid == IID_IUnknown)
      *ppvObject = (IUnknown*)this;
  else if(iid == DIID_DMessengerEvents || iid == IID_IDispatch)
      *ppvObject = m_pMessengerEvents;
  if(*ppvObject == NULL) return E_NOINTERFACE;
  AddRef();
  return S_OK;
}




MessengerEvents::MessengerEvents(msn *pmsn) { m_pmsn = pmsn; }
MessengerEvents::~MessengerEvents() {}

STDMETHODIMP MessengerEvents::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid,
                                   WORD wFlags, DISPPARAMS FAR* pDispParams,
                                   VARIANT FAR* parResult,
                                   EXCEPINFO FAR* pExcepInfo,
                                   unsigned int FAR* puArgErr)
{
BSTR pbstrName;
  BSTR pbstrTemp;
  if (!pDispParams)
      return E_INVALIDARG;
 
  switch (dispIdMember)
  {
  case DISPID_MUAE_ONSIGNIN:
      MessageBox(0,"Signed in",0,MB_OK);
      break;
  case DISPID_MUAE_ONSIGNOUT:
      MessageBox(0,"Signed out",0,MB_OK);
      break;
case DISPID_MUAE_ONMYFRIENDLYNAMECHANGE:
pbstrTemp = pDispParams->rgvarg[0].bstrVal;
      pIMessenger->get_MyFriendlyName(&pbstrName);
      MessageBoxW(0,(LPCWSTR)pbstrName,(LPCWSTR)pbstrTemp,MB_OK);
      break;
default:
      break;
  }
 
  return S_OK;
}



STDMETHODIMP MessengerEvents::QueryInterface(REFIID iid, void ** ppvObject)
{
  return m_pmsn->QueryInterface(iid, ppvObject);
}

ULONG STDMETHODCALLTYPE MessengerEvents::AddRef()
{ return m_pmsn->AddRef();  }

ULONG STDMETHODCALLTYPE MessengerEvents::Release()
{
  return m_pmsn->Release();
}


HRESULT STDMETHODCALLTYPE MessengerEvents::GetTypeInfoCount(unsigned int FAR* pctinfo)
{ return E_NOTIMPL; }

HRESULT STDMETHODCALLTYPE MessengerEvents::GetTypeInfo(unsigned int iTInfo, LCID  lcid,
                                                     ITypeInfo FAR* FAR*  ppTInfo)
{ return E_NOTIMPL; }

HRESULT STDMETHODCALLTYPE MessengerEvents::GetIDsOfNames(REFIID riid,
                                                       OLECHAR FAR* FAR* rgszNames,
                                                       unsigned int cNames,
                                                       LCID lcid,
                                                       DISPID FAR* rgDispId)
{ return E_NOTIMPL; }

LRESULT CALLBACK WndProc(HWND hWindow, UINT uiMessage, WPARAM wParam, LPARAM lParam)
{
  switch(uiMessage)
  {
  case WM_CLOSE:
      DestroyWindow(hWindow);
      break;
  case WM_DESTROY:
      PostQuitMessage(0);
      break;
  default:
      return DefWindowProc(hWindow, uiMessage, wParam, lParam);
  }
  return NULL;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
  MSG         msg;
  HWND        hwnd;
  WNDCLASSEX  wclsx;

  wclsx.cbClsExtra = NULL;
  wclsx.cbSize = sizeof(wclsx);
  wclsx.cbWndExtra = NULL;
  wclsx.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
  wclsx.hCursor = LoadCursor(NULL, IDC_ARROW);
  wclsx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  wclsx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  wclsx.hInstance = GetModuleHandle(NULL);
  wclsx.lpfnWndProc = WndProc;
  wclsx.lpszClassName = "MessengerEvents";
  wclsx.lpszMenuName = NULL;
  wclsx.style = NULL;

  RegisterClassEx(&wclsx);
  hwnd = CreateWindow("MessengerEvents", "Handling Events", WS_VISIBLE | WS_OVERLAPPEDWINDOW,
                      0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL);
  CoInitialize(0);
  CoCreateInstance(CLSID_Messenger, NULL, CLSCTX_ALL, IID_IMessenger, (void **)&pIMessenger);
  pMsn = new msn;
  while(GetMessage(&msg, NULL, NULL, NULL))
  {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
  }
  pIMessenger->Release();
  delete pMsn;
  CoUninitialize();
  ExitProcess(0);
  return 0;
}



Python :

http://msnp.sourceforge.net

msnp.py is an implementation of the MSN instant messaging protocol in the Python programming language.
Features:

* Login; logout
* Presence states (online, away, etc.)
* Full-fledged API-supported friend list management
* Privacy settings
* Chat conversations (start, join, leave)
* Instant messages
* Typing notifications
* HTTP proxy (tunnelling) support
Go to the top of the page
 
+Quote Post
timothy
post Sep 5 2004, 01:23 PM
Post #2



Group Icon

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



this will be very usefull for starting messers, btw, the how to use it with PHP code is allready availible msn_wink.gif
Go to the top of the page
 
+Quote Post
Patchou
post Sep 21 2004, 06:25 PM
Post #3


Mess.beetle
Group Icon

Group: VIP
Posts: 73
Joined: 3-September 04
From: Montreal
Member No.: 36



Very important note: if you plan on creating a plugin for Messenger Plus!, you must NOT call "New MessengerAPI". The Messenger object is sent in parameter in Initialize() so just use it (an example of that can be seen in the advanced plugin in VB.NET).
Go to the top of the page
 
+Quote Post
Homer4322
post Oct 24 2004, 04:20 PM
Post #4


Mess.beaver
***

Group: Members
Posts: 102
Joined: 5-October 04
Member No.: 1,044



thanks i just started vb.net and i have visual studio.net 2003 enterprise arcehtect but i cant find the messenger API/apis
Go to the top of the page
 
+Quote Post
MrWicked
post Nov 7 2004, 04:08 AM
Post #5


Mess.beaver
***

Group: Members
Posts: 140
Joined: 8-October 04
Member No.: 1,289



this is not for msn 7 correct?
Go to the top of the page
 
+Quote Post
mario
post Nov 7 2004, 01:43 PM
Post #6


Mess.beetle
**

Group: Members
Posts: 71
Joined: 27-September 04
Member No.: 170



The usage of api is not really useful these days
Go to the top of the page
 
+Quote Post
Stigmata
post Nov 7 2004, 04:37 PM
Post #7


Mess.betterthanyours
Group Icon

Group: Supervisor
Posts: 1,951
Joined: 5-September 04
From: Uk
Member No.: 79



Explain how it is not useful?

Mario, everything is useful in one way or another
Go to the top of the page
 
+Quote Post
Ahmad
post Nov 29 2004, 09:12 PM
Post #8


@hmad
Group Icon

Group: VIP
Posts: 962
Joined: 18-November 04
From: Melbourne, Australia
Member No.: 2,814



how can i view the Messenger API?
Go to the top of the page
 
+Quote Post
Stigmata
post Nov 29 2004, 09:29 PM
Post #9


Mess.betterthanyours
Group Icon

Group: Supervisor
Posts: 1,951
Joined: 5-September 04
From: Uk
Member No.: 79



in visual basic, make a reference to it, and press f2, then in the combo box at the top choose messenger api msn_happy.gif
Go to the top of the page
 
+Quote Post
Ahmad
post Nov 29 2004, 09:32 PM
Post #10


@hmad
Group Icon

Group: VIP
Posts: 962
Joined: 18-November 04
From: Melbourne, Australia
Member No.: 2,814



QUOTE(Stigmata @ Nov 30 2004, 08:29 AM)
in visual basic, make a reference to it, and press f2, then in the combo box at the top choose messenger api msn_happy.gif
[right][snapback]19567[/snapback][/right]


Thanks man! that helps alot msn_happy.gif
Go to the top of the page
 
+Quote Post
SuNcO
post Dec 31 2004, 01:40 AM
Post #11


Windows Live Butterfly
***

Group: Members
Posts: 144
Joined: 31-December 04
From: Mazatlán, Sinaloa, México
Member No.: 4,134



I have since 1 year a problem with the Reference, i never can choice it..

In the Reference i had the "Messenger API" but the file linked not exists, i think was the MSN 5 or something.. anyway, i never can put it.. 3 days ago i delete the Reference directly in the Registry of Windows and reinstall MSN (now have the 7) but still not appear in VB =/ (the same with MSN 6)

Exist one way to do that correctly ? Some fix Registry for that Reference or something ?

thanks all done now
Go to the top of the page
 
+Quote Post
CleanFilm
post Jan 15 2005, 03:22 PM
Post #12


Mess.beetle
**

Group: Members
Posts: 62
Joined: 15-December 04
Member No.: 3,719



QUOTE
Private msnmsgr As IMessenger

Private Sub Form_Load()
Set msnmsgr = New MessengerAPI
End Sub


No, To set the new messenger API its:

CODE
Set msn = New MessengerAPI.Messenger
Go to the top of the page
 
+Quote Post
doggie
post Jan 27 2005, 02:16 PM
Post #13


Shame on the ignorant
********

Group: Banned
Posts: 1,220
Joined: 6-October 04
From: Australia
Member No.: 1,062



CleanFilm:
makes no difference, its the same
Go to the top of the page
 
+Quote Post
readme.txt
post May 23 2005, 09:18 PM
Post #14


Mess.bean
*

Group: Members
Posts: 1
Joined: 23-May 05
Member No.: 9,180



I wonder if someone can help me with this error i seem to be constantly recieving every time i try to run my application... or any application using messenger api's. Before anybody says add the api's ive done it and i still seem to get this...

http://lejasonat0r.pwp.blueyonder.co.uk/wtf.JPG

What i have noticed is that in the references they seem to point to windows messenger and not messenger 7.0 msn_sarcastic.gif However im still unable to resolve it. Any help be mucho appreciated.

Regards
Go to the top of the page
 
+Quote Post
Sobeit
post Jun 4 2005, 04:56 AM
Post #15


Mess.beanie
*

Group: Members
Posts: 20
Joined: 7-October 04
Member No.: 1,128



QUOTE(readme.txt @ May 23 2005, 03:18 PM)
I wonder if someone can help me with this error i seem to be constantly recieving every time i try to run my application... or any application using messenger api's. Before anybody says add the api's ive done it and i still seem to get this...

http://lejasonat0r.pwp.blueyonder.co.uk/wtf.JPG

What i have noticed is that in the references they seem to point to windows messenger and not messenger 7.0  msn_sarcastic.gif However im still unable to resolve it. Any help be mucho appreciated.

Regards
[right][snapback]62987[/snapback][/right]

same for me...

this is rediculous...i find a nudge exploit, and now i cant make one because the only thing i can come up with is a lousy Emulate Mouse Click....
Go to the top of the page
 
+Quote Post
Stigmata
post Jun 4 2005, 09:43 AM
Post #16


Mess.betterthanyours
Group Icon

Group: Supervisor
Posts: 1,951
Joined: 5-September 04
From: Uk
Member No.: 79



QUOTE(readme.txt @ May 23 2005, 10:18 PM)
I wonder if someone can help me with this error i seem to be constantly recieving every time i try to run my application... or any application using messenger api's. Before anybody says add the api's ive done it and i still seem to get this...

http://lejasonat0r.pwp.blueyonder.co.uk/wtf.JPG

What i have noticed is that in the references they seem to point to windows messenger and not messenger 7.0  msn_sarcastic.gif However im still unable to resolve it. Any help be mucho appreciated.

Regards
[right][snapback]62987[/snapback][/right]


try following the tutorial

CODE

Private WithEvents Msn As MessengerAPI.Messenger


you cannot directly link to IMessenger via globals
Go to the top of the page
 
+Quote Post
hmaster
post Oct 19 2006, 03:09 PM
Post #17


Mess.beanbagfoo
Group Icon

Group: *Valued Members
Posts: 4,733
Joined: 27-September 04
From: UK
Member No.: 237



QUOTE(timothy @ Sep 5 2004, 01:23 PM)
this will be very usefull for starting messers, btw, the how to use it with PHP code is allready availible msn_wink.gif
[right][snapback]468[/snapback][/right]
Where is it available msn_tongue.gif?
Go to the top of the page
 
+Quote Post
vikke
post Oct 20 2006, 06:37 PM
Post #18


Mess.beanie
*

Group: Members
Posts: 13
Joined: 30-June 05
Member No.: 10,175



I think it's here:
http://sandbox.fanatic.net.nz/
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

 



RSS Lo-Fi Version Time is now: 24th January 2018 - 01:20 AM
© 2004-2008 Seb Skuse, mess.be.
MessForum v6.1.4 - created for, and for use only by mess.be.