locked
How to pass Map(Object) to WinRT Component?

    Question

  • C++ code:

    void SendMap(Windows::Foundation::Collections::IMap<Platform::String^, Platform::String^>^);

    Javascript code:

    var map = {"name": "Tony", "Id": "whappy"};
    component.sendMap(map); //here is a type mismatch exception
    After calling sendMap(), there is a type mismatch exception. How can I do? 

    Wednesday, March 28, 2012 8:48 AM

Answers

  • Hi H,

    Here is the information I was able to get for you:

    JavaScript cannot create new implementations of WinRT interfaces.  Your WinRT component will need to expose (or reuse) a concrete class implementing the specific instantiation of IMap that you need, and then JavaScript can construct one of these and fill it up.

    If what you want is an IMap<string, IPropertyValue>, you can use the built-in Windows.Foundation.Collections.PropertySet:

        var ps = new Windows.Foundation.Collections.PropertySet();
        ps['hello'] = 13;
        ps['bye'] = "bye";
        myWinRTFunctionWhichTakesAnIMap(ps);
    
    -Jeff

    Jeff Sanders (MSFT)

    Wednesday, March 28, 2012 3:58 PM
    Moderator

All replies

  • Hi H,

    Here is the information I was able to get for you:

    JavaScript cannot create new implementations of WinRT interfaces.  Your WinRT component will need to expose (or reuse) a concrete class implementing the specific instantiation of IMap that you need, and then JavaScript can construct one of these and fill it up.

    If what you want is an IMap<string, IPropertyValue>, you can use the built-in Windows.Foundation.Collections.PropertySet:

        var ps = new Windows.Foundation.Collections.PropertySet();
        ps['hello'] = 13;
        ps['bye'] = "bye";
        myWinRTFunctionWhichTakesAnIMap(ps);
    
    -Jeff

    Jeff Sanders (MSFT)

    Wednesday, March 28, 2012 3:58 PM
    Moderator
  • Hi Jeff,

        Thank you very much for your help.

    Thursday, March 29, 2012 1:50 AM