=?Utf-8?Q?Outlook_don=E2=80=99t_quit?=
I am using the MSOutlook automation in C++ too send an email from my
application.
After send the email, I use the Quit method to close quit from Outlook, but
the Outlook service didn???t not close. What can I do to exit Outlook?
My code is the following:
BOOL lb_outlookOpen = FALSE;
HANDLE icl_hProcess;
char buf[1024];
LPDISPATCH lpDisp;
HWND hWnd;
DWORD pid;
DWORD dThread;
// verify if Outlook is open
hWnd = ::FindWindow("rctrl_renwnd32", NULL);
if(hWnd)
{lb_outlookOpen = TRUE;}
_Application olApp;
Attachments myAttachments;
if(!olApp.CreateDispatch("Outlook.Application"))
return FALSE;
COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
_MailItem olMail = olApp.CreateItem(0);
myAttachments = olMail.GetAttachments();
for(int i=0; i<icl_attachmentsListFiles.GetCount(); i++)
{
COleVariant oAttachLocation(icl_attachmentsListFiles[i]);
myAttachments.Add(oAttachLocation,
covOptional,
covOptional,
covOptional);
}
olMail.SetSubject(is_mailSubject);
if(lb_outlookOpen)
olMail.Display(COleVariant((short)FALSE));
else
{
BeginWaitCursor();
olMail.Display(COleVariant((short)TRUE));
EndWaitCursor();
}
if(!lb_outlookOpen) olApp.Quit();
myAttachments.DetachDispatch();
myAttachments.ReleaseDispatch();
olMail.DetachDispatch();
olMail.ReleaseDispatch();
olApp.DetachDispatch();
olApp.ReleaseDispatch();