I'm trying to use the skype4com to work with skype from c++ code.
All the strait forward commands works great, but I don't get the events.
I'm attaching the basics of my code, maybe someone know why it's notworking.
10x,
Ofer
/*----------- Activation code -------------------------*/
CComPtr<_ISkypeEvents> evnt;
CComPtr<ISkype> app = NULL;
CComPtr<IApplication> pApp;
CComPtr<IConnectionPoint> pIConnectionPoint = NULL;
CComPtr<IConnectionPointContainer> pIConnectionPointContainer = NULL;
HRESULT hr;
hr=CoCreateInstance(CLSID_EventsDispatcher,
NULL,CLSCTX_ALL,
DIID__ISkypeEvents,
(void**)&evnt);
if (hr != S_OK)
{
return hr;
}
hr = CoCreateInstance(CLSID_Skype, NULL, CLSCTX_ALL, IID_ISkype, (LPVOID *)&app);
if (hr != S_OK)
{
return hr;
}
app->ChangeUserStatus(cusDoNotDisturb);
hr=app->Attach(3, -1);
// query the Messenger Object for connection point container
hr=app->QueryInterface(IID_IConnectionPointContainer,(void**)&pIConnectionPointContainer);
// find the DMessengerEvents to see if it is supported
hr=pIConnectionPointContainer->FindConnectionPoint(DIID__ISkypeEvents,&pIConnectionPoint);
//finally advise the Messenger Object to get events
DWORD pdwCookie = NULL;//Pointer to the connection point identifier used by Unadvise
hr=pIConnectionPoint->Advise(evnt,&pdwCookie);
Sleep(100000);
/*--------------------- Class to get events -----------------------*/
class ATL_NO_VTABLE CEventsDispatcher :
public CComObjectRootEx<CComMultiThreadModel>,
public CComCoClass<CEventsDispatcher, &CLSID_EventsDispatcher>,
public ISupportErrorInfo,
// public IDispatchImpl<IEventsDispatcher, &IID_IEventsDispatcher, &LIBID_IMEventsCatchLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
public IDispatchImpl<_ISkypeEvents, &DIID__ISkypeEvents, &LIBID_IMEventsCatchLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
public:
CEventsDispatcher()
{
m_pUnkMarshaler = NULL;
}
DECLARE_REGISTRY_RESOURCEID(IDR_EVENTSDISPATCHER)
BEGIN_COM_MAP(CEventsDispatcher)
// COM_INTERFACE_ENTRY(IEventsDispatcher)
COM_INTERFACE_ENTRY(_ISkypeEvents)
// COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
END_COM_MAP()
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
DECLARE_PROTECT_FINAL_CONSTRUCT()
DECLARE_GET_CONTROLLING_UNKNOWN()
HRESULT FinalConstruct()
{
return CoCreateFreeThreadedMarshaler(
GetControllingUnknown(), &m_pUnkMarshaler.p);
}
void FinalRelease()
{
m_pUnkMarshaler.Release();
}
CComPtr<IUnknown> m_pUnkMarshaler;
public:
STDMETHODIMP CEventsDispatcher::Invoke(DISPID dispidMember,
REFIID riid, LCID lcid, WORD wFlags,
DISPPARAMS* pDispParams, VARIANT* pvarResult,
EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
int x;
x=1;
return S_OK;
}
STDMETHODIMP CEventsDispatcher::Command( ICommand* pCommand){return S_OK;}
STDMETHODIMP CEventsDispatcher::Reply( ICommand* pCommand){return S_OK;}
STDMETHODIMP CEventsDispatcher::Error(
ICommand* pCommand,
long Number,
BSTR Description){return S_OK;}
STDMETHODIMP CEventsDispatcher::AttachmentStatus( TAttachmentStatus Status){return S_OK;}
STDMETHODIMP CEventsDispatcher::ConnectionStatus( TConnectionStatus Status){return S_OK;}
STDMETHODIMP CEventsDispatcher::UserStatus( TUserStatus Status){return S_OK;}
STDMETHODIMP CEventsDispatcher::OnlineStatus(
IUser* pUser,
TOnlineStatus Status){return S_OK;}
STDMETHODIMP CEventsDispatcher::CallStatus(
ICall* pCall,
TCallStatus Status){return S_OK;}
STDMETHODIMP CEventsDispatcher::CallHistory(){return S_OK;}
STDMETHODIMP CEventsDispatcher::Mute( VARIANT_BOOL Mute){return S_OK;}
STDMETHODIMP CEventsDispatcher::MessageStatus(
IChatMessage* pMessage,
TChatMessageStatus Status){return S_OK;}
STDMETHODIMP CEventsDispatcher::MessageHistory( BSTR Username){return S_OK;}
STDMETHODIMP CEventsDispatcher::AutoAway( VARIANT_BOOL Automatic){return S_OK;}
STDMETHODIMP CEventsDispatcher::CallDtmfReceived(
ICall* pCall,
BSTR code){return S_OK;}
STDMETHODIMP CEventsDispatcher::VoicemailStatus(
IVoicemail* pMail,
TVoicemailStatus Status){return S_OK;}
STDMETHODIMP CEventsDispatcher::ApplicationConnecting(
IApplication* pApp,
IUserCollection* pUsers){return S_OK;}
STDMETHODIMP CEventsDispatcher::ApplicationStreams(
IApplication* pApp,
IApplicationStreamCollection* pStreams){return S_OK;}
STDMETHODIMP CEventsDispatcher::ApplicationDatagram(
IApplication* pApp,
IApplicationStream* pStream,
BSTR Text){return S_OK;}
STDMETHODIMP CEventsDispatcher::ApplicationSending(
IApplication* pApp,
IApplicationStreamCollection* pStreams){return S_OK;}
STDMETHODIMP CEventsDispatcher::ApplicationReceiving(
IApplication* pApp,
IApplicationStreamCollection* pStreams){return S_OK;}
STDMETHODIMP CEventsDispatcher::ContactsFocused( BSTR UserHandle){return S_OK;}
STDMETHODIMP CEventsDispatcher::GroupVisible(
IGroup* pGroup,
VARIANT_BOOL Visible){return S_OK;}
STDMETHODIMP CEventsDispatcher::GroupExpanded(
IGroup* pGroup,
VARIANT_BOOL Expanded){return S_OK;}
STDMETHODIMP CEventsDispatcher::GroupUsers(
IGroup* pGroup,
IUserCollection* pUsers){return S_OK;}
STDMETHODIMP CEventsDispatcher::GroupDeleted( long GroupId){return S_OK;}