Author Archives: sridharpoduri

How To: Use XAML and DirectX with C++ and create a compelling Windows Store app

One of the great benefits of using C++ to write Windows Store apps is the ability to mix and match various components and create compelling user experiences. There are a variety of apps that use XAML and DirectX together and have built delightful user experiences. For example, there is the FreshPaint app in the Windows Store that allows free form panting using touch or the OneNote app which allows for, as you know, note taking using a stylus (along with keyboard support).

However, if you want to take a look at code and learn from the experts and masters who have built such apps, there are very few options. One such code base is Project Austin which is a sample built by the C++ team to demonstrate using C++ (and CX) along with XAML and DirectX to build a great note taking app. Today’s post, however, is not about Project Austin. It is about a cool sample built by a colleague and C++ enthusiast, Thomas Petchel. Tom built a cool app named Weathr, which he describes as “3D weather app for Windows 8.1 using C++, DirectX, and XAML“. I cannot agree more. This is the best weather app I have seen in a long time and it shows in the user experience. Tom has also made the sources available for anyone to check out and play with. If you are serious about learning how to build such great experiences in your Windows Store apps, please check out the code. And if you make changes to the code, please ensure you contribute back the changes. This ensures that all the folks get the new stuff!!

I can talk about code and design, but I would leave that out for fellow programmers. The app is not on the Store though. So if you want to get the app, you have to build the sources J

Cheers and Happy Holidays!

-Sridhar

Coming Soon: Updated Code Samples with resumable support

Hello,

I will be posting a revised set of samples from my book, “Modern C++ and Windows Store apps” using the resumable function support available from the C++ November CTP. The impacted samples are the ones which use the WinRT Async APIs in conjunction with PPL tasks.

For more information on resumable functions, see this post on vcblog.

Stay tuned for the sample set.

-Sridhar

Learning C++ /CX with a console app on Windows 8.1

I have previously published a template on the VS Gallery that allows you to build console apps by writing C++ /CX code and not starting with XAML and code generation project default templates that VS ships. The previous blog entry is here and the link to the gallery item is here.

The good news is I have published a new template that allows you to use the Windows 8.1 SDK and winmd files to build command line apps while learning C++ /CX. You can get the template here.

Enjoy coding in C++ /CX!

-Sridhar

 

 

 

The Windows 8.1 PDF API and innovations from the ecosystem

It feels good when you work with a feature team (Dev/Test/PM) and bring a new system to life. In Windows 8.1, I worked with a great team of developers and testers to add a new API family to the Windows Runtime. These are the new PDF APIs for supporting rendering of PDF content in Windows Store apps. The APIs are of two flavors:

  1. pure WinRT APIs that can be accessed from any WinRT-supported language like JavaScript, C#, C++ etc and
  2. a “native” API that can be accessed only from C++.

Watch out for my column in the December edition of the MSDN Magazine that talks a bit more in detail about these APIs and the need to have two flavors.

Anyways, more to the point. When my team was beginning to think about these APIs, one of the underlying aspirations was to enable external partners, developers or anyone who is interested in extending the APIs be allowed to do so. I think the community is taking baby steps in that direction!

One of the first extensions on the APIs is a new PDF XAML control built by the awesome folks at DevExpress. They have built a new control, named as the PDF-Viewer (aptly I think) that allows any XAML app to simply drag-drop a UI control and bind to a PDF document source. It really is that simple. This control is built over the native API that draws Pdf content directly to a DirectX backed drawing surface. Right now head over to the site, download the bits and start playing with them.

This week also marks my movement away from the Windows team. I have moved over the Visual Studio group here in India and will be working on the next big thing. Just don’t ask what it is Smile

-Sridhar

My C++ articles for MSDN Magazine

How does C++ fit in the “all in the cloud” meme we hear non-stop these days? Are C++ developers staring at a scenario where we need to use other languages just to connect to the “cloud” and consume web services? If you are increasingly staring at this scenario and wondering what options exist out there, then I have some great news for you.

The C++ team is investing in a modern C++ based library for connecting C++ to cloud services. This project, called the C++REST SDK (code-named Casablanca) allows a C++ developer write modern C++ code (C++11) and connect their apps to any REST-based cloud service. More details on C++REST SDK are here and you can get the bits here.

If you are interested in learning how to connect C++ applications to the cloud, I have written an article for MSDN Magazine. In the article, published in the August edition of the magazine, I discuss how to upload a file to Dropbox using C++REST SDK and the Dropbox REST-based endpoint. The sample is a Windows desktop application using MFC and illustrates how one can integrate C++REST SDK with little effort in existing codebases that need to communicate to cloud services.

If this excites you, I must say that is not all. The September edition, due shortly, will show how to integrate C++REST SDK in Windows Store applications.

I am currently exploring options to build a Linux based application and will write an article once I am done with it.

So, what is the big deal in all of this? Well, all of the client code that talks to Dropbox in my samples is written using standard C++ and remains exactly as-is across my samples, barring minor changes. Now, is that not exciting enough to dip your toes in C++REST SDK?

Stay tuned for more!

-Sridhar

Targeting Modern C++ and Windows Store apps samples for Windows 8.1 – Part 1 of n

I have previously mentioned that I will not be updating “Modern C++ and Windows Store apps” to have an edition exclusively for Windows 8.1. My reason behind the decision is simple: The concepts and technologies I have introduced in the book continue to be relevant in Windows 8.1 and all of the samples will work on Windows 8.1. Having said that, during Windows 8.1 some WinRT APIs were deprecated and you will see warnings when you compile the samples for Windows 8.1. In this series of blog posts, I will show you how, with little effort and small changes, you can recompile the samples for Windows 8.1.

Note: This is just the first post in a series.

Let us begin with the very first example from the book, the DXBouncingBall sample. When you attempt to open the solution file in Visual Studio 2013, Visual Studio prompts you to retarget the solution for Windows 8.1 as shown in the dialog below. If you choose not to retarget, then you will have to install the Windows 8 development tools in order to build the solution.

For the purpose of this exercise, go ahead and retarget the solution to Windows 8.1 by first clicking on OK in the above dialog and then right click on the project in Solution Explorer and choose Retarget to Windows 8.1 as shown below.

Once you ask Visual Studio to retarget the solution to Windows 8.1, Visual Studio makes the necessary changes and opens the project. Once the project is fully loaded, try building the solution. You should see a series of warning messages indicating the usage of deprecated APIs. The warnings are all listed below.

1>e:\projects\old\dxbouncingball\dxbouncingball\directxpage.xaml.cpp(35): warning C4973: ‘Windows::Graphics::Display::DisplayPropertiesEventHandler’ : marked as deprecated

1> Message: ‘The DisplayProperties type and related event handlers may be altered and or unavailable for releases after Windows 8.1. Instead, use DisplayInformation.’

1> This diagnostic occurred while importing type ‘Windows::Graphics::Display::DisplayPropertiesEventHandler ‘ from assembly ‘Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null’.

1> This diagnostic occurred while importing type ‘Windows::Graphics::Display::DisplayProperties ‘ from assembly ‘Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null’.

1>e:\projects\old\dxbouncingball\dxbouncingball\directxpage.xaml.cpp(35): warning C4973: ‘Windows::Graphics::Display::DisplayProperties::LogicalDpi::get’ : marked as deprecated

1> Message: ‘DisplayProperties may be altered or unavailable for releases after Windows 8.1. Instead, use DisplayInformation.’

1>e:\projects\old\dxbouncingball\dxbouncingball\directxpage.xaml.cpp(41): warning C4973: ‘Windows::Graphics::Display::DisplayPropertiesEventHandler’ : marked as deprecated

1> Message: ‘The DisplayProperties type and related event handlers may be altered and or unavailable for releases after Windows 8.1. Instead, use DisplayInformation.’

1>e:\projects\old\dxbouncingball\dxbouncingball\directxpage.xaml.cpp(41): warning C4973: ‘Windows::Graphics::Display::DisplayProperties::LogicalDpiChanged::add’ : marked as deprecated

1> Message: ‘DisplayProperties may be altered or unavailable for releases after Windows 8.1. Instead, use DisplayInformation.’

1>e:\projects\old\dxbouncingball\dxbouncingball\directxpage.xaml.cpp(44): warning C4973: ‘Windows::Graphics::Display::DisplayPropertiesEventHandler’ : marked as deprecated

1> Message: ‘The DisplayProperties type and related event handlers may be altered and or unavailable for releases after Windows 8.1. Instead, use DisplayInformation.’

1>e:\projects\old\dxbouncingball\dxbouncingball\directxpage.xaml.cpp(44): warning C4973: ‘Windows::Graphics::Display::DisplayProperties::OrientationChanged::add’ : marked as deprecated

1> Message: ‘DisplayProperties may be altered or unavailable for releases after Windows 8.1. Instead, use DisplayInformation.’

1>e:\projects\old\dxbouncingball\dxbouncingball\directxpage.xaml.cpp(47): warning C4973: ‘Windows::Graphics::Display::DisplayPropertiesEventHandler’ : marked as deprecated

1> Message: ‘The DisplayProperties type and related event handlers may be altered and or unavailable for releases after Windows 8.1. Instead, use DisplayInformation.’

1>e:\projects\old\dxbouncingball\dxbouncingball\directxpage.xaml.cpp(47): warning C4973: ‘Windows::Graphics::Display::DisplayProperties::DisplayContentsInvalidated::add’ : marked as deprecated

1> Message: ‘DisplayProperties may be altered or unavailable for releases after Windows 8.1. Instead, use DisplayInformation.’

1>e:\projects\old\dxbouncingball\dxbouncingball\directxpage.xaml.cpp(61): warning C4973: ‘Windows::Graphics::Display::DisplayProperties::LogicalDpi::get’ : marked as deprecated

1> Message: ‘DisplayProperties may be altered or unavailable for releases after Windows 8.1. Instead, use DisplayInformation.’

1>e:\projects\old\dxbouncingball\dxbouncingball\directxbase.cpp(177): warning C4973: ‘Windows::Graphics::Display::DisplayPropertiesEventHandler’ : marked as deprecated

1> Message: ‘The DisplayProperties type and related event handlers may be altered and or unavailable for releases after Windows 8.1. Instead, use DisplayInformation.’

1> This diagnostic occurred while importing type ‘Windows::Graphics::Display::DisplayPropertiesEventHandler ‘ from assembly ‘Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null’.

1> This diagnostic occurred while importing type ‘Windows::Graphics::Display::DisplayProperties ‘ from assembly ‘Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null’.

1>e:\projects\old\dxbouncingball\dxbouncingball\directxbase.cpp(177): warning C4973: ‘Windows::Graphics::Display::DisplayProperties::LogicalDpi::get’ : marked as deprecated

1> Message: ‘DisplayProperties may be altered or unavailable for releases after Windows 8.1. Instead, use DisplayInformation.’

1>e:\projects\old\dxbouncingball\dxbouncingball\directxbase.cpp(184): warning C4973: ‘Windows::Graphics::Display::DisplayProperties::CurrentOrientation::get’ : marked as deprecated

1> Message: ‘DisplayProperties may be altered or unavailable for releases after Windows 8.1. Instead, use DisplayInformation.’

1>e:\projects\old\dxbouncingball\dxbouncingball\directxbase.cpp(214): warning C4973: ‘Windows::Graphics::Display::DisplayProperties::CurrentOrientation::get’ : marked as deprecated

1> Message: ‘DisplayProperties may be altered or unavailable for releases after Windows 8.1. Instead, use DisplayInformation.’

Time for action! If you were to closely observe the warning messages, it should be pretty clear that there is one runtimeclass and some methods/properties/events associated with that particular class that are generating the warnings. That class happens to be the Windows::Graphics::Display::DisplayProperties. I will not go into the finer details of why this class has been deprecated in Windows 8.1 but for a teaser, it has to do with better multi-mon support J. Anyways back to our exercise.

The warning also informs us to use the newer class, DisplayInformation. This is one of the benefits of the great Intellisense support for WinRT apps in Visual Studio. All we need to do now, is replace the usage of DisplayProperties with DisplayInformation. Let’s begin the steps. I am showing you a table of the Windows 8 code and the new Windows 8.1 code to make the illustration easier. Each item in the table corresponds to the warnings in the order they appear.

 

File Name

Line Number in Windows 8 Code

Windows 8 Code

Windows 8.1 Code

DirectXPage.xaml.cpp

35

m_renderer->Initialize(

Window::Current->CoreWindow,

SwapChainPanel,

DisplayProperties::LogicalDpi

);

auto info = DisplayInformation::GetForCurrentView();

 

m_renderer->Initialize(


Window::Current->CoreWindow,

SwapChainPanel,

info->LogicalDpi

);

DirectXPage.xaml.cpp

41

DisplayProperties::LogicalDpiChanged +=


ref
new DisplayPropertiesEventHandler(this, &DirectXPage::OnLogicalDpiChanged);

info->DpiChanged +=


ref
new
TypedEventHandler<DisplayInformation^, Object^>( this, &DirectXPage::OnLogicalDpiChanged );

DirectXPage.xaml.cpp

44

DisplayProperties::OrientationChanged +=


ref
new DisplayPropertiesEventHandler(this, &DirectXPage::OnOrientationChanged);

info->OrientationChanged +=


ref
new
TypedEventHandler<DisplayInformation^, Object^>( this, &DirectXPage::OnOrientationChanged );

DirectXPage.xaml.cpp

47

DisplayProperties::DisplayContentsInvalidated +=


ref
new DisplayPropertiesEventHandler(this, &DirectXPage::OnDisplayContentsInvalidated);

info->DisplayContentsInvalidated +=


ref
new
TypedEventHandler<DisplayInformation^, Object^>( this, &DirectXPage::OnDisplayContentsInvalidated );

DirectXPage.xaml.cpp

61

m_renderer->SetDpi(DisplayProperties::LogicalDpi);

m_renderer->SetDpi( DisplayInformation::GetForCurrentView()->LogicalDpi );

DirectXBase.cpp

177

if (m_dpi != DisplayProperties::LogicalDpi)

{


return;

}

if ( m_dpi != DisplayInformation::GetForCurrentView()->LogicalDpi )

{


return;

}

DirectXBase.cpp

184

m_orientation != DisplayProperties::CurrentOrientation

m_orientation != DisplayInformation::GetForCurrentView()->CurrentOrientation

DirectXBase.cpp

214

m_orientation = DisplayProperties::CurrentOrientation

m_orientation = DisplayInformation::GetForCurrentView()->CurrentOrientation

DirectXPage.xaml.h

41-43

void OnLogicalDpiChanged(Platform::Object^ sender);

void OnOrientationChanged(Platform::Object^ sender);

void OnDisplayContentsInvalidated(Platform::Object^ sender);

void OnLogicalDpiChanged( Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args );

 

void OnOrientationChanged( Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args );

 

void OnDisplayContentsInvalidated( Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args );

 

Change the method signatures appropriately in the DirectXPage.xaml.cpp too and rebuild the solution. It should build clean with no warnings and your app should work on Windows 8.1 without any issues.

Try to resize the application window to different sizes and see how resizing and redrawing are all handled smoothly without having to explicitly write code. Is it not cool to write future proof code? J

 

Have fun!

-Sridhar

Will there be an update for “Modern C++ and Windows Store apps” for Windows 8.1?

With Windows 8.1 now released as a Consumer Preview enabling developers to try out and begin building apps for the new Operating System, I wanted to let folks know if there is an updated version of my book, “Modern C++ and Windows Store apps” under development.

When I began contemplating writing a book about Windows 8, I did not want to just show how to build Windows Store apps using C++ /CX and XAML. That would probably have been a great disservice to C++ developers since it would have restricted the scope of the book to just XAML. Don’t get me wrong. XAML is a great UX framework but I wanted to show how the power and flexibility of C++ and C++ /CX can be used to build a vide variety of apps that could be run both on the Desktop and Modern.

The more I thought about what to talk about in the book, the more my ideas began to crystallize around narrating the “C++ Renaissance” at Microsoft and in the industry. Discussing the “C++ Renaissance” is a vast topic in itself and I had to make a few hard decisions on the list of topics. After multiple deliberations, I ended up discussing the following topics:

  • Show the simplicity of developing Windows Store apps using C++ /CX
  • Important concepts of C++11
  • Introduction to C++ /CX
  • A High level tour of XAML
  • Using C++ /CX to combine XAML and DirectX
  • Advanced GPGPU Programming by using C++AMP in Desktop and Windows Store apps.
      • Under the covers of the Windows Runtime and the Windows Runtime Library (WRL)
      • Introducing the new native unit test support in VS2012.
      • Debugging tips for Windows Store apps
      • Performance tips for using XAML
      • Introduction to Windows Azure Mobile Services
      • A sneak preview of Windows Phone 8 “shared code”.

One of the ideas that I steadfastly took while developing samples and the narration was to focus explaining how C++ developers should be using XAML/DirectX interop techniques to make their apps stand apart from pure XAML or WWA counterparts. XAML/DirectX interop is really the “super pill” that can help C++ developers take full advantage of both the retained mode benefits of XAML and the immediate mode rendering provided by DirectX. When coupled with C++AMP, this has the added advantage of eking out maximum performance from the available hardware for all of your workloads.

With Windows 8.1, while XAML got a host of new controls, using those controls by itself is not an impossible task if you have already worked your way through my book. There simply is no point creating a new version of the book, when the fundamentals have already been discussed. All of the new updates are important but they are not breaking changes or stuff that is hard to incorporate. What is really interesting is the changes to the XAML/DirectX interop types. Does it warrant the creation of a new version of the book to explain 4 new interop types? I don’t think so. It, however, does merit explanation. So, going forward, I will begin posting content about the updated XAML/DirectX interop types. I will also update the samples from my book to show how to move code from Windows 8 to Windows 8.1. I hope that is of more value to readers instead of coming up with a new version of the book. What do you think? Please do let me know.

If you have noticed the topics I discussed in my book, attentive readers must have noticed that I did not discuss any communications or network API in the book. Is it a harbinger for things to come in future? Stay tuned for updates Smile

-Sridhar