Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Using the Windows Runtime from C# and Visual Basic

Download

Right click “Save as…”

Slides (view online)
C#, Visual Basic and the .NET tools have first-class support for the Windows Runtime. Learn about this integration and how to use C# and Visual Basic to write Metro style apps that call the Windows Runtime and how to build libraries that integrate with your Metro style apps using HTML.
For more information, check out these courses on Microsoft Virtual Academy:

Follow the Discussion

  • Ralf HoffmannRalf Hoffmann

    If we plan to have a .Net only UI: Is there any benefit creating RT components instead of using usual class libraries? Or is there e.g. even a performance penalty?

  • jarodjarod

    Ok, so we got a bunch of new assemblies (WinRT) that allow us to do more.

    What do we do if we want our application to not only run on Windows 8 but also on Windows 7/Vista which do not have these assemblies?

  • mumtazmumtaz

    The keywords dynamic and await remind me of my own favorite keyword ... procrastination ;)

  • Sleepy Daddy SoftwareSleepyDaddy​Software Family friendly games, utilities, and apps for Windows Phone 7 and Windows 8.

    If I'm not mistaken, it's been said in the directx and direct3d sessions that directx is not currently exposed to C# through winrt, so the only way to access it is through native C++ code. I'm sure there is a good reason for that (performance), but even given those reasons, shouldn't WinRT have some subset of DirectX exposed through WinRT metadata to C#/VB/JavaScript? As it stands, the only way to create a 3D or non-trivial 2D game using C# is by writing your own abstraction layer in native code and P/Invoking it (or creating a native WinRT component). Xna's availability on Windows Phone has been a major component in the explosion of games on that platform, and I think even C++ developers would benefit from a higher-level abstraction layer than raw DirectX api calls, even if that layer is not Xna specifically. 

  • Enjoyed the talk. I'd love to see more from these presenters together.

  • So we can build C# class libraries and expose them to C++ and JavaScript. Can we then turn around and consume those same class libraries in a .NET application?

  • CaseyCasey

    Testing out the new Windows Runtime system. I am having an issue creating winMD components containing PropertyChanged event handlers. I keep getting a System.TypeLoadException when
    "public event PropertyChangedEventHandler PropertyChanged;"
    is placed within a sealed C# class. Am I missing something? Will it be possible to expose the INotifyPropertyChanged interface in the Windows Runtime Components?

  • watwat

    cbae: of course you can. that's the whole point, once a winrt class is written in C++ or C# or VB, it can be consumed by all 3 languages plus Javascript. The only restriction looks to be, that you cannot build winrt classes in Javascript, only consume them.

  • Harry Pierson [MSFT]harrypierson Harry Pierson [MSFT]

    @Ralf Hoffmann:If you're only targeting managed apps w/ your library, you can continue to build DLLs the way you always have. If you want to project to JS and C++, you have to build WInRT components. When crossing language boundaries, you do have to be mindful of marshaling costs - even for managed code accessing managed WinRT components.

  • Harry Pierson [MSFT]harrypierson Harry Pierson [MSFT]

    @jarod:WinRT is only available on Windows 8. If you want to ship an app for 7 and 8, you'll need to abstract away the WinRT APIs you want to use.

  • Harry Pierson [MSFT]harrypierson Harry Pierson [MSFT]

    @cbae:Yes, you can consume managed WinRT components from C# or VB.

  • Harry Pierson [MSFT]harrypierson Harry Pierson [MSFT]

    @Casey:I'm not an expert on INotifyPropertyChanged. Would you mind asking your question on the "Building Metro style apps with C# or VB" forum? http://social.msdn.microsoft.com/Forums/en-us/winappswithcsharp/threads

  • Harry Pierson [MSFT]harrypierson Harry Pierson [MSFT]

    @SleepyDaddySoftware: Great feedback. Would you mind making a post over on the WIn8 forums (http://forums.dev.windows.com) or on http://connect.microsoft.com/? I want to make sure your feedback gets routed to the right team.

  • Harry Pierson [MSFT]harrypierson Harry Pierson [MSFT]

    @DanSorensen:Glad you liked it! Jesse and I have been working closely for the past 18 months, so it was great to finally get to show the world what we've been doing!

  • barretbarret

    Is there any site to download the source code which been demo ?

  • Harry Pierson [MSFT]harrypierson Harry Pierson [MSFT]

    I blogged a walkthru of the first coding demo here: http://devhawk.net/2011/09/15/using-winrt-from-csharp-build-demo/.

  • lapplapp

    Just thought I'd confirm as well, this was definitely the most entertaining presentation I've seen from //build/.

  • SteveKSteveK

    Can I create a WinRT Extension in C# that P/Invokes out to a native library that is included in my package, assuming I did not write it and does not call any of the verbotten Win32 APIs?

    Example

    C# Metro App calls into WinRT Extension exporting int32 Foo(int32 x, int32 y), which P/Invokes out to bar.dll exporting a C callable int Bar(int x, int, y) function that manipulates both?

    Could I also use custom marshalling?

    The samples provided seem to assume that the person that is creating a WinRT extension has access to the implementation. If a 3rd party supplier provides algorithms, etc that I can only get as a DLL implementation that do not break WinRT extension rules, then I would expect to be able to use it. Right?

  • Harry Pierson [MSFT]harrypierson Harry Pierson [MSFT]

    @SteveK, I just double checked w/ the CLR team on your question. Yes you can build a managed WinRT component that uses p/invoke to access Win32 APIs that are allowable from Metro style apps. The .NET profile for Metro style apps includes DllImporet, MarshalAs, etc.

    as for your 3rd party supplier, so long as that DLL works w/ the Metro .NET profile, then yes your scenario will work. Only the public surface area of your component has to conform to the WinRT type system. Other assemblies you reference aren't part of that surface area by default.

    I would think that is a common scenario - build a managed DLL component as a portable assemblies that can be used in Windows, Windows Phone, maybe even Xbox and then build a WinRT wrapper around it so the component is available to JS and C++ as well.

  • Harry Pierson [MSFT]harrypierson Harry Pierson [MSFT]

    Glad you liked it @lapp!

  • jheldjheld

    Where is the source code? As I was typing this up in Dev11, the await keyword is problematic (complaining that it can only be used when its containing method or lambda expression is marked with the async modifier), I'm not sure if Photo is a control on the Xaml page, and the file object does not contain a method for opening a file asynchronously.

  • SteveKSteveK

    Harry,

    Thanks for the clarification. That helps a lot.

    It appears that the Windows Store Certification Kit end up doing binary analysis of the components in a package. Is that right?

    Otherwise, how would it be able to detect that APIs that are not conformant are being called?

    Also, can I use "unsafe" functions in my C# apps as usual with WinRT?

Remove this comment

Remove this thread

close

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.