CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2003
    Posts
    938

    IMAPIAdviseSink Problem

    Hey.
    I have the following code:
    Header;
    Code:
    #pragma once
    #include <cemapi.h>
    #include <mapiutil.h>
    #include <mapidefs.h>
    
    class CIMAPIAdviseSink : public IMAPIAdviseSink
    {
    public:
    	CIMAPIAdviseSink(void);
    	virtual ~CIMAPIAdviseSink();
    	
    	STDMETHODIMP			QueryInterface(REFIID riid, LPVOID * ppvObj);
    	STDMETHODIMP_(ULONG)	AddRef();
    	STDMETHODIMP_(ULONG)	Release();
    	
    	STDMETHODIMP_(ULONG)	OnNotify (ULONG cNotify, LPNOTIFICATION lpNotifications);
    
    private :	
    	LONG		m_cRef;
    };
    Source
    Code:
    #include "StdAfx.h"
    #include "CustomImapi.h"
    
    CIMAPIAdviseSink::CIMAPIAdviseSink(void)
    {
    }
    CIMAPIAdviseSink::~CIMAPIAdviseSink()
    {
    };
    
    
    STDMETHODIMP CIMAPIAdviseSink::QueryInterface(REFIID riid, LPVOID * ppvObj)
    {
    	*ppvObj = 0;
    	if (riid == IID_IMAPIAdviseSink ||	riid == IID_IUnknown)
    	{
    		*ppvObj = (LPVOID)this;
    		AddRef();
    		return S_OK;
    	}
    	return E_NOINTERFACE;
    };
    
    STDMETHODIMP_(ULONG) CIMAPIAdviseSink::AddRef() 
    {
    	LONG lCount = InterlockedIncrement(&m_cRef);
    	return lCount; 
    };
    
    STDMETHODIMP_(ULONG) CIMAPIAdviseSink::Release() 
    {
    	LONG lCount = InterlockedDecrement(&m_cRef);
    	if (!lCount)  delete this; 
    	return lCount;
    };
    
    STDMETHODIMP_(ULONG) CIMAPIAdviseSink::OnNotify (ULONG cNotify, LPNOTIFICATION lpNotifications)
    {
    	HRESULT			hRes = S_OK;
    
    	
    	try
    	{
    		for (ULONG i=0 ; i<cNotify ; i++)
    		{
    			hRes = S_OK;
    			if (fnevNewMail == lpNotifications[i].ulEventType)
    			{
    			}
    			else if (fnevTableModified == lpNotifications[i].ulEventType)
    			{
    				switch(lpNotifications[i].info.tab.ulTableEvent)
    				{
    				case(TABLE_ERROR):
    				case(TABLE_CHANGED):
    				case(TABLE_RELOAD):
    					//EC_H((HRESULT)::SendMessage(m_hWndParent,WM_MFCMAPI_REFRESHTABLE,(WPARAM) m_hTreeParent,0));
    					break;
    				case(TABLE_ROW_ADDED):
    					/*EC_H((HRESULT)::SendMessage(
    						m_hWndParent,
    						WM_MFCMAPI_ADDITEM,
    						(WPARAM) &lpNotifications[i].info.tab,
    						(LPARAM) m_hTreeParent));*/
    					break;
    				case(TABLE_ROW_DELETED):
    					/*EC_H((HRESULT)::SendMessage(
    						m_hWndParent,
    						WM_MFCMAPI_DELETEITEM,
    						(WPARAM) &lpNotifications[i].info.tab,
    						(LPARAM) m_hTreeParent));*/
    					break;
    				case(TABLE_ROW_MODIFIED):
    					/*EC_H((HRESULT)::SendMessage(
    						m_hWndParent,
    						WM_MFCMAPI_MODIFYITEM,
    						(WPARAM) &lpNotifications[i].info.tab,
    						(LPARAM) m_hTreeParent));*/
    					break;
    				}
    			}
    		}
    	}
    	catch(...)
    	{
    		/*ErrDialog(__FILE__,__LINE__,
    			_T("Exception encountered in CAdviseSink."));*/
    	}
    	return 0;
    }
    When i attempt to compile it i get:
    Code:
    error LNK2001: unresolved external symbol IID_IMAPIAdviseSink
    Any ideas why? I get go to the definition of the GUID easily.
    I included cemapi.lib in the linker options (Smart Device Deploymnet), but i got no idea why i am getting that error.
    Thx in advance.

  2. #2
    Join Date
    Aug 2003
    Posts
    938

    Re: IMAPIAdviseSink Problem

    Okey,
    I think i figured out the compilation error. I forgot a definition before the object. However i am still having some problems with the code
    Code:
    #define INITGUID
    #define USES_IID_IMAPIAdviseSink
    #include <initguid.h>
    #include <MAPIguid.h>
    #include <cemapi.h>
    class CMapiAdviseSink : public IMAPIAdviseSink
    {
    protected:
        LPNOTIFCALLBACK m_pfnCallback;
        LPVOID m_lpvContext;
        LONG m_cRef;
    
    public:
        CMapiAdviseSink( LPNOTIFCALLBACK pfnCallback, LPVOID lpvContext )
        : m_pfnCallback( pfnCallback )
        , m_lpvContext( lpvContext )
        , m_cRef( 0 )
        {
        }
    
    public:// IUnknown
        STDMETHOD(QueryInterface)( REFIID riid, LPVOID FAR * ppvObj )
        {
            if( IID_IUnknown == riid || IID_IMAPIAdviseSink == riid )
            {
                *ppvObj = this;
                AddRef();
                return S_OK;
            }
            return E_NOINTERFACE;
        }
        STDMETHOD_(ULONG, AddRef)()
        {
            return InterlockedIncrement( &m_cRef );
        }
        STDMETHOD_(ULONG, Release)()
        {
            ULONG ul = InterlockedDecrement( &m_cRef );
    
            if( 0 == ul )
                delete this;
    
            return ul;
        }
    
    public:// IMAPIAdviseSink
        STDMETHOD_(ULONG, OnNotify)( ULONG cNotif,
            LPNOTIFICATION lpNotifications )
        {
            if( m_pfnCallback )
                m_pfnCallback( m_lpvContext, cNotif, lpNotifications );
    
            return S_OK;
        }
    }; 
    STDAPI HrAllocAdviseSink( LPNOTIFCALLBACK lpfnCallback, LPVOID lpvContext, LPMAPIADVISESINK* lppAdviseSink )
    {
        if( NULL == lppAdviseSink )
            return E_INVALIDARG;
    
        *lppAdviseSink = new CMapiAdviseSink( lpfnCallback, lpvContext );
    
        if( NULL == *lppAdviseSink )
            return E_OUTOFMEMORY;
    
        (*lppAdviseSink)->AddRef();
        return S_OK;
    } 
    ULONG __stdcall CallBack (LPVOID lpvContext,  ULONG cNotification,  LPNOTIFICATION lpNotifications  )
    {
    	MessageBox(0,_T("tesT"),0,0);
    	return 0;
    }
    and use:
    Code:
    DWORD dwContext = 0;
    	CMapiAdviseSink *lppAdviseSink = new CMapiAdviseSink((LPNOTIFCALLBACK)&CallBack, &dwContext );
    lppAdviseSink);
    	(*lppAdviseSink).AddRef();
    Anyways, i tried getting any notifications but i am not breaking anywhere.
    Note that htis is running on a Win Ce device, but this should be no different from a desktop environment
    Any ideas where the mistake is?
    Thx in advance.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured