title: Calling a C# dll from C++ using CoCreateInstance
body: <p>My <strong>ProjectA</strong> a <code>C#</code> class library with one single class : </p>
  
  <pre><code>  namespace myLib
    {
      // Interface declaration.
      [Guid("Some GUID")]
      [InterfaceType(ComInterfaceType.InterfaceIsDual)]
      public interface ICsClass
      {
          [DispId(1)]
          int Add(int Number1, int Number2);
      };
  
      [Guid("Some GUID")]
      [ClassInterface(ClassInterfaceType.None)]
      [ProgId("myLib.CsClas")]       
      public class CsClas : ICsClass
      {
           public int Add(int a, int b)
          {
              return a + b;
          }
      }
  }
  </code></pre>
  
  <p>I have checked <code>Register for com interop</code> using <code>VS2010</code> which generated <code>dll</code> &amp; <code>tlb</code> files for me, Ok until now.</p>
  
  <p>My <strong>ProjectB</strong> a <code>Win32 Dll</code> application with single <code>cpp</code> file:</p>
  
  <pre><code>    #import "MyLib.tlb" raw_interfaces_only
      using namespace MyLib;
  </code></pre>
  
  <p>...............</p>
  
  <pre><code>#ifdef __cplusplus
  extern "C"{
  #endif
      __declspec(dllexport) long Add(int a,int b)
      {
          CoInitialize(NULL); 
          long lResult = 0;       
          // Use Smart pointer
          CComQIPtr &lt;ICsClass&gt; spCoClass;
          if (SUCCEEDED (spCoClass.CoCreateInstance(L"myLib.CsClas")))
          {
              spCoClass-&gt;Add(a,b,&amp;lResult);   
              wprintf(L"The result is %d\n", lResult);
              std::cout &lt;&lt; "#"+lResult &lt;&lt; '\n'; 
          }
          CoUninitialize();
          return lResult;
      }
  #ifdef __cplusplus
  }
  #endif
  </code></pre>
  
  <p>.......</p>
  
  <p>Iam able to compile this Dll and everything looks ok until now.</p>
  
  <p>Question when I use my Win32 Dll &amp; try calling the Add function
  this line :</p>
  
  <pre><code> SUCCEEDED (spCoClass.CoCreateInstance(L"myLib.CsClas"))
  </code></pre>
  
  <p>Never gets passed, What might be the issue, Didnt it resgistered properly?</p>
  
  <p>Kindly assist.</p>