Go to the first, previous, next, last section, table of contents.


Sharing IDL files between MIDL and CamlIDL

The Microsoft software development kit provides a number of IDL files describing various libraries and components. In its current state, "camlidl" cannot exploit those files directly: they use many (often poorly documented) Microsoft IDL features that are not implemented yet in "camlidl"; symmetrically, "camlidl" introduces several new annotations that are not recognized by Microsoft's "midl" compiler. So, significant editing work on the IDL files is required.

The C preprocessor can be used to alleviate the "camlidl"-"midl" incompatibilities: "camlidl" defines the preprocessor symbol "CAMLIDL" when preprocessing its input files, while "midl" does not. Hence, one can bracket incompatible definitions in "#ifdef CAMLIDL ... #else ... #endif". Along these lines, a C preprocessor header file, "camlidlcompat.h", is provided: it uses "#define" to remove "camlidl"-specific attributes when compiling with "midl", and to remove "midl"-specific attributes when compiling with "camlidl". Thus, an IDL file compatible with both "midl" and "camlidl" would look like this:


        #include <camlidlcompat.h>

        #ifndef CAMLIDL
        import "unknwn.idl";    // imports specific to MIDL
        import "oaidl.idl";
        #endif
        import "mymodule.idl";  // imports common to MIDL and CamlIDL

        typedef [abstract,marshal_as(int)] void * ptr;

        ...

        #ifndef CAMLIDL
        [...] library MyTypeLib {
          importlib("stdole32.tlb");
          [...] coclass MyComponent { [default] interface IX; }
        }
        #endif

Notice that since "camlidl" doesn't handle type libraries, the type library part of an "midl" file must be enclosed in "#ifndef CAMLIDL".


Go to the first, previous, next, last section, table of contents.