title: Expose dll for COM Interop
body: <p>I thought I knew how to do this, but obviously not so I'd appreciate some help!
  I can't get my dll to register so I can instantiate it in a VBS, or elsewhere.</p>
  
  <p>I wrote the following sample class, checked "Make assembly COM Visible", checked "Register for COM Interop", then built it.
  When I try to instantiate it from VBS I get the "Activex component can't create object" error.</p>
  
  <p>This is the class code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace Smurf
  {
      public class Pants
      {
          public string Explode(bool Loud)
          {
              string result;
              if (Loud)
                  result = "BANG";
              else
                  result = "pop";
              return result;
          }
      }
  }
  </code></pre>
  
  <p>...and this is the VBS:</p>
  
  <pre><code>Dim a
  
  Set a = CreateObject("Smurf.Pants")
  
  msgbox("ok")
  </code></pre>
  
  <p>What else do I need to do?</p>
  
  <p>Thanks :)</p>
  
  <p>[edit]</p>
  
  <p>Forgot to mention, after the first failure I tried REGSVR32 and REGASM - no help!</p>
  
  <p>[/edit]</p>
  
  <p>Note that when I try REGSVR32, I get this message:</p>
  
  <p><strong>The Module "C:...\Smurf.dll" was loaded but the entry-point DllRegisterServer was not found.
  Make sure that "C:...\Smurf.dll" is a valid DLL or OCX file and then try again.</strong></p>
  
  <p>How helpful is that??</p>
  
  <p>This is the latest version of the code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Runtime.InteropServices;
  
  namespace Smurf
  {
      [Guid("EAA4976A-45C3-4BC5-BC0B-E474F4C3C83F")]
      public interface IPants
      {
          [DispId(1)]
          string Explode(bool Loud);
      }
  
      [Guid("7BD20046-DF8C-44A6-8F6B-687FAA26FA71"),
          InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
      public interface IPantsEvents
      {
          string Explode(bool Loud);
      }
  
      [ComVisible(true)]
      [Guid("0D53A3E8-E51A-49C7-944E-E72A2064F938"),
          ClassInterface(ClassInterfaceType.None),
          ComSourceInterfaces(typeof(IPantsEvents))]
      public class Pants : IPants
      {
          public Pants() { }
  
          [ComVisible(true)]
          [ComRegisterFunction()]
          public static void DllRegisterServer(string key) { }
          [ComVisible(true)]
          [ComUnregisterFunction()]
          public static void DllUnregisterServer(string key) { }
  
          [ComVisible(true)]
          public string Explode(bool Loud)
          {
              string result;
              if (Loud)
                  result = "BANG";
              else
                  result = "pop";
              return result;
          }
      }
  }
  </code></pre>