none
Using Metro - Win8 SDK to build Desktop style application

    Question

  • Hi,

    I would like to build a Desktop app and use the Near-Field Proximity interfaces to bypass some Metro restriction.

    Is it possible to do it ? What environment do i need to use ? Is there any example showing that ?

    Thanks

    Christophe

    Saturday, October 15, 2011 6:58 PM

Answers

  • You could use COM techniques with the new apis for creating WinRT components -- the RoXXX family. This is a pretty good blog post on this, I was able to get the Xaml application object up and running: http://www.interact-sw.co.uk/iangblog/2011/09/16/real-native-winrt. Make sure you use the RO_INIT_MULTITHREADED param to RoInitialize.

    There is no reason you can't use the new C++/CX syntax however. Here is a classic C++ console project that creates a file with the new WinRT storage api:

    #include "stdafx.h"
    #include <conio.h>

    #using <Windows.Storage.winmd>
    #using <Windows.Storage.Pickers.Provider.winmd>
    #using <Windows.Storage.Search.winmd>
    #using <Windows.Storage.Streams.winmd>

    int main(array<Platform::String^>^ args)
    {
     using namespace Platform;
     using namespace Windows::Foundation;
     using namespace Windows::Storage;
     using namespace Windows::Storage::Streams;

     StorageFolder^ documentsFolder =  KnownFolders::DocumentsLibrary;
            auto fileOperation = documentsFolder->CreateFileAsync("sample.txt", CreationCollisionOption::ReplaceExisting);
     fileOperation->Start();

     _putws(L"Press enter to quit");
     _getch();
     return 0;
    }

    Forgive the 'cheating' on using _getch(), Normally, you'd probably want to use something like a ppl task and .wait() to wait for completion, but I've pared this down to the minimum code to illustrate creating a WinRT component. If you go this route, you'll want the latest ppl header from http://code.msdn.microsoft.com/windowsapps/Windows-8-Asynchronous-08009a0d

    For this to build, you'll need to set the following compiler switches in the the C++ Win32 Console wizard generated project:

    C/C++ / General Settings
        Enable Windows Runtime Extensions (/ZX)
        Additional #Using Directories (/AI) -> set this to "C:\Program Files (x86)\Windows Kits\8.0\Windows Metadata" (modify as per your installation)

    C/C++ / Code Generation
        Disable Minimal Rebuild (/Gm-)  -> this is not compatible with /ZX

    I should point out the #using is only going to work with Windows winmd files in desktop scenarios.

    -Steve

    Wednesday, December 07, 2011 8:47 PM

All replies

  • Hi Christophe,

    Desktop apps should for the most part be able to use WinRT. This is an area where we should have more information moving forward. The Windows Developer Preview was primarily focused on the Metro style app development experience. See this thread for a general perspective of WinRT on the Desktop:

    http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/4e79b002-2361-4911-af49-0a8c47c1411b

     

    In regards to Proximity in particular:

    All of the ProximityDevice APIs should work from desktop apps.

    The PeerFinder will also work for Desktop apps if the app is already running on both devices. It is required that the Desktop app has called SetCurrentProcessExplicitAppUserModelId. App launching scenarios with the PeerFinder are not supported with Desktop apps though.

     

    Thanks,

    David

    Wednesday, October 19, 2011 10:56 PM
  • In regards to Proximity in particular:

    All of the ProximityDevice APIs should work from desktop apps.

    The PeerFinder will also work for Desktop apps if the app is already running on both devices. It is required that the Desktop app has called SetCurrentProcessExplicitAppUserModelId. App launching scenarios with the PeerFinder are not supported with Desktop apps though.

    Hi David,

    So finally is there any way to build a Desktop apps using the Proximity interface ?

    My previous Desktop apps looks to work on Win8 but i would like to upgrade them to use this new interfaces.

     

    Thanks

    Christophe

    Thursday, October 20, 2011 1:43 PM
  • Hi Christophe,

    Desktop apps should for the most part be able to use WinRT. This is an area where we should have more information moving forward. The Windows Developer Preview was primarily focused on the Metro style app development experience. See this thread for a general perspective of WinRT on the Desktop:

    http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/4e79b002-2361-4911-af49-0a8c47c1411b

     

    In regards to Proximity in particular:

    All of the ProximityDevice APIs should work from desktop apps.

    The PeerFinder will also work for Desktop apps if the app is already running on both devices. It is required that the Desktop app has called SetCurrentProcessExplicitAppUserModelId. App launching scenarios with the PeerFinder are not supported with Desktop apps though.

     

    Thanks,

    David


    David

    Would devs need to use straight COM to do this? Or will C++/CX syntax work for non-RT projects too?


    http://blog.voidnish.com
    Thursday, October 20, 2011 2:03 PM
  • The messaging around leveraging WinRT from the desktop is in-work. I'll make sure to post here once the specifics have been released.

     

    I also received an update from the Proximity team on their API:

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.proximity

    All of the ProximityDevice APIs should work from desktop apps.

    The PeerFinder APIs will not work for Desktop apps.

     

    Thanks,

    -David

    Thursday, October 20, 2011 3:26 PM
  • You could use COM techniques with the new apis for creating WinRT components -- the RoXXX family. This is a pretty good blog post on this, I was able to get the Xaml application object up and running: http://www.interact-sw.co.uk/iangblog/2011/09/16/real-native-winrt. Make sure you use the RO_INIT_MULTITHREADED param to RoInitialize.

    There is no reason you can't use the new C++/CX syntax however. Here is a classic C++ console project that creates a file with the new WinRT storage api:

    #include "stdafx.h"
    #include <conio.h>

    #using <Windows.Storage.winmd>
    #using <Windows.Storage.Pickers.Provider.winmd>
    #using <Windows.Storage.Search.winmd>
    #using <Windows.Storage.Streams.winmd>

    int main(array<Platform::String^>^ args)
    {
     using namespace Platform;
     using namespace Windows::Foundation;
     using namespace Windows::Storage;
     using namespace Windows::Storage::Streams;

     StorageFolder^ documentsFolder =  KnownFolders::DocumentsLibrary;
            auto fileOperation = documentsFolder->CreateFileAsync("sample.txt", CreationCollisionOption::ReplaceExisting);
     fileOperation->Start();

     _putws(L"Press enter to quit");
     _getch();
     return 0;
    }

    Forgive the 'cheating' on using _getch(), Normally, you'd probably want to use something like a ppl task and .wait() to wait for completion, but I've pared this down to the minimum code to illustrate creating a WinRT component. If you go this route, you'll want the latest ppl header from http://code.msdn.microsoft.com/windowsapps/Windows-8-Asynchronous-08009a0d

    For this to build, you'll need to set the following compiler switches in the the C++ Win32 Console wizard generated project:

    C/C++ / General Settings
        Enable Windows Runtime Extensions (/ZX)
        Additional #Using Directories (/AI) -> set this to "C:\Program Files (x86)\Windows Kits\8.0\Windows Metadata" (modify as per your installation)

    C/C++ / Code Generation
        Disable Minimal Rebuild (/Gm-)  -> this is not compatible with /ZX

    I should point out the #using is only going to work with Windows winmd files in desktop scenarios.

    -Steve

    Wednesday, December 07, 2011 8:47 PM
  • The ppl task version:

    	using namespace concurrency::preview;
    	
    	StorageFolder^ item = Windows::Storage::KnownFolders::DocumentsLibrary;
    	auto op = item->CreateFileAsync("sample.txt", CreationCollisionOption::ReplaceExisting);
    	task<StorageFile^> createFileTask(op);
    	createFileTask.then([](StorageFile^ sf)
    	{
    		wprintf(L"The file %s was created\n", sf->FileName->Data());
    	}).wait();

    -Steve 

    Thursday, December 08, 2011 2:52 AM