Stuck problem when WordEditor Close method is called?

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
 
K

Ken Slovak - [MVP - Outlook]

I've found that when using WordMail that if I close the Inspector or
MailItem that I get that empty Word window if there's only 1 Word window of
any kind open (Word doc or WordMail). If there are more than one open then
it doesn't happen. The only hack I've been able to get working is to call
for Word to quit. I instantiate a Word.Application object if WordMail is
being used (oWord) and then call oWord.Close if oWord.Windows.Count <= 1.

I've also found that if I try to close a WordMail window from within a Send
event handler or other such event handler that it errors. What I've had to
do is to set up a Windows timer and set that to fire about 500 ms after I
set the timer in the event handler. That allows time for the event handler
to terminate before the timer fires. In the timer event handler I then close
the Inspector.




Irfan said:
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
 

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