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. passing connection points parameters by ref

passing connection points parameters by ref

Scheduled Pinned Locked Moved COM
c++sharepointcomtutorialquestion
9 Posts 3 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.
  • S Offline
    S Offline
    SPENNER
    wrote on last edited by
    #1

    X| Does anyone know the trick to getting a connection point method to pass parameters by reference? Below is an example of a simple event, which should return a short from the client, but the variant varResult always returns empty?!? Any ideas? IDL: [ uuid(48053E7C-D307-40D2-A380-3B9CB25282AB), version(1.0), helpstring("atl_event 1.0 Type Library") ] library ATL_EVENTLib { importlib("stdole32.tlb"); importlib("stdole2.tlb"); [ uuid(224E5ED5-D64E-4556-A785-5ACE0DD8F0B3), helpstring("_IEventTestEvents Interface") ] dispinterface _IEventTestEvents { properties: methods: [id(1), helpstring("method TestEvent")] HRESULT TestEvent([in, out] short* sVar ); }; [ uuid(840EF1AE-F80F-4F71-9802-03DFE6555B19), helpstring("EventTest Class") ] coclass EventTest { [default] interface IEventTest; [default, source] dispinterface _IEventTestEvents; }; }; C++: template class CProxy_IEventTestEvents : public IConnectionPointImpl { //Warning this class may be recreated by the wizard. public: HRESULT Fire_TestEvent(SHORT * sVar) { CComVariant varResult; T* pT = static_cast(this); int nConnectionIndex; CComVariant* pvars = new CComVariant[1]; int nConnections = m_vec.GetSize(); for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++) { pT->Lock(); CComPtr sp = m_vec.GetAt(nConnectionIndex); pT->Unlock(); IDispatch* pDispatch = reinterpret_cast(sp.p); if (pDispatch != NULL) { VariantClear(&varResult); pvars[0] = *sVar; DISPPARAMS disp = { pvars, NULL, 1, 0 }; pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL); } } delete[] pvars; // *sVar = varResult.iVal; return varResult.scode; } }; __scott

    A 1 Reply Last reply
    0
    • S SPENNER

      X| Does anyone know the trick to getting a connection point method to pass parameters by reference? Below is an example of a simple event, which should return a short from the client, but the variant varResult always returns empty?!? Any ideas? IDL: [ uuid(48053E7C-D307-40D2-A380-3B9CB25282AB), version(1.0), helpstring("atl_event 1.0 Type Library") ] library ATL_EVENTLib { importlib("stdole32.tlb"); importlib("stdole2.tlb"); [ uuid(224E5ED5-D64E-4556-A785-5ACE0DD8F0B3), helpstring("_IEventTestEvents Interface") ] dispinterface _IEventTestEvents { properties: methods: [id(1), helpstring("method TestEvent")] HRESULT TestEvent([in, out] short* sVar ); }; [ uuid(840EF1AE-F80F-4F71-9802-03DFE6555B19), helpstring("EventTest Class") ] coclass EventTest { [default] interface IEventTest; [default, source] dispinterface _IEventTestEvents; }; }; C++: template class CProxy_IEventTestEvents : public IConnectionPointImpl { //Warning this class may be recreated by the wizard. public: HRESULT Fire_TestEvent(SHORT * sVar) { CComVariant varResult; T* pT = static_cast(this); int nConnectionIndex; CComVariant* pvars = new CComVariant[1]; int nConnections = m_vec.GetSize(); for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++) { pT->Lock(); CComPtr sp = m_vec.GetAt(nConnectionIndex); pT->Unlock(); IDispatch* pDispatch = reinterpret_cast(sp.p); if (pDispatch != NULL) { VariantClear(&varResult); pvars[0] = *sVar; DISPPARAMS disp = { pvars, NULL, 1, 0 }; pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL); } } delete[] pvars; // *sVar = varResult.iVal; return varResult.scode; } }; __scott

      A Offline
      A Offline
      Anders Molin
      wrote on last edited by
      #2

      SPENNER wrote: [id(1), helpstring("method TestEvent")] HRESULT TestEvent([in, out] short* sVar ); Woops, you can't have out parameters on a connection point event function... If you need a parameter back from the client, you need to implement a callback interface instead of using connection points. - Anders Money talks, but all mine ever says is "Goodbye!"

      S 1 Reply Last reply
      0
      • A Anders Molin

        SPENNER wrote: [id(1), helpstring("method TestEvent")] HRESULT TestEvent([in, out] short* sVar ); Woops, you can't have out parameters on a connection point event function... If you need a parameter back from the client, you need to implement a callback interface instead of using connection points. - Anders Money talks, but all mine ever says is "Goodbye!"

        S Offline
        S Offline
        SPENNER
        wrote on last edited by
        #3

        That's odd... Because, and I know this isn't the best example, but if I create a quick COM object with VB and define an outgoing interface with a byref parameter, it works great. The resulting IDL is below: [id(0x00000001)] void TestEvent( [in] short eventByVal, [in, out] short* eventAsRef, [in, out] VARIANT_BOOL* eventBoolRef); So, I'm thinking there must be a C++/ATL equivalent, but I can't figure it out...I know I could use a call back interface, but using a connection point would make it more straight forward from the client side... Any idea how to get this to work? __scott

        A M 2 Replies Last reply
        0
        • S SPENNER

          That's odd... Because, and I know this isn't the best example, but if I create a quick COM object with VB and define an outgoing interface with a byref parameter, it works great. The resulting IDL is below: [id(0x00000001)] void TestEvent( [in] short eventByVal, [in, out] short* eventAsRef, [in, out] VARIANT_BOOL* eventBoolRef); So, I'm thinking there must be a C++/ATL equivalent, but I can't figure it out...I know I could use a call back interface, but using a connection point would make it more straight forward from the client side... Any idea how to get this to work? __scott

          A Offline
          A Offline
          Anders Molin
          wrote on last edited by
          #4

          SPENNER wrote: Any idea how to get this to work? Nope, not right now. I have the "Inside ATL" book, but I left it at work... I'll try to see if there's a solution in there... (on monday when I get to work...) - Anders Money talks, but all mine ever says is "Goodbye!"

          1 Reply Last reply
          0
          • S SPENNER

            That's odd... Because, and I know this isn't the best example, but if I create a quick COM object with VB and define an outgoing interface with a byref parameter, it works great. The resulting IDL is below: [id(0x00000001)] void TestEvent( [in] short eventByVal, [in, out] short* eventAsRef, [in, out] VARIANT_BOOL* eventBoolRef); So, I'm thinking there must be a C++/ATL equivalent, but I can't figure it out...I know I could use a call back interface, but using a connection point would make it more straight forward from the client side... Any idea how to get this to work? __scott

            M Offline
            M Offline
            Michael P Butler
            wrote on last edited by
            #5

            Are you sure that VB has generated a connnection point and not a custom event handler? Michael :-)

            S 1 Reply Last reply
            0
            • M Michael P Butler

              Are you sure that VB has generated a connnection point and not a custom event handler? Michael :-)

              S Offline
              S Offline
              SPENNER
              wrote on last edited by
              #6

              :confused: That's one of the problems with VB, it's hard to know exactly what's going on. I guess my question should be, how do I create an event function that returns parameters from the client (without using a callback interface)? Anyone have a clue on this one? __scott

              A 1 Reply Last reply
              0
              • S SPENNER

                :confused: That's one of the problems with VB, it's hard to know exactly what's going on. I guess my question should be, how do I create an event function that returns parameters from the client (without using a callback interface)? Anyone have a clue on this one? __scott

                A Offline
                A Offline
                Anders Molin
                wrote on last edited by
                #7

                Why not just use the callback interface. It's easy to make in VC, and easy to use from VB... - Anders Money talks, but all mine ever says is "Goodbye!"

                S 1 Reply Last reply
                0
                • A Anders Molin

                  Why not just use the callback interface. It's easy to make in VC, and easy to use from VB... - Anders Money talks, but all mine ever says is "Goodbye!"

                  S Offline
                  S Offline
                  SPENNER
                  wrote on last edited by
                  #8

                  One of the good things about using connection points is that the client doesn't need to manage the connection to the incoming interface. That is, to connect to the COM server callback interface, the client must pass a reference of itself to the server. Is there a way for the server to determine if the client is still there before calling the callback function? Is there a way for the server to implicitly connect to the client when the client instantiates an object from the server? I'm not sure that made sense...oh well __scott

                  A 1 Reply Last reply
                  0
                  • S SPENNER

                    One of the good things about using connection points is that the client doesn't need to manage the connection to the incoming interface. That is, to connect to the COM server callback interface, the client must pass a reference of itself to the server. Is there a way for the server to determine if the client is still there before calling the callback function? Is there a way for the server to implicitly connect to the client when the client instantiates an object from the server? I'm not sure that made sense...oh well __scott

                    A Offline
                    A Offline
                    Anders Molin
                    wrote on last edited by
                    #9

                    SPENNER wrote: I'm not sure that made sense...oh well I know exactly what you mean. I just don't know of a solution... - Anders Money talks, but all mine ever says is "Goodbye!"

                    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