Word and IOleContainer.LockContainer
I am developing an OLE link source in C# and I am having trouble determining when to automatically exit when it runs as a hidden out-of-process server. Based on the documentation I would expect to exit when the IOleContainer.LockContainer() count reaches zero. Unfortunately Word 2000 and 2002 (but not 2007) calls LockContainer(false) while it still has IOleObject.Advise() and IDataObject.DAdvise() sinks registered with my application, which it is still trying to use. Therefore I cannot use LockContainer() as the signal to shut down my hidden out-of-process COM server. How should I decide when to shut down?
(I tried waiting until all advise connections were closed, but that means my application closes and re-opens for each linked object in the Word document. I tried adding a delay before shutdown to address this problem, but Word then stopped calling LockContainer(false) as before, leaving me with a positive lock count!)
(I tried waiting until all advise connections were closed, but that means my application closes and re-opens for each linked object in the Word document. I tried adding a delay before shutdown to address this problem, but Word then stopped calling LockContainer(false) as before, leaving me with a positive lock count!)
6 Comments:
Hi Oliver,
I am having problem with excel automation.
I have been developing an application in C#.NET which needs to extract embedded office documents (DOC,XLS,PPT) from office documents (DOC,XLS,PPT)
For this i have been using the COM Interop Assembly exposed by .NET for Microsoft Office.
But i am having problem when i deal with Excel File. I have been getting these two errors:
1. Error: Exception from HRESULT: 0x800A03EC
2. Error: Call was rejected by callee. (Exception from HRESULT:
0x80010001 (RPC_E_CALL_REJECTED))
These errors are highly unpredictable.
Till now i have found that error 2 can be solved by doing like this
http://msdn.microsoft.com/en-us/library/ms228772.aspx
But this will make my application dependent upon Visual Studio IDE.
I have googled a lot and someone has suggested to use Sleep(1000) of kernel32.dll but this is not solving my problem.
I have been rambling around internet for days now? I just went through your blog site and found out that you have been doing work on somewhat identical thing.
Also: Error 1 doesn't appear when i run the application by debugging step by step.
Note: My application also deals with outlook files at the same time. Does this interrupt Excel Automation? I have read somewhere it does?
Please let me know your thoughts on these.
Implementing IOleMessageFilter is definitely the right way to go. Your application need not depend on Visual Studio. Just add your own definition:
[ComImport(), Guid("00000016-0000-0000-C000-000000000046"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
interface IOleMessageFilter
{
[PreserveSig]
int HandleInComingCall(int dwCallType, IntPtr hTaskCaller, int dwTickCount, IntPtr lpInterfaceInfo);
[PreserveSig]
int RetryRejectedCall(IntPtr hTaskCallee, int dwTickCount, int dwRejectType);
[PreserveSig]
int MessagePending(IntPtr hTaskCallee, int dwTickCount, int dwPendingType);
}
...and I cannot see how dealing with Outlook could cause problems, but I have no experience in the area.
Hi Oliver,
I have tried using IOLEMessageFilter as well as shown in following link
http://msdn.microsoft.com/en-us/library/ms228772.aspx
I have removed the Visual Studio Part and have call MessageFilter.Register() before automation is done and then in the end i have called MessageFilter.Revoke().
But still i am having the same problem. Also i have tried setting the culture to en-US but again i get same error.
My pseudo code will be like this:
MessageFilter.Register();
object obj=Missing.Value;
//active excel document
excelOLEFormatObj.SaveAs(path, ref obj,ref obj,ref obj);
MessageFilter.Revoke();
What do you suggest?
I don't know what to suggest. It fixed my RPC_E_CALL_REJECTED problems. I have seen 0x800A03EC when users were editing formulas in Excel, when no workbook is open ad when dialogs were open. All you can do in these cases is try to present a friendly error message.
Hi Oliver,
Thank you for your response.
I am using IOLEMEssageFilter for RPC error but for the other one i still think that it has something to do with Outlook as well. Can you point me to email or forum of some concerned people who can have clear answer to this. I am having real problem regarding this.
Thank You
Post a Comment
<< Home