title: ATL DCOM Object creation fails in VS 2010 Build
body: <p>We have a DCOM server which works fine in Win 7 64 Bit for the VS 2008 build. In the case of VS 2010 build, the client side object creation fails with "Server Creation Failed" error message. The class  definition is given below.  </p>
  
  <p>When debugged, we have seen that a message with message id 1024, has received in the message loop, but <code>DispatchMessage</code> does not route the message, to create  <code>CICEConnect</code> object.  In the VS 2008 build, <code>DispatchMessage</code> routes the call to create <code>CICEConnect</code> object.  I believe this creates the issue</p>
  
  <p>The server application was stated when the client tries to create the object.  The DCOM server is running in the local machine</p>
  
  <p>How can I debug the issue further?</p>
  
  <pre><code>void RunMessageLoop() throw()
        {
              MSG msg;
              while (GetMessage(&amp;msg, 0, 0, 0) &gt; 0)
              {
                    TranslateMessage(&amp;msg);
                    DispatchMessage(&amp;msg);
              }
        }
  </code></pre>
  
  <hr>
  
  <pre><code>class ATL_NO_VTABLE CICEConnect :
        public CComObjectRootEx&lt;CComMultiThreadModel&gt;,
        public CComCoClass&lt;CICEConnect, &amp;CLSID_ICEConnect&gt;,
        public IDispatchImpl&lt;IICEConnect, &amp;IID_IICEConnect, &amp;LIBID_ICEConnectServerLib, /*wMajor =*/ 1, /*wMinor =*/ 0&gt;
  {
  public:
        CICEConnect()
        {
        }
        DECLARE_CLASSFACTORY_SINGLETON(CICEConnect)
  DECLARE_REGISTRY_RESOURCEID(IDR_ICECONNECT)
  
  
  BEGIN_COM_MAP(CICEConnect)
        COM_INTERFACE_ENTRY(IICEConnect)
        COM_INTERFACE_ENTRY(IDispatch)
  END_COM_MAP()
  
  };
  </code></pre>
  
  <hr>
  
  <p>If I Skip <code>p-&gt;Release();</code> in the following <code>RegisterClassObject</code>, the COM Object creation succeeds. </p>
  
  <pre><code>struct _ATL_OBJMAP_ENTRY30
  {
         HRESULT WINAPI RegisterClassObject(
                _In_ DWORD dwClsContext,
                _In_ DWORD dwFlags)
         {
                IUnknown* p = NULL;
                if (pfnGetClassObject == NULL)
                       return S_OK;
                HRESULT hRes = pfnGetClassObject(pfnCreateInstance, __uuidof(IUnknown), (LPVOID*) &amp;p);
                if (SUCCEEDED(hRes))
                       hRes = CoRegisterClassObject(*pclsid, p, dwClsContext, dwFlags, &amp;dwRegister);
                if (p != NULL)
                       p-&gt;Release();
                return hRes;
         }
  // Added in ATL 3.0
         void (WINAPI *pfnObjectMain)(_In_ bool bStarting);
  };
  </code></pre>
  
  <p>The Code used to create the COM object is given below</p>
  
  <pre><code>int _tmain(int argc, _TCHAR* argv[])
  {
        CoInitializeEx(NULL,COINIT_MULTITHREADED);
  
                        COSERVERINFO server;
                        memset(&amp;server,0,sizeof(COSERVERINFO));
                        COAUTHINFO athn;
                        ZeroMemory(&amp;athn, sizeof(COAUTHINFO));
                        athn.dwAuthnLevel = RPC_C_AUTHN_LEVEL_NONE;
                        athn.dwAuthnSvc = RPC_C_AUTHN_WINNT;
                        athn.dwAuthzSvc = RPC_C_AUTHZ_NONE;
                        athn.dwCapabilities = EOAC_NONE;
                        athn.dwImpersonationLevel = RPC_C_IMP_LEVEL_IMPERSONATE;
                        athn.pAuthIdentityData = NULL;
                        athn.pwszServerPrincName = NULL;
                        server.pAuthInfo = &amp;athn;
                        server.pwszName = L"\\\\localhost";
                        server.dwReserved1 = 0;
                        server.dwReserved2 = 0;
                        MULTI_QI mqi = {&amp;IID_IICEConnect, NULL, S_OK};
  
                        // Access the PMC on the given machine
                          HRESULT hRes = CoCreateInstanceEx(CLSID_ICEConnect,NULL,
                                          CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER,&amp;server,1,&amp;mqi);
        return 0;
  }
  </code></pre>