If you are processing and printing only some items in the folder, why do you
loop though all of them instead of applying a restriction and using
ITems.Find/Restrict?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
"Pradeep Singh" wrote in message
...
Thanks Dmitry for interest in this topic.
Basically I need to get the information from each mail in the folder and
dump it some place, and then print the mail if certain condtion is met.
The code is extension of comaddin.exe from
(http://support.microsoft.com/kb/230689)
The ButtonHandler is extended as follows:
STDMETHODIMP CButtonHandler::Invoke(DISPID dispIdMember, REFIID riid, LCID
lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
if (IID_NULL != riid)
return DISP_E_UNKNOWNINTERFACE;
if (dispIdMember != 0x00000001)
return DISP_E_MEMBERNOTFOUND;
if (NULL == pDispParams) return E_POINTER;
if (pDispParams-cArgs != 2) return DISP_E_BADPARAMCOUNT;
ProcessItems();
return S_OK;
}
void CButtonHandler::ProcessItems()
{
// get the MAPIFolderPtr pFolder from user provided foldername;
_ItemsPtr pItems = NULL;
pItems = pFolder-GetItems();
long nItems = pItems == NULL ? 0 : pItems-GetCount();
for ( long i=0; inItems; i++)
{
IDispatchPtr pDispItem = NULL;
try { pDispItem = pItems-Item(_variant_t((long)(i+1))); } catch(...){}
if (pDispItem != NULL)
{
ProcessItemType(pDispItem);
}
else
break;
}
}
void CButtonHandler::ProcessItemType(IDispatch* pDispItem)
{
if (pDispItem == NULL)
return;
_MailItemPtr pMailItem;
pDispItem-QueryInterface(__uuidof(_MailItem), (LPVOID*)&pMailItem);
if (pMailItem != NULL)
{
//get many things from pMailItem such as body , subject, to from , and
dump it to
// some place
if ( some condition is met in subject)
pMailItem-PrintOut();
}
}
Two problems:
1) while this code is being executed I can not have keyboard controls and
preview pane is fixed ( does not change)
2) the .PrintOut call is actually executed when control returns from this
code. This problem is not seen in Outlook 2007, but I can see it in
Outlook 2003. surprisingly in Outlook 2003 also this works fine provided
the selected mail is text only mail ( no html body)
I read in many threads in this forum that Outlook executes COM addin in
it's main thread. Ideal solution will be to release this thread in for
loop of CButtonHandler::ProcessItems() once, so that Outlook can process
the keyboard requests and print requests. Solution proposed by Ken
regarding use of DoEvents would have solved this issue provided that could
be achieved in C++.
Hope this explains the problem. Please let me know how can this be solved.
Regards,
Pradeep
"Dmitry Streblechenko" wrote in message
...
Why exactly do you need to process *all* items in a folder? What is your
code?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
"Pradeep Singh" wrote in message
...
I'm trying to process all the emails of a folder using a COM addin. I
get the folder (MAPIFolderPtr). From that I can get mails using
GetItems. This whole loop of going through mails takes quite a while.
And unfortunately Outlook does not respond to keyboard commands ( e.g.
ctrl N) during this, also the preview pane does not change even if I
choose
another e-mail ( mouse is working). Is this a known issue with COM
addins or I need to take care of something special to avoid this.
Another issue is, if I fire print (-PrintOut) on any item this call
is not honoured until I finish all the processing of the folder and
return from my COM adding control.
It would be great if someone could help me or point me to right
direction.
Kind Regards,
Pradeep