locked
Expose native interface on runtime class

    Question

  • Hi,

    I have a Windows Runtime Component written in C++/CX. I want to expose a native interface, containing DirectX/COM types, for other C++ consumers of the component. Is it possible to do that (even if I have to rewrite my component in C++ with WRL)? The idea is to have low-level access for C++ consumers and high-level for the C# consumers.

    My goal is to achieve interface like ISwapChainPanelNative exposed on SwapChainPanel.

    Thanks

    Thursday, May 15, 2014 6:27 PM

Answers

  • Hi,

    I think I found the way to do what I want, although I haven't extensively tested it yet.

    The key point is to create the RuntimeClass and specify RuntimeClassFlags to WinRtClassicComMix.

    • Marked as answer by Nik.Z Thursday, May 22, 2014 8:41 PM
    Friday, May 16, 2014 8:43 PM

All replies

  • Hi,

    You can directly contain the DirectX/COM types or native interface in the windows runtime component. Then you can reuse the codes in your app. For more information about windows runtime component. I recommend you can refer to the link below:

    http://blogs.msdn.com/b/windowsappdev/archive/2012/08/06/building-your-own-windows-runtime-components-to-deliver-great-metro-style-apps.aspx

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, May 16, 2014 6:07 AM
  • Hi,

    Thanks for your reply. However, I'm trying to solve a different problem. I know my runtime component can contain DirectX/COM types, and it does.

    I want to expose access to these (native) types from outside. However, they cannot be exposed through winmd, and that's OK.

    Let's say I have a runtime class Class1, and I want C++ consumers, that use the component as 3rd party library, to have access to a function like this after they Query some interface on Class1 object (like the sample with ISwapChainPanelNative):

    HRESULT DoSomething(IDXGISwapChain *pSwapChain);

    Is it possible to do that.

    Friday, May 16, 2014 7:10 AM
  • Hi,

    Accroding to your description. You implement a natvie interface in windows runtime component and want to consume the windows runtime component in C++ project(like desktop). Am i right?As far as i know, a Windows Runtime Component project is a DLL that can export WinRT types. This means this project produces a metadata file (.WINMD), that can be consumed by Windows  Store app projects (or other Windows Runtime Component projects) in any supported projection language, such as C++, C# and JavaScript. If you want to consumed by other app or Class Library, that is not allowed.

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, May 16, 2014 9:12 AM
  • Hi,

    My goal is to consume the runtime component in Windows Store App implemented in C++ or another Windows Runtime Component implemented in C++/CX or C++ with WRL and have access to native objects exposed (somehow) by the runtime object from the first component.

    I see that this is possible for the SwapChainPanel type, that can be queried for ISwapChainPanelNative, but I don't know how to do that for my runtimeclass.

    Thanks

    • Edited by Nik.Z Friday, May 16, 2014 9:23 AM
    Friday, May 16, 2014 9:18 AM
  • Hi,

    That's possible. Would you see the link i give you:

    http://blogs.msdn.com/b/windowsappdev/archive/2012/08/06/building-your-own-windows-runtime-components-to-deliver-great-metro-style-apps.aspx

    The link define the class exposed to our XAML C# project. And in the class define native interface to expose to C# project.

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, May 16, 2014 9:32 AM
  • Thanks, but I don't think this will work for my case. I don't want to just wrap native types and expose them to C#, I want to also expose some of the native internals of the class to C++ consumers of the library.

    Note that in the example with ISwapChainPanelNative the SetSwapChain method takes "IDXGISwapChain *pSwapChain" which is pointer to COM type that derives from IUnknown and cannot be consumed from C#, but it can be used from C++.

    Thanks

    • Edited by Nik.Z Friday, May 16, 2014 9:43 AM
    Friday, May 16, 2014 9:42 AM
  • Hi,

    You can refer to the sample:

    http://code.msdn.microsoft.com/windowsapps/Creating-a-Windows-Runtime-ed84af9d

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, May 16, 2014 9:52 AM
  • Hi,

    Unfortunately I don't see how this sample can help me with my problem. It does show how to use C++ with WRL but only with IInspectable types. I still can't figure out how implement interface based on IUnknown on runtimeclass.

    Thanks

    Friday, May 16, 2014 12:31 PM
  • Hi,

    Please refer to the link below:

    http://www.codeproject.com/Articles/524086/Implementing-WinRT-Interfaces-Defined-Using-WRL-Cp

    http://www.codeproject.com/Articles/654343/Authoring-and-consuming-classic-COM-components-wit

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, May 16, 2014 2:07 PM
  • Hi,

    Thanks for pointing out these articles. I skimmed through them and they look very similar to what I've already seen on MSDN, namely:

    How to: Create a Classic COM Component Using WRL - http://msdn.microsoft.com/en-us/library/jj822931.aspx

    Walkthrough: Creating a Basic Windows Runtime Component Using WRL - http://msdn.microsoft.com/en-us/library/jj155856.aspx

    I've already tried to mix what I've seen there but without luck. Probably the real question is how to mix Windows Runtime Component with Classic COM using WRL.

    I believe it should be possible given that it looks like that SwapChainPanel can be Queried for ISwapChainPanelNative, and ISwapChainPanelNative derives from IUnknown

    Fig 1: http://msdn.microsoft.com/en-us/library/dn302143(v=vs.85).aspx

    Microsoft::WRL::ComPtr<ISwapChainPanelNative>	m_swapChainNative;
    // ...
    IInspectable* panelInspectable = (IInspectable*) reinterpret_cast<IInspectable*>(swapChainPanel);
    panelInspectable->QueryInterface(__uuidof(ISwapChainPanelNative), (void **)&m_swapChainNative);

    Fig 2: C:\Program Files (x86)\Windows Kits\8.1\Include\um\windows.ui.xaml.media.dxinterop.idl:

    [
        object,
        uuid( F92F19D2-3ADE-45A6-A20C-F6F1EA90554B ),
        local,
        pointer_default(unique)
    ]
    interface ISwapChainPanelNative: IUnknown
    {
        HRESULT SetSwapChain([in, annotation("_In_")] IDXGISwapChain *swapChain);
    }

    Thanks

    • Edited by Nik.Z Friday, May 16, 2014 2:33 PM
    Friday, May 16, 2014 2:31 PM
  • Hi,

    I think I found the way to do what I want, although I haven't extensively tested it yet.

    The key point is to create the RuntimeClass and specify RuntimeClassFlags to WinRtClassicComMix.

    • Marked as answer by Nik.Z Thursday, May 22, 2014 8:41 PM
    Friday, May 16, 2014 8:43 PM