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 send NULL to a IUnknown** parameter when COM object is surrogate hosted

How to send NULL to a IUnknown** parameter when COM object is surrogate hosted

Scheduled Pinned Locked Moved COM
helpcomtutorial
5 Posts 2 Posters 5 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.
  • P Offline
    P Offline
    Per Nilsson
    wrote on last edited by
    #1

    I'm developing a COM object in a dll. The object takes an IUnknown** parameter.

    interface IPasser : IDispatch{
    [id(1), helpstring("method Pass")]
    HRESULT Pass([in]IUnknown* ptr);};

    When using it in-process I can send NULL as parameter, but when I instantiate the com object usign a surrogage usign CLSCTX_LOCAL_SERVER I get an error message 0x800706f4, "A null reference pointer was passed to the stub."

    IPasserPtr obj;
    IUnknown* ptr;hr = obj.CreateInstance (CLSID_Passer, 0, CLSCTX_LOCAL_SERVER);
    hr = obj->raw_Pass (0); // Returns 0x800706f4
    hr = obj->raw_Pass (&ptr); // OK

    This is only a problem when I use double indirection, not when I use an ordinary IUnknown*. Can anyone tell me why this is not allowed and how to change the implementation to be able to send a NULL pointer. /Per

    T 1 Reply Last reply
    0
    • P Per Nilsson

      I'm developing a COM object in a dll. The object takes an IUnknown** parameter.

      interface IPasser : IDispatch{
      [id(1), helpstring("method Pass")]
      HRESULT Pass([in]IUnknown* ptr);};

      When using it in-process I can send NULL as parameter, but when I instantiate the com object usign a surrogage usign CLSCTX_LOCAL_SERVER I get an error message 0x800706f4, "A null reference pointer was passed to the stub."

      IPasserPtr obj;
      IUnknown* ptr;hr = obj.CreateInstance (CLSID_Passer, 0, CLSCTX_LOCAL_SERVER);
      hr = obj->raw_Pass (0); // Returns 0x800706f4
      hr = obj->raw_Pass (&ptr); // OK

      This is only a problem when I use double indirection, not when I use an ordinary IUnknown*. Can anyone tell me why this is not allowed and how to change the implementation to be able to send a NULL pointer. /Per

      T Offline
      T Offline
      tolw
      wrote on last edited by
      #2

      You said it yourself - the raw method expects a pointer to a pointer - that's why passing a NULL results in an invalid argument error code. You need to pass a pointer to a null for this to work (you actually have the solution in your question).

      P 1 Reply Last reply
      0
      • T tolw

        You said it yourself - the raw method expects a pointer to a pointer - that's why passing a NULL results in an invalid argument error code. You need to pass a pointer to a null for this to work (you actually have the solution in your question).

        P Offline
        P Offline
        Per Nilsson
        wrote on last edited by
        #3

        Thanks for the response. To clarify a bit. The parameter is used to return a COM pointer. If the caller don't need the value, it sends NULL. So my implementation has the following construction

        if (ptr != 0) {
        *ptr = something;
        *ptr->AddRef ();
        }

        This i not uncommon in C++ programming, but for some resaon its problematic in COM.

        T 1 Reply Last reply
        0
        • P Per Nilsson

          Thanks for the response. To clarify a bit. The parameter is used to return a COM pointer. If the caller don't need the value, it sends NULL. So my implementation has the following construction

          if (ptr != 0) {
          *ptr = something;
          *ptr->AddRef ();
          }

          This i not uncommon in C++ programming, but for some resaon its problematic in COM.

          T Offline
          T Offline
          tolw
          wrote on last edited by
          #4

          I think this[^] might be the answer you need. Apparently the COM object going out of proc causes a problem if the pointer is null. Try declaring the pointer as unique - read more in the article I linked to.

          modified on Friday, September 3, 2010 3:29 AM

          P 1 Reply Last reply
          0
          • T tolw

            I think this[^] might be the answer you need. Apparently the COM object going out of proc causes a problem if the pointer is null. Try declaring the pointer as unique - read more in the article I linked to.

            modified on Friday, September 3, 2010 3:29 AM

            P Offline
            P Offline
            Per Nilsson
            wrote on last edited by
            #5

            Thanks for a very interesting link. Though, I was not able to reproduce the behavior, even with the code in the article. Even if I put, unique or ptr as attribute to my parameter ([in, string, unique]) I get the same error code. I can pass a IUnknow* with 0 as value, both with unique and ref (which should be impossible), but a wchar_t* cannot be passed, regardless of the unique attribute or not. /Per

            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