Search code examples
comc++builderidl

Compiling .ridl file


Is there a utility for compiling the .ridl file used by C++Builder, to generate a C header?

As far as I can tell, TLIBIMP can only extract RIDL from TLB, and generate C++ headers from TLB. I do not see an option to generate headers from RIDL.

Using the Microsoft SDK 7.1's "midl.exe" on the .ridl file I get a bunch of errors:

.\MyObject.ridl(114) : error MIDL2072 : inapplicable attribute : [version] [ Parameter 'param1' of Procedure 'func1' ( Interface 'IMyObject' ) ]

Also there are some good warnings:

.\MyObject.ridl(343) : warning MIDL2400 : for oleautomation, optional parameters should be VARIANT or VARIANT * : [optional] [ Parameter 'param2' of Procedure 'func2' ( Interface 'IMyObject' ) ]

which I since learned about, but didn't know when originally defining my interface. It'd be good to have these sort of warnings available when defining an interface in C++Builder.

I'm guessing that .ridl is an extension invented by Embarcadero, and [version] is a tag in that extension. The error specifically refers to the version(1.0) that appears in the header for enums that I defined. (Each use of an enum as function parameter triggers the warning).

(If I fix the errors by removing this excess version tag then it generates headers correctly that I can use in a C program built with C++Builder).


Solution

  • A RIDL file is specific to Embarcadero compilers only. Embarcadero uses RIDL instead of standard IDL, and RIDL is not compatible with MIDL.exe.

    In pre-2009 versions, the IDE edited the TLB file directly, and then linked it as-is into executables. This was error-prone, hard to maintain and edit, and did not lend itself well to VCS systems. So RIDL was created, and TLB files became intermediate files created dynamically during project compiling, like OBJ and RES files.

    There is no tool to create C/C++ source files directly from a RIDL file. However, there is a GenTLB.exe tool to create a TLB file from a RIDL file, and then you can use the TLIBIMP.exe tool to create C/C++ source files from the TLB file.

    Note, however, that the C/C++ source files generated by TLIBIMP.exe are only usable in C++Builder, as they rely on Embarcadero-specific compiler extensions and RTL headers/types. If you want to use the TLB file with other compilers, you will have to use their own TLB import tools/capabilities.