Wait until Windows COM server application has started and initialized

0

We have an application (written in C++) that implements a Windows COM (as in DCOM/Automation) server.

In a functional tests environment, we use the COM interface instantiation mechanism to get objects of our server's interface type, in order to test things automatically.

C# code:

SomeComInterfaceType object = new SomeComObject();

There are many tests running that way, where between each test, we kill the COM server process again before launching the next test. This works globally, but every now and then, tests fail with exceptions of the kind

System.Runtime.InteropServices.COMException: Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))

Searching for this error yields only sporadic information, where it is claimed that this can happen due to the COM server not yet well initialized and thus being unable to server the request. (Mostly with examples that automate WORD or EXCEL) What people seem to do to circumvent the issue is to just wait/sleep some time before doing the COM calls. This would be annoying since it would considerably slow down the tests.

So i wonder if there is a more robust way to avoid these issues.

Are there any sort of system calls where i can check if a COM server has been started and properly initialized? Something equivalent of Process.WaitForInputIdle, but for COM server based objects? Note that i cannot easily get the process Id of my COM server. (As asked in Get Process ID of COM Server).

windows
com
asked on Stack Overflow Dec 17, 2019 by Scrontch • edited Dec 20, 2019 by Scrontch

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0