title: Write ActiveX control in C# but use it in MFC
body: <p>The current projects are all written in <strong>VC6</strong> and <strong>VB6</strong>. It has been proved that .Net can write Active X controls for MFC use. So we'd like to write some active x controls using .Net with minimum changes in the legacy code. </p>
  
  <p>Here is the <strong>requirements</strong>:</p>
  
  <ol>
  <li>The Host application (written in VC6) must be able to find and load the active x control from the registered category.</li>
  <li>The active x control must support property pages.</li>
  <li>The active x control must support property persistence.</li>
  </ol>
  
  <p>Here is my <strong>questions</strong>:</p>
  
  <ol>
  <li>Is it possible to write Active X property pages using .Net WinForm Controls? And how to communicate between controls and corresponding properties in C#?</li>
  <li><p>How to register the Active X control under a certain category in C#? The following is a piece of sample code in MFC regarding to control registration.</p>
  
  <pre><code>STDAPI DllRegisterServer(void)
  {
  
  HRESULT hr;  
  
  AFX_MANAGE_STATE(_afxModuleAddrThis);
  
  if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
    return ResultFromScode(SELFREG_E_TYPELIB);
  
  if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
    return ResultFromScode(SELFREG_E_CLASS); 
  
  hr = CreateComponentCategory(CATID_CTRL_CAT, 
       L"XXXX");
  if (FAILED(hr))
    return hr;
  
  hr = RegisterCLSIDInCategory(CATID_CONTROL, 
       CATID_CTRL_CAT);
  if (FAILED(hr))
      return hr; 
  
  return NOERROR;
  }
  </code></pre>
  
  <p>The above registration has 3 steps, <strong>AfxOleRegisterTypeLib</strong>, <strong>CreateComponentCategory</strong> and <strong>RegisterCLSIDInCategory</strong>. How can we implement them in C#?</p></li>
  <li>What is the equivalent way in C# to achieve property persistence?</li>
  </ol>
  
  <p>Thank you in advance for any comments and helps!!!</p>