Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.
How to pass anonymous function to an object method implemented by BHO, and ivoke it at a later time?

Answered How to pass anonymous function to an object method implemented by BHO, and ivoke it at a later time?

  • Friday, July 27, 2012 7:28 PM
     
      Has Code
    How to pass anonymous function to an object method implemented by BHO, and ivoke it at a later time, i.e.:

    // javascript
    window.bho.addEventListener('event', function() { alert('test') }, false);

    // c#
    public void addEventListener(String eventName, Object closure, Boolean useCapture)
    {
        ...
        // invoke a function
    }

    I assume we could use sink objects or reflection to get a MethodInfo or Delegate, to store the object passed in the second parameter in a list and then invoke it at a later time... but I couldn't figure out how to do that.

All Replies

  • Saturday, July 28, 2012 1:32 AM
     
     Answered

    The objects are of type IDispatch but you need to invoke via IDispatchEx if the event handler supports that. Otherwise just invoke the IDispatch implementationThe dispid to invoke is 0 (DISPID_VALUE).



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

  • Saturday, July 28, 2012 10:11 AM
     
     

    Thanks a lot,

    Could you demonstrate some example of C# code?

  • Saturday, July 28, 2012 3:38 PM
     
     

    The code to invoke IDispatch is linked above. For invoking IDispatchEx, check https://groups.google.com/d/topic/microsoft.public.dotnet.framework.interop/HkZgGxq8jIQ/discussion

    By the way addEventListener does not sound like it would invoke the function. If you indeed want to invoke the functions in this method, change the method name to be more descriptive about what it does.



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP