Showing posts with label windev. Show all posts
Showing posts with label windev. Show all posts

Tuesday, May 12, 2015

Bridges connect the world - iOS and Android on Windows 10. What?

Bridge to Astoria, OR. Nov 2014
Photo from our road trip to Portland
At the //build 2015 conference Microsoft announced their development stories for Windows 10. This also includes bridges to reuse existing iOS, Android and other investments for Windows 10.
The keynote showed how an existing iOS game was ported to Windows 10 without much effort. The shown one-stop porting solutions for Android and iOS raised the concern why anyone should bother to develop natively for Windows 10 anymore and created quite some confusion and uncertainty in the Windows developer community. A few developers at //build were really worried about those announcements as some of their business is mainly porting iOS and Android apps to Windows Phone.

I think at the moment there's just too less knowledge to make decisions based on the announcements and assumptions floating around. There were two sessions at //build about Project Astoria for Android and Project Islandwood for iOS. Keep in mind both projects are in a alpha/beta stage and aren't publicly released at the moment so there's no public hands-on experience and independent in-depth analysis available yet. It's also worth noting that Project Astoria allows one to build Windows apps for phones but not for all Universal Windows Platforms at the moment. More information is expected during Summer 2015 and you could also try to sign up for an early access program for Astoria and Islandwood. There's also a good post by my friend Alan from AdDuplex. Peter Bright published a good Ars Technica article as well.

In my opinion there's one particular really good use case:
Share existing business logic across platforms and build the UI natively for the platform.
This way a common cross-platform app core is reused and the UI is built natively on top of that layer to provide the best UX. Porting an app completely might work for games with a custom UI and some simple apps, but advanced apps usually leverage too much platform-specific features for a one-stop port to work at all and a great app adapts to the UX of the platform.
Sharing core business logic is actually a common use case I see with our larger clients who want to bring their existing apps to Windows or Windows Phone. In the projects I've been involved over the last few years, the shared portion was usually implemented in C/C++ as it is still one of the best cross-platform options since most platforms support C/C++ in some way. Right now it is still quite an effort to get the custom C/C++ libs from other platforms adapted for Windows Phone compilation/linking, even with elevated API access rights. The cross-platform C++ Clang support in Visual Studio 2015 allows us to just recompile the Android or iOS C/C++ code and could help us a lot for such scenarios.
After writing this blog post I came across this excellent post by the Visual C++ team which describes just that. And this post which provides more details about the Visual Studio 2015 cross-platform C++ features.

As I see it, Xamarin will be the best choice for green field cross-platform projects to share as much code as possible and still provide the best UX. The new Visual Studio 2015 tooling for Windows 10 could help to make the reuse of existing iOS and Android business logic easier for Windows 10 when there's not a desire for a green field.

On the last day of //build I had a nice breakfast and roundtable with an executive of the Windows Dev Platform and of course we talked about the //build announcements. There was actually the same vision about the easier reuse of business logic. I think we made it clear that quite some confusion was created in the dev community around Islandwood, Astoria but we were told Microsoft will release more information to make the vision for those porting tools clearer.

In the end I think there's no need to be worried. Porting tools have never been a one-stop solution so I'm confident Islandwood and Astoria won't be the holy grail either. As usual a keynote also contains a good portion of marketing and software development is never that easy, so always consume such announcements with a grain of salt and wait for final decisions until the expected is delivered for real-world scenarios.
If those tools help us to make the porting of existing iOS and Android apps easier and the Store provides the apps which users are looking for, it's good for all Windows developers in the end.
It's just a matter of adapting to leverage the new tooling and helping clients to create great apps.

Don't Worry, Be Happy!

Thursday, September 25, 2014

Matrix of the Universe - Matrix3DEx now available for Universal Apps

Do you know about the semi-3D features of XAML and the UIElement Projection available in WinRT and Silverlight? I know many aren't aware of this feature which enables actually pretty nice semi-3D experiences just with XAML. To make the handling easier, I created the Matrix3DEx open source project a few years ago which provides helper methods and samples.

It's better described in action than with words, so you should try the live Silverlight sample which is now also available for WinRT.
There were also some cool games developed using Matrix3DEx: Cubemania is a great and highly addictive rigid body physics game and Go Go Racer! is a nice 2.5D retro racing game.


The Matrix3DEx library is now available for WinRT including Universal Apps, Windows Phone Silverlight and goo old Web Silverlight.
You can download the binaries here.
As usual all samples and the source code can be found in the repository.

The Matrix3DEx project description from the CodePlex site:
The Matrix3DEx library is a collection of extension and factory methods for the Matrix3D struct. It's available for Windows WinRT including Universal Apps, Silverlight and Windows Phone Silverlight. The Matrix3D struct represents a 4x4 matrix that is used in combination with the Matrix3DProjection to apply more complex semi-3D scenarios to any UIElement than are possible with the simple PlaneProjection. This makes it possible to apply arbitrary model transformation matrices and perspective matrices to Silverlight elements.
The Matrix3D struct is very minimalistic and has only a few members. The Matrix3DEx library tries to compensate that with extension and factory methods for common transformation matrices that are easy to use like built in methods.

Friday, April 4, 2014

Content for the Modern Camera and Imaging Apps Build 2014 Session

I had a chance to give a presentation at Microsoft's largest developer conference //build 2014 about the great new capturing APIs. The session Modern Camera and Imaging Apps was given together with Jeff Day who's the Windows Camera API lead PM.

The session was recorded and available at Channel 9.

The slides can also be viewed / downloaded here.
The source code of the demos is available here.

Friday, January 31, 2014

No Biggie - How to Query the Available Storage Size in WinRT

Tape drive photo by P. Hollenback
The Windows Runtime (WinRT) provides a nice file IO API called Windows.Storage. Part of it are atomic operations to create files and folders, etc. It also has a KnownFolders class with static references to different library folders like documents, videos, photos, plus RemovableDevices. Additionally does ApplicationData.Current provide references to the app's temporary, local and roaming folder.
Unfortunately there's no built-in way to check for the available free storage size / free disk space at those locations, although there are scenarios where that information can be essential, especially when dealing with removable devices. But no worries, the good old Win32 has it covered with the GetFreeDiskSpaceEx  function and it can be used with Windows 8 and Windows Phone 8. In order to use it from managed code it just has to be called through P/Invoke or wrapped in a WinRT component which I prefer nowadays, therefore this post provides a short WinRT C++/Cx snippet.

I assume you know how to create a custom C++/Cx WinRT component with Visual Studio, if not go back to my previous blog post which shows just that.


How it works

  1. Open the generated precompiled header file pch.h of your WinRT component's Visual Studio project and add an include for windows.h:
    // pch.h - Header for standard system include files.
    #pragma once
    
    #include <windows.h>

  2. Open the header file of your component and add the method declaration of GetAvailableBytes to your WinRT component which will internally use the GetFreeDiskSpaceEx, but only takes a path as string parameter and returns a WinRT uint64 (unsigned long) type with the available free space in bytes.
    namespace MyNativeStuff
    {
        public ref class MyStorageExtensions sealed
        {
        public:
            uint64 GetAvailableBytes(Platform::String^ path);
        };
    }

  3. Add the method implementation in the source file of the component (.cpp).
    The GetDiskFreeSpaceEx function takes a pointer to an ULARGE_INTEGER which is an union from ancient times when compilers didn't support 64 bit types. Our method then returns the filled unsigned long QuadPart of it.
    #include "pch.h"
    #include "MyNativeStuff.h"
    
    using namespace MyNativeStuff;
    using namespace Platform;
    
    uint64 MyStorageExtensions::GetAvailableBytes(Platform::String^ path)
    {
        ULARGE_INTEGER availableBytesToCaller;
        availableBytesToCaller.QuadPart = 0;
    
        GetDiskFreeSpaceEx(path->Data(), &availableBytesToCaller, NULL, NULL);
    
        return availableBytesToCaller.QuadPart;
    }

  4. You are now ready to use the component in your managed C# code.
    var myNativeComponent = new MyNativeStuff.MyStorageExtensions();
    
    // Create a folder in temp folder of the app and check the available free space
    var myTempFolder = await ApplicationData.Current.TemporaryFolder.CreateFolderAsync("test", CreationCollisionOption.OpenIfExists);
    var availableSpaceTempFolder = myNativeComponent.GetAvailableBytes(myTempFolder.Path);
    
    // Create a folder in videos lib and check the available free space
    var myVideoFolder = await KnownFolders.VideosLibrary.CreateFolderAsync("test", 
    CreationCollisionOption.OpenIfExists);
    var availableSpaceVideoLib = myNativeComponent.GetAvailableBytes(myVideoFolder.Path);

Note, the GetFreeDiskSpaceEx works with any directory path the calling code is allowed to access.