Deleted items not updated!!!

M

MON205

Hello all,
I'm developing an Outlook Addin...
I encounter a problem that when my addin perform simple functionality which
is looping through all folders, then when the user work on Outlook move
messages from the inbox to Deleted Items folder, the Deleted Items folder
still empty till you restart the outlook.
In my code, I loop through all folders and get Items an do some process on
them. For testing this problem I removed looping into items and processing
and the problem still.
Finally I found that the problem in "pFolder->get_Items" which when I call,
the problem found, and if I removed this statement, the problem fly...
In my code below, I don't do anything with the _ItemsPtr !!!!!
Where is the problem?!! What I've missed?!!

Here is my code:
//////////////////////////////////////////////////////////////
int MyClass::Start( )
{
m_nCount = 0;
Outlook::_NameSpacePtr pMapi = NULL;
pMapi = m_spApp->GetNamespace( _bstr_t( "MAPI" ) );
if( NULL == pMapi )
{
return 0;
}

HRESULT hr;
_FoldersPtr pFoldersCollection = NULL;
hr = pMapi->get_Folders( & pFoldersCollection );
if( FAILED( hr ) )
{
pMapi->Release( );
pMapi = NULL;
return 0;
}
MAPIFolderPtr pFolder = NULL;
long lFoldersCount = pFoldersCollection->GetCount( );
pFolder = pFoldersCollection->GetFirst( );

for( long lIndex = 0; lIndex < lFoldersCount; lIndex++ )
{
ReadFolder( pFolder );
// release...
pFolder->Release( );
pFolder = NULL;
pFolder = pFoldersCollection->GetNext( );
}
// release...
pFoldersCollection->Release( );
pFoldersCollection = NULL;
pMapi->Release( );
pMapi = NULL;
return 1;
}

int MyClass::ReadFolder( MAPIFolderPtr pFolder )
{
_ItemsPtr pItems = NULL;
HRESULT hr;

hr = pFolder->get_Items( & pItems ); // Here is the problem
if( FAILED( hr ) )
{
return 0;
}
// release...
pItems->Release( );
pItems = NULL;

_FoldersPtr pFoldersCollection = NULL;
hr = pFolder->get_Folders( & pFoldersCollection );
if( FAILED( hr ) )
{
return 0;
}
long lFoldersCount = pFoldersCollection->GetCount( );
if( lFoldersCount > 0 )
{
MAPIFolderPtr pInnerFolder = pFoldersCollection->GetFirst( );
while( pInnerFolder )
{
ReadFolder( pInnerFolder );
// release...
pInnerFolder->Release( );
pInnerFolder = NULL;
pInnerFolder = pFoldersCollection->GetNext( );
}
}
// release...
pFoldersCollection->Release( );
pFoldersCollection = NULL;

return 1;
}
//////////////////////////////////////////////////////////////
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top