Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. how to pre-define a com interface in a idl file?

how to pre-define a com interface in a idl file?

Scheduled Pinned Locked Moved COM
helpc++comtutorialquestion
3 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kcynic
    wrote on last edited by
    #1

    There are two interfaces IA and IB, but they reference each other in their method. The problem is, if i declared IA before IB, IA would get a error because IB was unknown to it; if i declared IB before IA, IB would get the same error. I know i can fix this problem by replacing the parameters from IAs and IBs to IUnkown. but i want to know if there is a resolution like C++'s classes pre-defining?

    S 1 Reply Last reply
    0
    • K kcynic

      There are two interfaces IA and IB, but they reference each other in their method. The problem is, if i declared IA before IB, IA would get a error because IB was unknown to it; if i declared IB before IA, IB would get the same error. I know i can fix this problem by replacing the parameters from IAs and IBs to IUnkown. but i want to know if there is a resolution like C++'s classes pre-defining?

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      IDL has forward declaration of interface, just like C/C++ has forward declarations, viz:

      // cccc.idl : IDL source for cccc
      //

      // This file will be processed by the MIDL tool to
      // produce the type library (cccc.tlb) and marshalling code.

      import "oaidl.idl";
      import "ocidl.idl";

      [
      uuid(D39DD965-FC96-4C0A-AA62-CA3F5F117685),
      version(1.0),
      helpstring("cccc 1.0 Type Library")
      ]
      library ccccLib
      {
      interface ITest2;
      [
      object,
      uuid(7CD26371-4A6B-4234-A024-6690A53CA450),
      nonextensible,
      helpstring("Itest Interface"),
      pointer_default(unique)
      ]
      interface Itest : IUnknown
      {
      HRESULT DoSomething([in] ITest2* c);
      };
      [
      object,
      uuid(72a5a7e2-0256-428f-8bb5-42d39096892d),
      nonextensible,
      helpstring("Itest Interface"),
      pointer_default(unique)
      ]
      interface ITest2 : IUnknown
      {
      HRESULT DoSomething([in]Itest* c);
      };
      importlib("stdole2.tlb");
      [
      uuid(F8AAE058-76E9-4F2C-995A-FB5B6565CED6),
      helpstring("test Class")
      ]
      coclass test
      {
      [default] interface Itest;
      interface ITest2;
      };
      };

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

      K 1 Reply Last reply
      0
      • S Stuart Dootson

        IDL has forward declaration of interface, just like C/C++ has forward declarations, viz:

        // cccc.idl : IDL source for cccc
        //

        // This file will be processed by the MIDL tool to
        // produce the type library (cccc.tlb) and marshalling code.

        import "oaidl.idl";
        import "ocidl.idl";

        [
        uuid(D39DD965-FC96-4C0A-AA62-CA3F5F117685),
        version(1.0),
        helpstring("cccc 1.0 Type Library")
        ]
        library ccccLib
        {
        interface ITest2;
        [
        object,
        uuid(7CD26371-4A6B-4234-A024-6690A53CA450),
        nonextensible,
        helpstring("Itest Interface"),
        pointer_default(unique)
        ]
        interface Itest : IUnknown
        {
        HRESULT DoSomething([in] ITest2* c);
        };
        [
        object,
        uuid(72a5a7e2-0256-428f-8bb5-42d39096892d),
        nonextensible,
        helpstring("Itest Interface"),
        pointer_default(unique)
        ]
        interface ITest2 : IUnknown
        {
        HRESULT DoSomething([in]Itest* c);
        };
        importlib("stdole2.tlb");
        [
        uuid(F8AAE058-76E9-4F2C-995A-FB5B6565CED6),
        helpstring("test Class")
        ]
        coclass test
        {
        [default] interface Itest;
        interface ITest2;
        };
        };

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

        K Offline
        K Offline
        kcynic
        wrote on last edited by
        #3

        Thanks for your reply. I have tried this method but fail, because i always use the right idl files generated by atl project wizards, and i failed because i spelt 'Interface IB' other than 'interface IB'.(VS also highlights 'Interface' and 'interface'!). Regards.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups