Even though this capability does not exist in WinRT directly, it is possible to determine the processor architecture at runtime through the Win32 API, GetNativeSystemInfo. This API is included in the list of Win32 APIs that can be called from Windows Store apps (see the system page specifically). You can call this directly from a C++ app, of course, and from C# or Visual Basic you can use PInvoke as described on this MSDN forum thread.

To use the API from JavaScript, as with any other Win32 API, you’ll need to create a WinRT component wrapper. I show how to do this in Chapter 16 of my book, with the resulting DLL/WinMD being small. The short of it is that within your JavaScript app project, right click the solution in Visual Studio and select Add > New Project… then choose Visual C++ on the left and Windows Runtime Component in the middle. Call it SysInfo for lack of a better name.

In pch.h, add this line:

#include<Windows.h>

In the component’s header (.h) file, define a method like this:

namespace SysInfo
{
    publicrefclassInfosealed
    {
    public:
        Info();
        static Platform::String^ GetProcessorArchitecture();
    };
}

 

Here’s the implementation of the class in the .cpp file:

#include“pch.h”
#include“Info.h”

usingnamespace SysInfo;
usingnamespace Platform;

Info::Info()
{
}

String^ Info::GetProcessorArchitecture(void)
{
    SYSTEM_INFO sysInfo;
    String^ str;

    GetNativeSystemInfo(&sysInfo);

    switch (sysInfo.wProcessorArchitecture)
    {
        casePROCESSOR_ARCHITECTURE_AMD64:
            str = “x64″; //AMD or Intel
break;

        casePROCESSOR_ARCHITECTURE_ARM:
            str = “ARM”;
            break;

casePROCESSOR_ARCHITECTURE_IA64:
            str = “IA64″;
            break;

        casePROCESSOR_ARCHITECTURE_INTEL:
            str = “x86″;
            break;

        default:
            str = “Unknown”;
            break;
    }

return str;
}

 

To use the component from JavaScript, right click the JS project in Visual Studio and select Add Reference…. In that dialog select Solution on the left and the component name in the middle. Then you can use this line and do what you want with the resulting string.

var arch = SysInfo.Info.getProcessorArchitecture();

You could also return numeric codes from the C++ component, of course…your choice.

 


2 Comments

  1. Posted April 9, 2013 at 8:34 pm | Permalink

    This could also be implemented as a property and feel even more natural to call from JavaScript .

    • Posted April 10, 2013 at 4:46 pm | Permalink

      Definitely true…I guess my old C habits still like functions :)

3 Trackbacks

  1. By Determining Process Architecture at Runtime on April 10, 2013 at 10:58 am

    [...] /* 0) { ratingctl00_cphMiddle_cphContent_tr3w45fwwvre_itemRating = result['Rating']; SetCurrentRating('ctl00_cphMiddle_cphContent_tr3w45fwwvre_itemRating_pnlHolder', result['Rating'], "disabled fullStar", "disabled emptyStar", true); if(votesCountctl00_cphMiddle_cphContent_tr3w45fwwvre_itemRating!=null) { votesCountctl00_cphMiddle_cphContent_tr3w45fwwvre_itemRating ++; SetVotesCount('ctl00_cphMiddle_cphContent_tr3w45fwwvre_itemRating_lblUsersRated', '(' + votesCountctl00_cphMiddle_cphContent_tr3w45fwwvre_itemRating + ' votes)'); } SetRatingCookie('r', 'i33651', '1'); } else if (result['Status'] == 1) { alert('The session has expired. Please refresh the page to be able to vote!'); } } /* ]]> */ (0 votes) 0 comments   /   posted by Silverlight Show on Apr 10, 2013 Tags:   windows-8 , winrt , kraig-brockschmidt Read original post at Kraig Brockschmidt's Blog [...]

  2. [...] Determining Process Architecture at Runtime (Kraig Brockschmidt) [...]

  3. By Determining Process Architecture at Runtime | eXtreme Windows Phone Developer News on April 14, 2013 at 2:54 pm

    [...] Read original post at Kraig Brockschmidt’s Blog [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>