title: CDialog::Create fails for dialog with ActiveX control
body: <p>I have a module that creates a modeless dialog containing an ActiveX control. This module was part of an MFC EXE application and the creation of the dialog worked fine. Recently, I moved the module out into an ATL/COM server and copied the dialog resource from the EXE into the COM server. When trying to create the modeless dialog using <code>CDialog::Create()</code> an error happens.</p>
  
  <p>I debugged into <code>CDialog::Create</code> and noticed that it fails in <code>::CreateDialogIndirect()</code> which returns <code>NULL</code> and <code>GetLastError</code> returns <code>0</code>. I changed the "No Fail Create" flag to True in the dialog resource properties and I get more details into the error. The problem happens in the dialog's <code>DoDataExchange()</code> within the <code>DDX_Control</code> macro. This calls into the <code>CDataExchange::PrepareCtrl()</code> with the control's resource ID as follows:</p>
  
  <pre><code>HWND CDataExchange::PrepareCtrl(int nIDC)
  {
     ASSERT(nIDC != 0);
     ASSERT(nIDC != -1); // not allowed
     HWND hWndCtrl;
     COleControlSite* pSite = NULL;
     m_pDlgWnd-&gt;GetDlgItem(nIDC, &amp;hWndCtrl);
     if (hWndCtrl == NULL)
     {
        // Could be a windowless OCX
        pSite = m_pDlgWnd-&gt;GetOleControlSite(nIDC);
        if (pSite == NULL)
        {
           TRACE(traceAppMsg, 0, "Error: no data exchange control with ID 0x%04X.\n", nIDC);
           ASSERT(FALSE);
           AfxThrowNotSupportedException();
        }
     }
     m_idLastControl = nIDC;
     m_bEditLastControl = FALSE; // not an edit item by default
  
     return hWndCtrl;
  }
  </code></pre>
  
  <p>The call to the function <code>m_pDlgWnd-&gt;GetOleControlSite()</code> fails for the resource ID passed. By the way, the resource ID is the control's ID. </p>
  
  <p>Any suggestions on why this works inside the EXE and fails in the COM server? </p>