I
Irfan
Hi,
I am experiencing a strange problem when I call Close method of WordEditor.
It
closes the open email and MS Word blank window stays there and sudden windows
error message appear that says "Send Error" button and has checkbox to reopen
the word.
I tried to diagnose this problem and this scenario I came to understand, If
I enter To address, Subject and just have a focus in word compose window the
email closes and ms word window stays there and it doesn't stuck anything.
But just I don't have a focus in that window it always stuck and error comes
up.
Below is the code that is written in my Button in compose window:
{ //Start of button click function
HRESULT hr;
//Get the email if flag for tracking, return boolean
CString Ret = MailTracked();
//Write log
logging.lineStatus ("Tracking option "+Ret);
if(Ret == "no")
{
//Send email normally.
mailItem->Send ();
}
else
{
//*Cancel= true;
//Don't send open email, send it using the Send method later.
*Cancel = VARIANT_TRUE;
CComPtr<Outlook::_Inspector > spInspect;
m_spApp->ActiveInspector (&spInspect);
CComPtr<IDispatch >dif;
spInspect->get_CurrentItem( &dif);
//Manipulate the mail item and send it manully in this function
Write_SentItemsData(dif);
dif=NULL;
//Check the type of editor open
enum Outlook::OlEditorType EditorType;
spInspect->get_EditorType (&EditorType);
//This code is written to put the focus in word window forcely
before sending the email. The working window handle is get and SendWindow
SET_Focus to do this. but not working...
HWND hwnd;
hwnd = ::GetForegroundWindow();
HRESULT hr = EnumChildWindows(hwnd, &EnumWindowsProc, NULL);
if(EditorType==olEditorText)
{
spInspect->Close (olDiscard);
}else
if(EditorType==olEditorRTF)
{
spInspect->Close (olDiscard);
}else
if(EditorType==olEditorHTML)
{
spInspect->Close (olDiscard);
}
else if(EditorType==olEditorWord)
{
//spInspect->Close (olDiscard);
// AfxMessageBox("Word");
CComPtr<IDispatch >Dispatch;
spInspect->get_WordEditor((IDispatch**)&Dispatch);
DISPID dispp;
OLECHAR FAR* szMemberpName;
VARIANTARG pResult;
EXCEPINFO pexcep;
UINT uArgErr;
DISPPARAMS disparams={NULL,NULL,0,0};
disparams.cArgs =1;
disparams.cNamedArgs=0;
disparams.rgdispidNamedArgs =NULL;
disparams.rgvarg =new VARIANTARG[1];
disparams.rgvarg [0].vt =VT_I4;
disparams.rgvarg [0].lVal = 0;
//szMemberpName = L"Application";
//Call the WordEditor object Close to close the
open word window
szMemberpName = L"Close";
VARIANTARG ApResult;
Dispatch->GetIDsOfNames (IID_NULL, &szMemberpName,
1, LOCALE_SYSTEM_DEFAULT, &dispp);
hr = Dispatch->Invoke(dispp, IID_NULL,
LOCALE_SYSTEM_DEFAULT,DISPATCH_METHOD, &disparams, &ApResult, &pexcep,
&uArgErr);
if(FAILED(hr))
{
_bstr_t des;
char * ii;
des = pexcep.bstrDescription;
ii = (char*) des;
logging.lineStatus ("Application method
fail");
}
else
{
}//End Close of WordEditor call
} //End Word Editor
}//End Send Email manually
}//End Function
When the Close method is called and code is return the open email does close
but it stuck the WINWORD and window error message appear.
I tried sending a WM_CLOSE message to hwnd at the end of above code and it
says a popup is open. But there is no popup anywhere in the Outlook or
WinWord. What could be the issue?
Is there any alternate or better way doing this? I need this very urgently,
any help please.
Thank you,
Irfan
I am experiencing a strange problem when I call Close method of WordEditor.
It
closes the open email and MS Word blank window stays there and sudden windows
error message appear that says "Send Error" button and has checkbox to reopen
the word.
I tried to diagnose this problem and this scenario I came to understand, If
I enter To address, Subject and just have a focus in word compose window the
email closes and ms word window stays there and it doesn't stuck anything.
But just I don't have a focus in that window it always stuck and error comes
up.
Below is the code that is written in my Button in compose window:
{ //Start of button click function
HRESULT hr;
//Get the email if flag for tracking, return boolean
CString Ret = MailTracked();
//Write log
logging.lineStatus ("Tracking option "+Ret);
if(Ret == "no")
{
//Send email normally.
mailItem->Send ();
}
else
{
//*Cancel= true;
//Don't send open email, send it using the Send method later.
*Cancel = VARIANT_TRUE;
CComPtr<Outlook::_Inspector > spInspect;
m_spApp->ActiveInspector (&spInspect);
CComPtr<IDispatch >dif;
spInspect->get_CurrentItem( &dif);
//Manipulate the mail item and send it manully in this function
Write_SentItemsData(dif);
dif=NULL;
//Check the type of editor open
enum Outlook::OlEditorType EditorType;
spInspect->get_EditorType (&EditorType);
//This code is written to put the focus in word window forcely
before sending the email. The working window handle is get and SendWindow
SET_Focus to do this. but not working...
HWND hwnd;
hwnd = ::GetForegroundWindow();
HRESULT hr = EnumChildWindows(hwnd, &EnumWindowsProc, NULL);
if(EditorType==olEditorText)
{
spInspect->Close (olDiscard);
}else
if(EditorType==olEditorRTF)
{
spInspect->Close (olDiscard);
}else
if(EditorType==olEditorHTML)
{
spInspect->Close (olDiscard);
}
else if(EditorType==olEditorWord)
{
//spInspect->Close (olDiscard);
// AfxMessageBox("Word");
CComPtr<IDispatch >Dispatch;
spInspect->get_WordEditor((IDispatch**)&Dispatch);
DISPID dispp;
OLECHAR FAR* szMemberpName;
VARIANTARG pResult;
EXCEPINFO pexcep;
UINT uArgErr;
DISPPARAMS disparams={NULL,NULL,0,0};
disparams.cArgs =1;
disparams.cNamedArgs=0;
disparams.rgdispidNamedArgs =NULL;
disparams.rgvarg =new VARIANTARG[1];
disparams.rgvarg [0].vt =VT_I4;
disparams.rgvarg [0].lVal = 0;
//szMemberpName = L"Application";
//Call the WordEditor object Close to close the
open word window
szMemberpName = L"Close";
VARIANTARG ApResult;
Dispatch->GetIDsOfNames (IID_NULL, &szMemberpName,
1, LOCALE_SYSTEM_DEFAULT, &dispp);
hr = Dispatch->Invoke(dispp, IID_NULL,
LOCALE_SYSTEM_DEFAULT,DISPATCH_METHOD, &disparams, &ApResult, &pexcep,
&uArgErr);
if(FAILED(hr))
{
_bstr_t des;
char * ii;
des = pexcep.bstrDescription;
ii = (char*) des;
logging.lineStatus ("Application method
fail");
}
else
{
}//End Close of WordEditor call
} //End Word Editor
}//End Send Email manually
}//End Function
When the Close method is called and code is return the open email does close
but it stuck the WINWORD and window error message appear.
I tried sending a WM_CLOSE message to hwnd at the end of above code and it
says a popup is open. But there is no popup anywhere in the Outlook or
WinWord. What could be the issue?
Is there any alternate or better way doing this? I need this very urgently,
any help please.
Thank you,
Irfan