locked
Approach for building a Metro app that uses a C library?

    Question

  • Hello,

    I want to build a metro app that takes advantage of an open source C library. 

    I've looked at both the C++ and C# getting started tutorials and roughly understand those approaches, but I'm not sure where to start when it comes to getting this C library to compile such that it can be invoked in a Metro style app. 

    Can someone help me with a high level approach to getting this working?

    Should I be trying to create a Metro DLL for the C library so that it can be called by C#? Should I use C++ and just include all the files from the library in my project? Should I compile a static library ? 

    I don't have experience with Windows development (I'm coming from iOS/ OS X), so I'm not even sure exactly what I should be searching for to accomplish this.

    I'm comfortable with both C# and C++, as well as C.


    Tuesday, June 19, 2012 1:21 AM

Answers

  • In VS11 RC release, one option is to build your C library (static lib) with "General" -> "Metro Style Support" set to "true". Once you set that, your C libraries (static Lib) can be referenced by the metro app.

    If you would like to consume WinRT types in the C libraries (static lib), you can turn on the /ZW switch by setting C/C++->General->Consume Windows RunTime Extension to "true". Note that, you may get linker warning:

    warning LNK4264: archiving object file compiled with /ZW into a static library; note that when authoring Windows Runtime types it is not recommended to link with a static library that contains Windows Runtime metadata

    The reason for the linker warning is that for static lib we support for WinRT consumption but not authoring. Since linker does not have a way to tell between these two case, the warning will always be given. To turn off the warning, you can pass /IGNORE:4264 to the linker (set it as additional options for the linker tools, if building in the IDE). 

    Li Shao, MSFT  


    Li Shao

    Tuesday, June 19, 2012 4:42 AM

All replies

  • You'll want to watch this - Bringing Existing C++ Code into Metro style apps - http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-789C

    This applies to C code as well. Once you build a Dll that doesn't call any Windows api that are not Metro style compatible then you can just call it's exports directly from C++ Metro style apps. From C#, you'll need to P/Invoke to the Dll exports.

    Tuesday, June 19, 2012 1:38 AM
    Moderator
  • In VS11 RC release, one option is to build your C library (static lib) with "General" -> "Metro Style Support" set to "true". Once you set that, your C libraries (static Lib) can be referenced by the metro app.

    If you would like to consume WinRT types in the C libraries (static lib), you can turn on the /ZW switch by setting C/C++->General->Consume Windows RunTime Extension to "true". Note that, you may get linker warning:

    warning LNK4264: archiving object file compiled with /ZW into a static library; note that when authoring Windows Runtime types it is not recommended to link with a static library that contains Windows Runtime metadata

    The reason for the linker warning is that for static lib we support for WinRT consumption but not authoring. Since linker does not have a way to tell between these two case, the warning will always be given. To turn off the warning, you can pass /IGNORE:4264 to the linker (set it as additional options for the linker tools, if building in the IDE). 

    Li Shao, MSFT  


    Li Shao

    Tuesday, June 19, 2012 4:42 AM