title: Calling VB DLL from C++
body: <p>I'm a bit mystified as to how to do this.  I have followed instructions on <a href="https://stackoverflow.com/questions/389244/best-way-to-use-a-vb-net-class-library-from-a-c-dll">Best way to use a VB.NET class library from a C++ DLL?</a> but being new to VB I don't know if I've got the VB part right let alone the C++.  If anyone can help me here I'll correct the code below for posterity's sake!</p>
  
  <p>Here they are: VB first; the project is a Class Library, all settings default except that "Register for COM interop" is switched on in the project properties.</p>
  
  <pre class="lang-vb prettyprint-override"><code>Public Class Class1
      Public Sub New()
          'do stuff
      End Sub
  
      Public Sub increment()
          'do stuff
      End Sub
  End Class
  </code></pre>
  
  <p>And here's the C++, it's a console application, with CLR support switched on:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #import "..\ClassLibrary1\bin\Debug\ClassLibrary1.tlb" raw_interfaces_only
  
  using namespace std;
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      cout &lt;&lt; "hello world" &lt;&lt; endl;
      HRESULT hr = CoInitialize(NULL);
      long lResult = 0;
  
      Class1 c1; //compiler fails on this, doesn't know what Class1 is
      c1.increment();
  
      //wait for console key press then exit
      char x;
      cin &gt;&gt; x;
      CoUninitialize();
      return 0;
  }
  </code></pre>
  
  <p>Specific questions:</p>
  
  <ol>
  <li>is the VB correct?  Do I need to add anything like an interface to it?</li>
  <li>Assuming I want to call it over COM not C++/CLI, how do I do that.  (This seems like the logical choice as the client already calls other stuff over COM; however, I'm not sure where to get the IDispatch pointer from, in my other code it's passed to me by the client).  </li>
  <li>If I went the C++/CLI route, when moving up from toy project to actual implementation, that would mean changing my existing C++ code from "no clr support" to "/clr" - is that likely to break it?</li>
  </ol>