Keeping outlook alive...

  • Thread starter Thread starter Huw
  • Start date Start date
H

Huw

This sounds like a stupid question, as normally the problem is normally
getting outlook to close down cleanly.

What my application does is create a new instance of Outlook.Application,
and then executes some code in one of the loaded addins. The code in the
addin is executed on a different thread and the call returns almose
immediately.

When it returns, the application closes down and releases it's reference to
outlook. This causes outlook to shutdown, destroying the thread that's
busy!

What I want to do is block outlook from closing down for the time the addin
is executing the code in the thread.

I thought I could just add another reference to outlook.application (from
inside the addin) and that would keep it alive, but it doesn't seem to do
the trick.

I then tried adding a reference to the object returned by
Outlook.Application.GetNamespace("MAPI") (thinking that there was some
perculiar behaviour with outlook), but the same behaviour.

I dont understand why outlook is closing down even though I have addref'd
the app object many times.

Does anyone have any ideas why addrefing does not work, or know of any way I
call tell outlook that it should not shut down.

Thanks in advance,
Huw
 
You would have to show some of your code so we can see how you are
doing what you are doing.
 
I can't actually show you all the code as there is lots of it and it's
nearly
all in c++, but in summary this is what is happening.

From IE script, I load up a com object (inside IE) with

var o = new ActiveXObject("MyObject.MyObjectName")
o.DoSomething()




DoSomething then loads up the outlook using...


MapiInitialize();

CComPtr<IMAPISession> MAPISessionPtr;
HRESULT hrLogon = MAPILogonEx(0, NULL, NULL,MAPI_LOGON_UI|MAPI_ALLOW_OTHERS,
&MAPISessionPtr);

// Launch Outlook if it isn't already running
CLSID clsidOutlook;
CLSIDFromProgID(L"Outlook.Application", &clsidOutlook);

CComPtr<IDispatch> OutlookPtr;
CoCreateInstance(clsidOutlook, NULL, CLSCTX_LOCAL_SERVER,
IID_IDispatch,(void **)&OutlookPtr);

CComPtr<IDispatch> AutoDesktopPtr;
CComVariant result;
CComVariant varObjectName(L"MyAddin.Object");

AutoWrap(DISPATCH_METHOD, &result, OutlookPtr, L"CreateObject",
1,varObjectName);
AutoDesktopPtr = result.pdispVal;

CComVariant result;
CComVariant varString(str);
AutoWrap(DISPATCH_METHOD, &result, AutoDesktopPtr, L"AddInDoSomething",
1,varString);

AutoDesktopPtr = NULL;
OutlookPtr = NULL;

MapiUninitialize();

The AutoWrap calls just wrap up calls to GetIDsOfNames and Invoke.



Then my outlook addin contains something like the following.....


//Create an outlook application to try and keep outlook alive
CLSID clsidOutlook;
CComPtr<IDispatch> OutlookPtr;
CLSIDFromProgID(L"Outlook.Application", &clsidOutlook);
CoCreateInstance(clsidOutlook, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch,
(void **)&OutlookPtr);

CMyDownloader* pDownloader = new CMyDownloader();
//Set the keep alive pointer to outlook, this will be released when the
thread finishes!
pDownloader->SetKeepAlivePtr(OutlookPtr);
pDownloader->Download();


The setkeepaliveptr is my attempt to keep outlook up and running, I thought
the reference on the object would keep it alive, but it doesnt.

Does the make sense ken?
Thanks,
Huw
 
I'm sorry for the delay in answering. I can't really help with this, I
don't code in C++ or use MAPI. I'd repost your question with a
different subject to see if someone more familiar with that can help
you.
 
Back
Top