Thursday, April 28, 2011

is there a way to have midl generate each interface in a separate .h ?

I have a bunch of objects that inherit abstracts interfaces generated from an idl file. Each object that use of theses interfaces include the same file interfaces.h which contain all the c++ generated abstract classes that map to the idl interface.

Each time I change anything into interfaces.idl every classes that depend on this have to be rebuild since interfaces.h change. Is there a flag or something to tell midl to generate each abstract class in its own .h ?

From stackoverflow
  • The only way I can think of is to put each interface in its own IDL file, or divide them into multiple IDLs according to rate-of-change.

    Then include (or is it #import -- I forget) these interface IDLs into the main library IDL, which will produce the type library, if you need that.

    Emmanuel Caradec : That's possible but not very easy to do because I integrate typelib inside the application. Adding a separate library for each would be painful. Midl has everything it needs to split the .h, I expected someone give me the magic flag of the magic tool to do it.
    Kim Gräsman : There should still only need to be one type library -- have one master IDL that includes each interface IDL and contains the library block. Does that not work for you?
    Emmanuel Caradec : I should have read more carefully, this is exactly what I needed. Thanks.
  • Here is a sample on how to organize the idl to generate separate .h files and a single typelib. The correct directive is import.

    main.idl

    import "oaidl.idl";
    import "ocidl.idl";
    
    import "frag1.idl";
    import "frag2.idl";
    
    [
        uuid(1BECE2AF-2792-49b9-B133-BBC89C850D6F),
        version(1.0),
        helpstring("Bibliothèque de types")
    ]
    library Library
    {
        importlib("stdole2.tlb");
    
        interface IFrag1;
        interface IFrag2;
    }
    

    frag1.idl

    import "oaidl.idl";
    import "ocidl.idl";
    
    [
        object,
        uuid(9AEB517B-48B9-4628-8DD3-4A0BA8D39BEF),
        dual,
        nonextensible,
        helpstring("Interface IFrag1"),
        pointer_default(unique)
    ]
    interface IFrag1 : IDispatch {
        HRESULT frag1();
    };
    

    frag2.idl

    import "oaidl.idl";
    import "ocidl.idl";
    
    [
        object,
        uuid(D60835D4-E1B1-40fb-B583-A75373EF15BE),
        dual,
        nonextensible,
        helpstring("Interface IFrag2"),
        pointer_default(unique)
    ]
    interface IFrag2 : IDispatch {
        HRESULT frag2();
    };
    

0 comments:

Post a Comment