title: How to call a managed DLL from native Visual C++ code in Visual Studio 2008
body: <p>I found an article entitled
  How to call a managed DLL from native Visual C++ code in Visual Studio.NET or in Visual Studio 2005
  It was recommended to me by a colleague because I found a useful C# library that would require quite a lot of work to port to C++ (I estimate 2-3 weeks).</p>
  
  <p>The article is here: <a href="http://support.microsoft.com/kb/828736/en-us" rel="nofollow">http://support.microsoft.com/kb/828736/en-us</a>
  I'm still trying to create the part that exports a function from C# so I can call it from
  C++
  The entire code of main.cs  is</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  //Interface declaration
  public interface ICalculator
  {
     int Add(int Number1, int Number2);
  };
  
  //Interface Implementation
  
  
  public class ManagedClass:ICalculator
  {
      public int Add(int Number1, int Number2)
     {
      return Number1 + Number2;
      }
  }
  </code></pre>
  
  <p>assemblyinfo.cs is this</p>
  
  <pre><code>using System.Reflection;
  using System.Runtime.CompilerServices;
  using System.Runtime.InteropServices;
  
  // General Information about an assembly is controlled through the following 
  // set of attributes. Change these attribute values to modify the information
  // associated with an assembly.
  [assembly: AssemblyTitle("sManagedDLL")]
  [assembly: AssemblyDescription("")]
  [assembly: AssemblyConfiguration("")]
  [assembly: AssemblyCompany("")]
  [assembly: AssemblyProduct("sManagedDLL")]
  [assembly: AssemblyCopyright("Copyright ©  2014")]
  [assembly: AssemblyTrademark("")]
  [assembly: AssemblyCulture("")]
  
  // Setting ComVisible to false makes the types in this assembly not visible 
  // to COM components.  If you need to access a type in this assembly from 
  // COM, set the ComVisible attribute to true on that type.
  [assembly: ComVisible(true)]
  
  // The following GUID is for the ID of the typelib if this project is exposed to COM
  [assembly: Guid("5a30f24d-c60b-49fe-9943-afe862741030")]
  
  // Version information for an assembly consists of the following four values:
  //
  //      Major Version
  //      Minor Version 
  //      Build Number
  //      Revision
  //
  // You can specify all the values or you can default the Build and Revision Numbers 
  // by using the '*' as shown below:
  // [assembly: AssemblyVersion("1.0.*")]
  [assembly: AssemblyVersion("1.0.0.0")]
  [assembly: AssemblyFileVersion("1.0.0.0")]
  [assembly: AssemblyDelaySign(false)]
  </code></pre>
  
  <p>unfortunately, it seems to have at least one error: the project called sManagedDLL suddenly seems to drop its initial "s" when regasm.exe is called.</p>
  
  <p>I'm working with VS 2008 and Windows 7 on a 64 bit machine.</p>
  
  <p>When I tried to call regasm.exe I got a message cannot find sManagedDLL.dll or one of its dependencies. So I launched dependency walker to look at the DLL created. I got the following error messages</p>
  
  <pre><code>Error: Modules with different CPU types were found.
  Warning: At least one delay-load dependency module was not found.
  Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.
  </code></pre>
  
  <p>Do you have any suggestions?</p>