For Programmers: Free Programming Magazines  


Home > Archive > VC Language > January 2006 > Problem in COM object calling, it stucks the WINWORD object.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Problem in COM object calling, it stucks the WINWORD object.
Irfan

2006-01-26, 7:08 pm

Hi,

I am expressing 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.

Is there any alternate or better way doing this? I need this very urgently,
any help please.

Thanks you,
Irfan

Simon Trew

2006-01-27, 8:01 am

Try reposting in microsoft.public.office.developer.automation


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com