Click to See Complete Forum and Search --> : Compiler Error in .tlh file


sohail_k
April 16th, 2004, 01:14 AM
Hi,
I am developing an application in which i am using .tlh file generated from typelibrary of one COM component.
It works fine if i use this file in VC++6.0 application but i get compiler error when i include it in my VC++.Net application.

I have generated it first by using #import "File.Tlb".. which inturn generates "File.tlh and File.tli" files on compilation.

Then i removed #import and used this "File.tlh" in my application as -
#include "File.tlh"

I get Compiler error for File.tlh in VC++.Net saying

error C2143: syntax error : missing ')' before 'constant'

error C2143: syntax error : missing ';' before 'constant'

error C2059: syntax error : ')'

error C2238: unexpected token(s) preceding ';'

etc

Same files works fine when used in VC++6.0 application

Since I havent changed anything in this file I am confused what is the problem....

Being a novice in VC++.net (this is my first App in it)... I am more confused

Help me.

Mr. Tomaszek
April 16th, 2004, 03:44 AM
As I understood you generated .tlh under VC6 and trying to use it under VS.NET. You can not do this. Automatically generated files are compiler specific, and should be used with the same complier.

sohail_k
April 16th, 2004, 10:36 AM
Okay,
I had tried generating the files using VC.Net compiler also but no change in problem. But u are right about -
"Automatically generated files are compiler specific, and should be used with the same complier."

I could suppress that error after using "auto_rename"
#import "File.Tlb" auto_rename

Actually i had got warning coz there was some variable that was used in .tlh file and it was keyword in VC++

once generated the files using this #import statement i could run my application smoothly.

Thanx again

Have a nice day.

NGNeer
May 4th, 2006, 02:03 PM
Hello,

I was having similar problems myself, and your post really helped!
Using the auto_rename tip solved 7 out of 9 compiler errors. The remaining two errors were union type redefinition errors, so I commented those out in the automatically generated .tlh file.

Of course, VS will recreate the file when rebuilding the solution, so it was necessary to remove the .tlh file from the output directory and place it in the project directory, and then remove the #import for the .tlb file and add an #include for the .tlh file. For some reason, the .tli file has to remain in the output directory.

Thanks again!
The NGNeer.

yandra2k
December 7th, 2009, 01:33 AM
Guys problem may not be because of .net, it is about multi threaded compiling if you have more than one independent projects in your solution have have #import *.tlb etc used across these projects.

Visual Studio Menu - Tools/Options/Projects and Solutions/Build and Run/Maximum number of parallel project builds.

The default value of parallel threads is 2 if you change it to 1, your solutions might build propertly but would take more time to compile or use the tip provided by sohail (auto_rename).

It is the new feature added in VS 2005+ not available in VS 6.0