locked
get event from c++ component RRS feed

  • Question

  • I have a very long running process that should be able to post an event whenever it has processed an item.

    I would like to register a handler function in JavaScript for that event and the c++ should call the handler with the processed item.

    Is that possible already? In my design I cannot use the .then async API.

     

    Thanks

    Wednesday, January 25, 2012 10:13 PM

Answers

All replies

  • Hi Phil,

    This shows creating a C++ WinRT object that fires an event:

    http://msdn.microsoft.com/en-us/library/windows/apps/hh441569(v=vs.110).aspx

    -Jeff


    Jeff Sanders (MSFT)
    Thursday, January 26, 2012 4:13 PM
    Moderator
  • Thanks Jeff for your swift response.

    This sample is pretty self explanatory. I just wonder where the "someevent" and addEventListener come from.

    nativeObject.addEventListener("someevent", multicast1);

     

    They are not declared in the C++ component. Do all C++ components have the addEventListener method? 

    I see the C++ component hase the someEvent member but how does it relate to "someevent" used in the Script? Is the name used in the script not case sensitive?


    • Edited by phil_ke Thursday, January 26, 2012 5:27 PM
    Thursday, January 26, 2012 5:27 PM
  • Hi Phil,

    Sorry for the delay... I lost you somehow.

    The lowercase event name is a convention inherited from the javascript/HTML world... Ya I know, confusing.  In fact, 'someEvent' will NOT work so you need to go all lowercase.

    addEventListener simply hooks up the event.  Think of it as if the 'Object' has that method on it.  Again, this is part of the HTML world and specified in the DOM Events specification.

    -Jeff


    Jeff Sanders (MSFT)
    Tuesday, January 31, 2012 5:24 PM
    Moderator
  • Thanks Jeff, I think I understood now. I am pretty much at home in HTML and DOM I just wondered how the C++ compiler knows about all this by some magic :) Or I guess its the thin wrapper that is put around the C++ object by the compiler.

     

    Another question that is somewhat related to this: If I would like to use the same C++ component in a Win7 desktop app, could I treat the C++ component as a normal COM object and how would I instantiate it on Win7? I am thinking about code sharing when we want to backport some of the core C++ code from our Metro app to a Win7 desktop client.

    Tuesday, January 31, 2012 6:04 PM
  • Hi Phil,

    I would not expect this code to work on Win7.  We have not publically discussed the desktop usage of WinRT either yet.  I would separate my logic from my interface code.  That would allow for good code re-use. 

    -Jeff


    Jeff Sanders (MSFT)
    Tuesday, January 31, 2012 7:01 PM
    Moderator
  • Hi Jeff,

    thats what I meant. Put the OCR code into a C++ component and provide binding for WinRT so that the component could also be used (as a COM) component in Windows < 8

    Tuesday, January 31, 2012 7:33 PM
  • Hi Phil,

    When you say C++ component I assume you are talking about a Dll.  If so you could include that Dll in your package and load it (the C++ forum has some threads on this I believe).   You should follow up on the C++ forum if you need some more details about how that would work.

    -Jeff


    Jeff Sanders (MSFT)
    Tuesday, January 31, 2012 8:11 PM
    Moderator