tags:

views:

989

answers:

6

In C++ program, I am trying to #import TLB of .NET out-of-proc server.

I get errors like:

z:\server.tlh(111) : error C2146: syntax error : missing ';' before identifier 'GetType'

z:\server.tlh(111) : error C2501: '_TypePtr' : missing storage-class or type specifiers

z:\server.tli(74) : error C2143: syntax error : missing ';' before 'tag::id'

z:\server.tli(74) : error C2433: '_TypePtr' : 'inline' not permitted on data declarations

z:\server.tli(74) : error C2501: '_TypePtr' : missing storage-class or type specifiers

z:\server.tli(74) : fatal error C1004: unexpected end of file found

The TLH looks like:

_bstr_t GetToString();
VARIANT_BOOL Equals (const _variant_t & obj);
long GetHashCode();
_TypePtr GetType();
long Open();

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.

Some google research indicates I could #import mscorlib.tlb (or put it in path), but I can't get that to compile either.

Any tips?

+1  A: 

Added no_namespace and raw_interfaces_only to my #import:

#import "server.tlb" no_namespace named_guids

Also using TLBEXP.EXE instead of REGASM.EXE seems to help this issue.

jm
A: 

Also, make sure your C# class doesn't have this attribute:

[ClassInterface(ClassInterfaceType.AutoDual)] <-- Seems to cause errors in C++ with _TypePtr

jm
+1  A: 

more ofenly, when vs complied the com source to a tlb in it will have a hint like this: // #import "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.tlb" you shoud add this to StdAfx.h before #inport youOwn.tlb the the basice property like _Type, _ObjRef will added in you project for the proto type

i think, it will solve you problem.

but the bigger problem is : after everythin done, there be some runtime errors when you call a Ptr in you program

anyone can help?

+1  A: 

It seems that you need to use

[ClassInterface(ClassInterfaceType.None)]

Here is another discussion about the similar problem.

OndrejP_SK
+1  A: 
#import "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.tlb" was the solution for me.

Thank you very much!

ggo