title: How to use CoCreateInstance in c++
body: <p>I am a COM beginner. I have a DLL file that I register using the <code>regsvr32</code> command. In the COM client, I try to use the <code>CoCreateInstance</code> function, but it doesn't work. This is my code:</p>
  
  <pre><code>IMessageBox *pBox;        
  hr = CoCreateInstance(
            __uuidof(IMessageBox),
            NULL,
            CLSCTX_INPROC_SERVER,
            IID_IUnknown,
            (void **)&amp;pBox
       );
  </code></pre>
  
  <p><code>IMessageBox</code> is the interface which is defined in my DLL file. It implements the <code>IDispatch</code> interface. The result of <code>hr</code> displays the error <code>REGDB_E_CLASSNOTREG</code>. How do I use the <code>CoCreateInstance</code> function?</p>