title: Is this .tlh file correct, and if not, then how do I generate the correct one?
body: <p>I am trying to call a .NET 4.0 dll from unmanaged C++ code.</p>
  
  <p>I followed the instructions in <a href="http://www.codeproject.com/Articles/12673/Calling-Managed-NET-C-COM-Objects-from-Unmanaged-C?fid=254999&amp;df=90&amp;mpp=25&amp;noise=3&amp;prof=False&amp;sort=Position&amp;view=Normal&amp;spc=Relaxed&amp;fr=26#xx0xx" rel="nofollow">this Code Project article by Atul Mani.</a></p>
  
  <p>I built the .NET dll, and followed all the steps up to and including registering it  with regasm.</p>
  
  <p>Next, I created an unmanaged C++ project and added this line at the start of the .cpp file:</p>
  
  <pre><code>#import "D:\PathToMyCSharpProject\bin\Debug\com.DeviceServices.tlb" rename ("EOF","adoEOF") no_namespace named_guids raw_interfaces_only
  </code></pre>
  
  <p>When I built the C++ project, a .tlh file was created in D:\MyCPlusPlusProject\Debug.</p>
  
  <p>Next, I added the code suggested by the CodeProject article, which tries to create a pointer to an object from the C# library.</p>
  
  <pre><code>CoInitialize(NULL);   //Initialize all COM Components
  
  // &lt;namespace&gt;::&lt;InterfaceName&gt;
  MyCSharpNamespace::IMyCSharpInterfacePtr pMyCSharpInterfacePtr;
  </code></pre>
  
  <p>"MyCSharpNamespace" is the namespace that I used in the C# project.</p>
  
  <p>When I build the C++ project, I now get a compile error:</p>
  
  <blockquote>
    <p>Error 2   error C2653: 'MyCSharpNamespace' : is not a class or namespace name </p>
  </blockquote>
  
  <p>Also other errors because it doesn't recognise IMyCSharpInterfactPtr.</p>
  
  <p>So, I looked into the .tlh file, and the contents are as follows:</p>
  
  <pre><code>// Created by Microsoft (R) C/C++ Compiler Version 10.00.40219.01 (6478e0c7).
  //
  // MyCPlusPlusProjectPath\debug\com.deviceservices.tlh
  //
  // C++ source equivalent of Win32 type library MyCSharpProjectPath\bin\Debug\com.DeviceServices.tlb
  // compiler-generated file created 05/27/14 at 11:52:16 - DO NOT EDIT!
  
  #pragma once
  #pragma pack(push, 8)
  
  #include &lt;comdef.h&gt;
  
  //
  // Forward references and typedefs
  //
  
  struct __declspec(uuid("961b3c24-98f2-400e-8bea-ab357a18d851"))
  /* LIBID */ __MyCSharpProject;
  
  //
  // Named GUID constants initializations
  //
  
  extern "C" const GUID __declspec(selectany) LIBID_MyCSharpProject =
      {0x961b3c24,0x98f2,0x400e,{0x8b,0xea,0xab,0x35,0x7a,0x18,0xd8,0x51}};
  
  #pragma pack(pop)
  </code></pre>
  
  <p>I searched on the internet to find out what should be in the .tlh file, and found <a href="http://msdn.microsoft.com/en-us/library/8etzzkb6.aspx" rel="nofollow">the #import page at msdn.</a></p>
  
  <p>It says that the contents of the .tlh file should include smart pointer declarations (i.e. IMyCSharpProjectInterfacePtr) and typeinfo declarations, that are not present in my .tlh file.</p>
  
  <p>MyCSharpProject declares a public interface, includes a generated GUID, builds correctly, and all the steps that I followed from the article appeared to be successful.</p>
  
  <p>So, my question is, can someone suggest why these definitions aren't present in my .tlh file that should be there?</p>