locked
Porting to Metro - static libs and DLLs

    Question

  • So, I have this C++ Windows app that runs fullscreen "exclusive mode" (in old-timer speak), and it is a great candidate to be made a Metro app.

    The current structure is one project in the solution creates an executable (which I'm going to replace with a DX game style Metro app), and the other projects generate ".lib" files.


    I have three worries:

    - VisualStudio Express 11 doesn't let me create a ".lib" project. (and importing the old solution just goes "uses dotNet 4.0, can't load, please install", and nothing seem to fix that)
    - It doesn't let me create a DLL project either. If I want to use 3rd party DLLs (like, in particular, Intel TBB or IPP), is it at all possible ?
    - I sometimes make use of an out of process COM object  (through a nice an simple OleAutomation style interface), will I have to drop it?

     

    Does anybody have experience creating static libs outside VSe11 and linking them into a metro app, is that the way to go?


    Not sure which parts are new rules and which are limitations of the Preview (ie will be addressed in later versions of VS11, and/or Win8). 

    I guess there is a doc somewhere that I haven't found yet that explains in more details the requirements of a native Metro app. If anybody can point me to it, it would be great.

    (Confused but Excited)

    Wednesday, September 21, 2011 3:35 PM

Answers

  • Hi jmuffat,

    As you rightly guessed some of the issues you mention are rules and some are limitations of the preview :)

    • Visual Studio Express supports only a limited number of templates and the focus is on the newer templates (like XAML app template and WinRT DLL template).  Traditional Lib and DLL template can be found in Visual Studio 11 Developer preview. However we are considering adding them to Express as well.
    • Failure to load existing DLL projects with the dotNet 4.0 message is a bug we know about and will be fixed in future releases.  Meanwhile to unblock yourself you could add the following lines in the project (.vcxproj) file itself.  In the “globals” property group:

    <TargetFrameworkIdentifier>.NETCore</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>

    • Use of classic COM objects is quite restricted in Metro style apps.  The Metro style SDK supports only a limited number of classic COM objects.  Using Windows Runtime API is the prescribed way.
    • Static linking is usually discouraged for Metro style native apps especially if your binaries statically link to C Runtime libraries.  This is because Metro style apps need to go through a special validation to ensure that the binaries contained in your package doesnt call into any non-Metro style API.

    Please let me know if you have any more questions.

    Thanks

    Raman Sharma

    Program Manager, Visual C++

    Thursday, September 22, 2011 5:12 PM

All replies

  • Hi jmuffat,

    As you rightly guessed some of the issues you mention are rules and some are limitations of the preview :)

    • Visual Studio Express supports only a limited number of templates and the focus is on the newer templates (like XAML app template and WinRT DLL template).  Traditional Lib and DLL template can be found in Visual Studio 11 Developer preview. However we are considering adding them to Express as well.
    • Failure to load existing DLL projects with the dotNet 4.0 message is a bug we know about and will be fixed in future releases.  Meanwhile to unblock yourself you could add the following lines in the project (.vcxproj) file itself.  In the “globals” property group:

    <TargetFrameworkIdentifier>.NETCore</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>

    • Use of classic COM objects is quite restricted in Metro style apps.  The Metro style SDK supports only a limited number of classic COM objects.  Using Windows Runtime API is the prescribed way.
    • Static linking is usually discouraged for Metro style native apps especially if your binaries statically link to C Runtime libraries.  This is because Metro style apps need to go through a special validation to ensure that the binaries contained in your package doesnt call into any non-Metro style API.

    Please let me know if you have any more questions.

    Thanks

    Raman Sharma

    Program Manager, Visual C++

    Thursday, September 22, 2011 5:12 PM
  • This is very helpful.  Can you give more specific information on which project types I am able to use in Visual Studio 2011 Developer Preview (not Express Edition) to create C/C++ libraries that would be linked to by a metro style application?  That is, is it acceptable for a metro style application to link statically with a standard C++ static library that is compiled using VC11, as long as it doesn't call any forbidden APIs?
    • Edited by Adam Gross Wednesday, October 5, 2011 6:11 PM
    Wednesday, October 5, 2011 6:02 PM
  • In Visual Studio 2011 Ultimate SKU, you can use Win32 wizards to create static library that can be consumed by Metro style application. However, since these libraries may call into non-metro style app, run time behavior is not guaranteed.

    Li Shao, MSFT


    Li Shao
    Saturday, October 8, 2011 8:34 PM
  • Perhaps that (.net 4.0 bug)  indicates a hole in your quality control testing for VS11.  You should routinely try importing VS6, VS2008, and VS2010 projects.
    • Proposed as answer by Hardi_Liang Monday, April 23, 2012 5:20 AM
    Sunday, October 9, 2011 3:33 PM
  • It was a known issue.  Just that it was discovered too late and too close to the release of this Developer Preview, that a fix was not warranted.  This has been addressed already in our internal builds.

    Thanks

    Raman

    Tuesday, October 11, 2011 5:11 PM
  • Thanks for the answer.  So it sounds like we shouldn't have a Metro style app consume a standard Win32 dll project, even if that dll project doesn't use any blacklisted APIs and the dll is packaged in the metro style app?  I ask because I know that LoadLibrary is blacklisted but LoadPackagedLibrary isn't, but I'm not sure which function Windows would use under the covers when importing a library like this.
    Friday, October 21, 2011 1:53 PM
  • "Static linking is usually discouraged for Metro style native apps especially if your binaries statically link to C Runtime libraries.  This is because Metro style apps need to go through a special validation to ensure that the binaries contained in your package doesnt call into any non-Metro style API. "

     

    Hi, I did a simple test and it looks metro app can't static link to lib file which created in earlier version of visual studio(like 2010), however it succeed linking to static lib created in same VS11 solution.  Does this mean for legacy libraries we have to rebuild it in VS11 in order to reuse for metro apps?  

     

    Error when link to lib file created in VS2010:error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700'


    • Edited by Dong, Yi Tuesday, November 1, 2011 5:17 AM
    Tuesday, November 1, 2011 5:13 AM
  • Hi Adam,

    Actually you should be able to consume a standard Win32 DLL project in your app if this DLL doesn't use any blacklisted APIs.  You can use either LoadLibraryPackage or dynamically link to this DLL using it's import lib.  In both cases it should be fine.

    Thanks

    Raman

    Tuesday, November 1, 2011 4:46 PM
  • I am building a metro style DX/C++ game and would like to have each of the games levels be a separate WinRTComponent DLL project. When the time comes I would like to load another level (.DLL) instantiate all the geometry, textures, sounds, etc stored in the DLL and then make callbacks into the DLL for level-specific AI, etc.

    This scheme works well for me with Flex/Molehill, so I would like to do the same with Metro.

    It would be a nice feature to in the future package new sets of levels togother via XML or some other mechanism and expand the levels the game has (it is a Minigolf game)

    How do you dynamically load a WinRTComponent DLL so that I don't have to create a Reference to it in the main project?

    Any help is appreciated!!


    www.puttnutz.com
    Wednesday, February 1, 2012 4:40 PM