<p>In C++ program, I am trying to #import TLB of .NET out-of-proc server.</p>
<p>I get errors like:</p>
<blockquote>
<p>z:\server.tlh(111) : error C2146: syntax error : missing ';' before identifier 'GetType'</p>
<p>z:\server.tlh(111) : error C2501: '_TypePtr' : missing storage-class or type specifiers</p>
<p>z:\server.tli(74) : error C2143: syntax error : missing ';' before 'tag::id'</p>
<p>z:\server.tli(74) : error C2433: '_TypePtr' : 'inline' not permitted on data declarations</p>
<p>z:\server.tli(74) : error C2501: '_TypePtr' : missing storage-class or type specifiers</p>
<p>z:\server.tli(74) : fatal error C1004: unexpected end of file found</p>
</blockquote>
<p>The TLH looks like:</p>
<pre><code>_bstr_t GetToString();
VARIANT_BOOL Equals (const _variant_t &amp; obj);
long GetHashCode();
_TypePtr GetType();
long Open();
</code></pre>
<p>I am not really interested in the having the base object .NET object methods like GetType(), Equals(), etc. But GetType() seems to be causing problems.</p>
<p>Some google research indicates I could <code>#import mscorlib.tlb</code> (or put it in path), but I can't get that to compile either.</p>
<p>Any tips?</p>

[{'answer_id': 12751, 'author': 'jm.', 'author_id': 814, 'author_profile': 'https://Stackoverflow.com/users/814', 'pm_score': 2, 'selected': True, 'text': '<p>Added no_namespace and raw_interfaces_only to my #import:</p>\n\n<pre><code>#import "server.tlb" no_namespace named_guids\n</code></pre>\n\n<p>Also using TLBEXP.EXE instead of REGASM.EXE seems to help this issue.</p>\n'}, {'answer_id': 18376, 'author': 'jm.', 'author_id': 814, 'author_profile': 'https://Stackoverflow.com/users/814', 'pm_score': 0, 'selected': False, 'text': "<p>Also, make sure your C# class doesn't have this attribute:</p>\n\n<p>[ClassInterface(ClassInterfaceType.AutoDual)] &lt;-- Seems to cause errors in C++ with _TypePtr</p>\n"}, {'answer_id': 758927, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Often, when MSVC compile COM source to a <code>TLB</code>, there\'ll be hints left behind like:</p>\n\n<pre><code>#import "C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\mscorlib.tlb"\n</code></pre>\n\n<p>You should add that to <code>stdafx.h</code> before the line</p>\n\n<pre><code>#import "your_own.tlb"\n</code></pre>\n\n<p>After that, basic types like <code>_Type</code>, <code>_ObjRef</code> will be added to your project for the prototypes generated.</p>\n\n<p>I hope that solves your problem.</p>\n\n<p>but the bigger problem is that after everything is done, there might be runtime errors when you call a Ptr in you program</p>\n\n<p>anyone can help?</p>\n'}, {'answer_id': 2071836, 'author': 'OndrejP_SK', 'author_id': 251550, 'author_profile': 'https://Stackoverflow.com/users/251550', 'pm_score': 1, 'selected': False, 'text': '<p>It seems that you need to use </p>\n\n<pre><code>[ClassInterface(ClassInterfaceType.None)]\n</code></pre>\n\n<p>Here is <a href="http://osdir.com/ml/windows.devel.dotnet.cx/2004-05/msg00016.html" rel="nofollow noreferrer">another discussion</a> about the similar problem.</p>\n'}, {'answer_id': 2731679, 'author': 'ggo', 'author_id': 328135, 'author_profile': 'https://Stackoverflow.com/users/328135', 'pm_score': 2, 'selected': False, 'text': '<pre><code>#import "C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\mscorlib.tlb"\n</code></pre>\n\n<p>Was the solution for me.</p>\n'}]
['https://Stackoverflow.com/questions/12716', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/814/']