title: Automation server is launched twice with CreateOleObject but not all the time
body: <p>I have a program written in Delphi 7 that is also an automation server.</p>
  
  <p>The automation server is registered the following way:</p>
  
  <pre><code>  TAutoObjectFactory.Create(ComServer, TMyServer, Class_App,
      ciMultiInstance, tmSingle);
  </code></pre>
  
  <p>I have two COM add-ins, one for Word and one for Outlook. Both of them are using the automation server to get some info from the main program. The following code is called from the add-ins, ie.: when the user clicks on a button in the add-in:</p>
  
  <pre><code> MyServerApp: Variant;
  begin
   MyServerApp := CreateOleObject('MyServer.App');
   try
     MyServerApp.DoSomething;
   finally
     MyServerApp := UnAssigned;
   end–
  </code></pre>
  
  <p><strong>Here is the problem:</strong>
  Most of the time the code works fine. If the main application is already running the add-ins will connect to the automation server and do their thing, if it is not running then the add-ins will launch the main application.</p>
  
  <p>But due to some unknown circumstances, especially with Outlook, it can sometimes happen that even though the main program is running, the add-in will not connect to it, but will instead relaunch the main application a second time and connect to the automation server of this new instance. The disaster comes here: since my app doesn't allow itself to be run in two instances, the second application instance will just display an error message and my add-in will freeze whole Outlook.</p>
  
  <p>Why does this happen? Why will CreateOleObject connect like it should most of the time, and launch my application again from time to time?</p>