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. C#
  4. IUnknown -> object => null ???

IUnknown -> object => null ???

Scheduled Pinned Locked Moved C#
comcsharpquestion
4 Posts 2 Posters 0 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
    kb boxer
    wrote on last edited by
    #1

    Hi I am having a COM interface method like this:- interface IMain : IUknown { HRESULT GetInterface([in]IID riid, [out, iid_is("riid")]IUnknown **ppInterface); } and importing the idl/tlb to metadata; the above method is translated as follows:- [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] void GetInterface([In] Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppInterface); When i call this from the .NET client like this:- Guid someItfGUID = "6BD5A170-D0DC-4b59-8D86-2651C46CB6CC"; object itfObject = null; iMain.GetInterfacesomeItfGUID, out itfObject); IController ctrlr = itfObject as IController; I see that the itfObject is null even after the call to GetInterface but does not fail on the COM side. Let me know if you get any idea why itfObject is null [why the IUnknown/IController is not transported across]. Thanks Vivek Ragunathan

    Programming is an art, Code is a poem !!!

    L 1 Reply Last reply
    0
    • K kb boxer

      Hi I am having a COM interface method like this:- interface IMain : IUknown { HRESULT GetInterface([in]IID riid, [out, iid_is("riid")]IUnknown **ppInterface); } and importing the idl/tlb to metadata; the above method is translated as follows:- [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] void GetInterface([In] Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppInterface); When i call this from the .NET client like this:- Guid someItfGUID = "6BD5A170-D0DC-4b59-8D86-2651C46CB6CC"; object itfObject = null; iMain.GetInterfacesomeItfGUID, out itfObject); IController ctrlr = itfObject as IController; I see that the itfObject is null even after the call to GetInterface but does not fail on the COM side. Let me know if you get any idea why itfObject is null [why the IUnknown/IController is not transported across]. Thanks Vivek Ragunathan

      Programming is an art, Code is a poem !!!

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Why do you have a method GetInterface in a COM interface? :confused:

      K 1 Reply Last reply
      0
      • L led mike

        Why do you have a method GetInterface in a COM interface? :confused:

        K Offline
        K Offline
        kb boxer
        wrote on last edited by
        #3

        There are various components beside the main component and the main component is responsible for providing access to the other components. Hence a GetInterface.

        Programming is an art, Code is a poem !!!

        L 1 Reply Last reply
        0
        • K kb boxer

          There are various components beside the main component and the main component is responsible for providing access to the other components. Hence a GetInterface.

          Programming is an art, Code is a poem !!!

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          Well that's what IUnknown::QueryInterface is for. I'm confused :confused:

          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