none
WinRT and CLR cannot be used together?

    Question

  • I tired to add .dll compiled with CLR to WinRT DLL project and cannot to do it. The compiler said it's impossible to use CLR and WinRT switches together. Also I cannot add reference from precompiled CLR dll to the project. Also when I trying to found .dll via 'Add reference' the studio doesn't show it ( I can see .winmd file only).

    Also is there a way to add 'classical' C++ dll to Metro project?


    • Edited by _Arthur Monday, September 19, 2011 3:08 PM
    Monday, September 19, 2011 3:08 PM

Answers

All replies

  • Well the WinRT dll project is a native C++ project. So you cannot add a reference to a managed project (which is what the /clr project would be). You may be able to do this though: have a mixed-mode DLL which exports a C++ class that wraps a C++/CLI managed class. Link to this mixed-mode DLL the old fashioned way from the WinRT project, and access the wrapper and thus indirectly the managed code too. I have not tried it out but I don't see why it won't work.

    Note: even if it builds and runs, you may not be able to upload it to the app-store (so that's something to keep in mind).


    http://blog.voidnish.com
    Monday, September 19, 2011 4:07 PM
  • Using managed C++ dll's in a Metro style project is not supported with the developer preview.

    Alex Thaman
    Senior Test Lead
    C++ team


    Monday, September 19, 2011 8:13 PM
  • Thank. Hope it will supported later.
    Tuesday, September 20, 2011 4:47 AM
  • Thank. Hope it will supported later.

    Well while some of these are not officially supported, you may be able to get it working if you keep out the disallowed APIs.
    http://blog.voidnish.com
    Tuesday, September 20, 2011 11:22 AM
  • >> 'Add reference' the studio doesn't show it ( I can see .winmd file only):

    Yes this is the motivating scenario or guideline for re-using or referencing code using WinRT and the language projections.

    You could create your library code in the form of a Visual C# ClassLibrary project, change the output type to generate a winmd. This class library should have atleast a public class which will expose appropriate interface methods. You can then add this winmd file as a reference to your main metro visual C# application. This winmd is now completely reusable in many different projects.

    You could do the same thing with the WinRT Component Dll option under Visual C++ drop down.

    Hope this helps in making things clearer.


    Neeraj Wadhwa SDET II, Runtime Experience(WinRT), Developer Exp. Windows.
    Wednesday, September 21, 2011 4:02 AM
  • Thank you very much! I'll try

    Tried...

    For some reasons I have an error message:

    1>bin\Debug\Atentis.Connection.dll : warning CS1684: Reference to type 'System.ComponentModel.Component' claims it is defined in 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.dll', but it could not be found

    1>bin\Debug\Atentis.Connection.dll : error CS0011: The base class or interface 'System.ComponentModel.Component' in assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' referenced by type 'xxxx.yyyyy.zzzz' could not be resolved

     

    As I see it cannot find System.ComponentModel.Component for some reasons?

     

    • Edited by _Arthur Wednesday, September 21, 2011 6:35 AM
    Wednesday, September 21, 2011 4:37 AM
  • Could you please detail out the exact repro steps ? I could successfully create the winmd and then use it in my metro app by adding as a reference. Thank you.


    Neeraj Wadhwa SDET II, Runtime Experience(WinRT), Developer Exp. Windows.
    Wednesday, September 21, 2011 8:07 AM
  • Yes, I created the winmd project succesfully. And empty project was compiled succesfully.

    Then I need to use .dll written with C# inside. I added it to reference, added 'using' directive to my project. And added the object from this dll.

    And have got this error.

    I mean I cannot compile winmd project now.
    Wednesday, September 21, 2011 8:44 AM
  • The way it would work is: You need to add the winmd as a reference to the other metro app project that will be the final application. I guess you are trying to do the reverse.
    Neeraj Wadhwa SDET II, Runtime Experience(WinRT), Developer Exp. Windows.
    Wednesday, September 21, 2011 5:08 PM
  • I cannot compile library to winmd. See the previous post.

    If I can compile it, then I will add it to Metro app, no problem.

    Wednesday, September 21, 2011 5:25 PM
  • Interesting. It seems to compile fine when I change the output type to winmd in the properties window.

    I also have a class and interface implemented in the project infact.


    Neeraj Wadhwa SDET II, Runtime Experience(WinRT), Developer Exp. Windows.
    Wednesday, September 21, 2011 5:31 PM
  • I can send the code to you to check. It's a very simple winmd project and DLL created with C#. I use this DLL now in active C++ project (in Windows 7) without any problems.
    Wednesday, September 21, 2011 5:38 PM
  • Yes. Please make sure not to share any proprietary code. You could either paste it here or share it on a location of your choice.

    It will be much appreciate if the code snippet is small and easily repro-able.

    Thank you.


    Neeraj Wadhwa SDET II, Runtime Experience(WinRT), Developer Exp. Windows.
    Thursday, September 22, 2011 11:11 PM
  • Neeraj, it includes non-public dll. Please let me know your e-mail, I will send it to you.
    • Edited by _Arthur Friday, September 23, 2011 6:25 AM
    Friday, September 23, 2011 6:16 AM
  • System.ComponentModel.Component is not available for Metro style apps.  See http://msdn.microsoft.com/en-us/library/windows/apps/hh454035(v=VS.85).aspx for the supported types in System.ComponentModel.

    Friday, September 23, 2011 6:25 AM
    Owner
  • Thank you. I see.

    Is it limitation for Developer preview only?

    • Edited by _Arthur Friday, September 23, 2011 6:39 AM
    Friday, September 23, 2011 6:38 AM
  • I would encourage you to use the Feedback tool to request any feature you feel is missing in the Developer Preview.

    Look under "Windows Kits\Software Development Kit\API missing" and provide the scenario you are  needing the missing feature to achieve.

     

    Thanks,

    -David

     

    Friday, October 21, 2011 4:17 PM
    Moderator
  • To answer you question as to whether or not it is support to add native C++ dll to classic metro app. The answer is that you can do that by building the classic dll with property page property "General -> Enable Tailored feature" enabled. However, since some of the classic APIs are not supported in Metro style app. The runtime behavior is not guaranteed.

    Li Shao, MSFT


    Li Shao
    Sunday, October 23, 2011 7:41 PM