T
tired
I use the following code in an outlook plugin to save n selected msgs to disk. large amounts of
memory is consumed. This memory is only released when the SelectionPtr goes out of scope. Is there
any answer to this or am I doing this the wrong way. This works ok except for the memory consumption
on large selects.
any assistance would be appreciated
{
CComQIPtr<Office::_CommandBarButton> pCommandBarButton(Ctrl);
_ApplicationPtr pApp = NULL;
_ExplorerPtr pExp = NULL;
if(FAILED(pApp.CreateInstance(__uuidof(Application))))
{
MessageBox(NULL, _T("Bla Bla"),_T("Outlook"), MB_OK);
return;
}
try
{
long count;
CComVariant index(0);
IDispatchPtr pDisp = NULL;
---------> SelectionPtr pSel = NULL;
TestForFail(pApp->ActiveExplorer(&pExp), _T("Bla Bla"));
TestForFail(pExp->get_Selection(&pSel), _T("Unable to get Selection."));
TestForFail(pSel->get_Count(&count), _T("Unable to get Count."));
for(int i = 0; i < count; i++)
{
index = i+1;
---------------> TestForFail(pSel->Item(index , &pDisp), _T("Bla Bla"));
UINT type(0);
LCID lcid(0);
CComBSTR szName;
LPTYPEINFO lpMyTypeInfo = NULL;
TestForFail(pDisp->GetTypeInfo(type, lcid, &lpMyTypeInfo), _T("Bla Bla"));
if (lpMyTypeInfo != NULL)
TestForFail(lpMyTypeInfo->GetDocumentation(MEMBERID_NIL, &szName, 0,
0, 0), _T("Bla Bla"));
if (0 == strcmp("_MailItem",(char *) (_bstr_t)szName))
{
//Cast the IDispatch pointer to a MailItem pointer
_MailItemPtr pMailItem = pDisp;
char num[3000];
CComBSTR ch((LPCSTR) itoa(rand(), num, 10));
CComBSTR str((LPCOLESTR) m_WorkDir);
str.Append((LPCOLESTR) ch);
str.Append(L".xch");
TestForFail(pMailItem->SaveAs(str), _T("Failed to Save msg file"));
}
}
}
catch(_com_error &e)
{
DisplayError(_T("COM Error."), e);
}
}
memory is consumed. This memory is only released when the SelectionPtr goes out of scope. Is there
any answer to this or am I doing this the wrong way. This works ok except for the memory consumption
on large selects.
any assistance would be appreciated
{
CComQIPtr<Office::_CommandBarButton> pCommandBarButton(Ctrl);
_ApplicationPtr pApp = NULL;
_ExplorerPtr pExp = NULL;
if(FAILED(pApp.CreateInstance(__uuidof(Application))))
{
MessageBox(NULL, _T("Bla Bla"),_T("Outlook"), MB_OK);
return;
}
try
{
long count;
CComVariant index(0);
IDispatchPtr pDisp = NULL;
---------> SelectionPtr pSel = NULL;
TestForFail(pApp->ActiveExplorer(&pExp), _T("Bla Bla"));
TestForFail(pExp->get_Selection(&pSel), _T("Unable to get Selection."));
TestForFail(pSel->get_Count(&count), _T("Unable to get Count."));
for(int i = 0; i < count; i++)
{
index = i+1;
---------------> TestForFail(pSel->Item(index , &pDisp), _T("Bla Bla"));
UINT type(0);
LCID lcid(0);
CComBSTR szName;
LPTYPEINFO lpMyTypeInfo = NULL;
TestForFail(pDisp->GetTypeInfo(type, lcid, &lpMyTypeInfo), _T("Bla Bla"));
if (lpMyTypeInfo != NULL)
TestForFail(lpMyTypeInfo->GetDocumentation(MEMBERID_NIL, &szName, 0,
0, 0), _T("Bla Bla"));
if (0 == strcmp("_MailItem",(char *) (_bstr_t)szName))
{
//Cast the IDispatch pointer to a MailItem pointer
_MailItemPtr pMailItem = pDisp;
char num[3000];
CComBSTR ch((LPCSTR) itoa(rand(), num, 10));
CComBSTR str((LPCOLESTR) m_WorkDir);
str.Append((LPCOLESTR) ch);
str.Append(L".xch");
TestForFail(pMailItem->SaveAs(str), _T("Failed to Save msg file"));
}
}
}
catch(_com_error &e)
{
DisplayError(_T("COM Error."), e);
}
}