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. Managed C++/CLI
  4. COM event sink

COM event sink

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++dotnetwinformscom
5 Posts 2 Posters 1 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.
  • E Offline
    E Offline
    eero_p
    wrote on last edited by
    #1

    How can one implement a COM event sink with 'Windows Forms Application' with .NET 2005? Found plenty of examples on how to do it using MFC, but no luck witn CLI yet. Anyone solved this tricky operation yet? I managed to implement one solution with 2003-version (it's not using CLR:pure or :safe, but CLR:oldformat), yet a problem exists on how to tell the Forms application the parameters (i.e. how to display the received parameters in controls).

    L 1 Reply Last reply
    0
    • E eero_p

      How can one implement a COM event sink with 'Windows Forms Application' with .NET 2005? Found plenty of examples on how to do it using MFC, but no luck witn CLI yet. Anyone solved this tricky operation yet? I managed to implement one solution with 2003-version (it's not using CLR:pure or :safe, but CLR:oldformat), yet a problem exists on how to tell the Forms application the parameters (i.e. how to display the received parameters in controls).

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

      eero_p wrote:

      with 2003-version (it's not using CLR:pure or :safe, but CLR:oldformat), yet a problem exists on how to tell the Forms application the parameters (i.e. how to display the received parameters in controls).

      I don't understand. Perhaps you could post the relevant code that is problematic along with the compiler errors.

      E 1 Reply Last reply
      0
      • L led mike

        eero_p wrote:

        with 2003-version (it's not using CLR:pure or :safe, but CLR:oldformat), yet a problem exists on how to tell the Forms application the parameters (i.e. how to display the received parameters in controls).

        I don't understand. Perhaps you could post the relevant code that is problematic along with the compiler errors.

        E Offline
        E Offline
        eero_p
        wrote on last edited by
        #3

        No errors, just don't know how can I make the sink object 'see' the main form or its controls. Here's the sink that is created in: public __gc class Form1 : public System::Windows::Forms::Form -style form. Connecting to COM and reveiving an event is no problem, but how do I pass the parameter received in 'OnEvent' into a control on the form? #ifndef __SINKBASE #define __SINKBASE #include #include #import "xxx.dll" named_guids raw_interfaces_only #include "xxx.h" template class SinkBase : public IDispEventSimpleImpl { public: SinkBase() { } // fill in the _ATL_FUNC_INFO structured depending on DISPID virtual HRESULT GetFuncInfoFromId(const IID& iid, DISPID dispidMember, LCID lcid, _ATL_FUNC_INFO& info)=0; }; class MySink : public SinkBase<0, MySink, &DIID__IxxxEvents> { public: MySink() { } BEGIN_SINK_MAP(MySink) SINK_ENTRY_EX(0, DIID__IxxxEvents, 1, OnEvent) END_SINK_MAP() HRESULT GetFuncInfoFromId(const IID& iid, DISPID dispidMember, LCID lcid, _ATL_FUNC_INFO& info) { if (InlineIsEqualGUID(iid, DIID__IxxxEvents)) { info.cc = CC_STDCALL; switch(dispidMember) { case 1: info.vtReturn = VT_I4; info.nParams = 1; info.pVarTypes[0] = VT_BSTR; return S_OK; default: return E_FAIL; } } return E_FAIL; } HRESULT __stdcall OnEvent(BSTR eventString) { return S_OK; } };

        L 1 Reply Last reply
        0
        • E eero_p

          No errors, just don't know how can I make the sink object 'see' the main form or its controls. Here's the sink that is created in: public __gc class Form1 : public System::Windows::Forms::Form -style form. Connecting to COM and reveiving an event is no problem, but how do I pass the parameter received in 'OnEvent' into a control on the form? #ifndef __SINKBASE #define __SINKBASE #include #include #import "xxx.dll" named_guids raw_interfaces_only #include "xxx.h" template class SinkBase : public IDispEventSimpleImpl { public: SinkBase() { } // fill in the _ATL_FUNC_INFO structured depending on DISPID virtual HRESULT GetFuncInfoFromId(const IID& iid, DISPID dispidMember, LCID lcid, _ATL_FUNC_INFO& info)=0; }; class MySink : public SinkBase<0, MySink, &DIID__IxxxEvents> { public: MySink() { } BEGIN_SINK_MAP(MySink) SINK_ENTRY_EX(0, DIID__IxxxEvents, 1, OnEvent) END_SINK_MAP() HRESULT GetFuncInfoFromId(const IID& iid, DISPID dispidMember, LCID lcid, _ATL_FUNC_INFO& info) { if (InlineIsEqualGUID(iid, DIID__IxxxEvents)) { info.cc = CC_STDCALL; switch(dispidMember) { case 1: info.vtReturn = VT_I4; info.nParams = 1; info.pVarTypes[0] = VT_BSTR; return S_OK; default: return E_FAIL; } } return E_FAIL; } HRESULT __stdcall OnEvent(BSTR eventString) { return S_OK; } };

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

          eero_p wrote:

          but how do I pass the parameter received in 'OnEvent' into a control on the form?

          eero_p, your english seems fine but your choice of words is less than optimal in terms of clear communications. "how do I pass the parameter" ? What the heck does that mean. If you want assistance from texting forums you must give clear specific information. We can't see what you see on your monitor. For example that might mean that on your form you have a System::Windows::Forms::TextBox and you want to assign the string value received in eventString to the .Text property of the TextBox. If you had asked that question I would know exactly what you are asking. Also my answer would be that marshaling data from native memory to managed memory is a fundamental aspect of developing with C++/CLI. Therefore if you have not taken the time to study that aspect until you clearly understand it, I strongly suggest you do so now. There are excellent introductory resources both here on CodeProject (Articles) and on MSDN that provide all the C++/CLI information you require.

          E 1 Reply Last reply
          0
          • L led mike

            eero_p wrote:

            but how do I pass the parameter received in 'OnEvent' into a control on the form?

            eero_p, your english seems fine but your choice of words is less than optimal in terms of clear communications. "how do I pass the parameter" ? What the heck does that mean. If you want assistance from texting forums you must give clear specific information. We can't see what you see on your monitor. For example that might mean that on your form you have a System::Windows::Forms::TextBox and you want to assign the string value received in eventString to the .Text property of the TextBox. If you had asked that question I would know exactly what you are asking. Also my answer would be that marshaling data from native memory to managed memory is a fundamental aspect of developing with C++/CLI. Therefore if you have not taken the time to study that aspect until you clearly understand it, I strongly suggest you do so now. There are excellent introductory resources both here on CodeProject (Articles) and on MSDN that provide all the C++/CLI information you require.

            E Offline
            E Offline
            eero_p
            wrote on last edited by
            #5

            Sorry about that. It is sometimes a bit tricky to dig up the correct terms, when you get a new tool in your right hand and task to do in your left. Some sort of guidance on the tool and terminology would be optimal, but unfortunately in this case there were none. Example would have helped a lot. However, you guessed just fine, and that gives me nice keywords to hit into the google search-field. Thanks!

            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