编写Windows RT的桌面程序

转载自XDA, 原帖:http://forum.xda-developers.com/showthread.php?t=2096820
From XDA Dev, Credit to no2chem
Here’s a basic guide on how to port, since some people were asking:Prerequisites:Windows 8 (non-RT) development machine

Visual Studio 2012 (Don’t know if express will work, but evaluation editions exist here: http://www.microsoft.com/visualstudio/eng/downloads)

dll-to-lib tool (http://forum.xda-developers.com/show…php?p=36597774)

Part 1: Getting necessary libs:

(1) On your Windows RT device, copy the .dll files in C:\Windows\System32 to some directory on your development machine (We’ll call it C:\rtdev\dlls).

(2) Create a directory on your development machine for the libs (we’ll call it C:\rtdev\libs)

(3) Extract the dll-to-lib to your lib directory

(4) Open powershell (run powershell.exe) and navigate to the libs directory

(5) run the lib script against the dlls (“./dll-to-lib.ps1 C:\rtdev\dlls).

(6) If you’ve never run a powershell script before, you might get a signing error. You can type “Set-ExecutionPolicy Unrestricted” to run the script. Please be aware of the security implications if you choose to do this.

(7) You now have a bunch of libs that tell the linker what functions are available in the DLLs on the Windows RT device. Copy the libs that you need to “C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\arm”. DO NOT OVERWRITE ANY EXISITNG LIBS (repeat: DO NOT OVERWRITE ANY EXISITNG LIBS OR YOU MAY HAVE TO REPAIR/REINSTALL VS) You’ll probably have to change the security permissions if you want to copy to this directory, or copy as an administrator.

Part 2: Fixing the compiler.

The compiler won’t let you build desktop apps due to a configuration setting. Fortunately, some people at stack overflow figured this out:
http://stackoverflow.com/questions/1…al-studio-2012

Basically, edit:
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Platforms\AR M\Microsoft.Cpp.ARM.Common.props

to include:
<WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>
before </PropertyGroup>

Part 3: Building a Win32 Hello World app.

Now that we have the libs out of the way, lets build a basic hello world app.

(1) Start Visual Studio 2012.

(2) Create a new project, select Visual C++ (might be under other languages) and pick Win32 Project.

(3) In the wizard, select “Console Application”, and press “Finish”.

(4) Replace the program body with some text that prints hello world:

#include “stdafx.h”
#include <stdio.h>

int _tmain(int argc, _TCHAR* argv[])
{
printf(“Hello World!”);
return 0;
}

(5) Add the ARM configuration settings in configuration manager. Goto Build>Configuration Manager, and under “Active Solution Platform” click on Win32 and click New. Select “ARM” under “Type or select the new platform”, and press “OK”.

(6) Select the “Release” configuration and build the solution (F6). With some luck, some win32 ARM binaries should appear in the ARM subdirectory of your project.

Part 4: Porting Apps

Now that your compiler works, you can port apps over. Most apps that have a VC++ project should port fine just by adding the ARM configuration.

Some apps will have manually set \MACHINE:x86, in which case you will have to change that in the linker options. Also, ARM doesn’t support no dynamic rebase, so if you get that error, turn of \DYNAMICBASE:NO in the linker options.

A lot of cross-platform apps will use ‘nmake’ or the like. For the most part, these apps can be cross compiled using the VS 2012 ARM Cross Tools – you can find that in your start menu- In Windows 8 just type “ARM” and it should show up.

Also some interesting issues might experience:

You might encounter missing symbols from __imp_XXXX or the like from the linker. If it looks like a Win32 function, you just need to explicitly add the .lib (in project properties under Linker->Input->Additional Dependencies, type the name of the lib, which you need to also copy to the VC\lib\arm directory as above. Some common libs include “gdi32.lib” “shell32.lib” and “ole32.lib”. You can usually find the .lib under the msdn references: for example this entry for GetUserName http://msdn.microsoft.com/en-us/libr…(v=vs.85).aspx tells us we can find GetUserName in Advapi32.lib. Also the A and W suffixes just represent the ANSI and unicode version of these functions.

When compiling big libraries like Qt, you might run into some problem about BLX fixups, since relative jumps on arm are limited (23 bits?) I guess they didn’t create fixup islands in the MSVC compiler, but I found if you set \INCREMENTAL:NO, that should fix the problem most of the time. Otherwise you might have to add an \ORDER file and manually order things. See stack overflow topic for more details:http://stackoverflow.com/questions/1…fixup-overflow

Another serious pitfall.. no in-line assembly support in the MS ARM compiler. So you’ll have to write in your assembly in a .S file and link to it.

…hopefully this helps someone – happy coding!

Related post

  1. NO IMAGE
  2. NO IMAGE

    2012.03.26

    Test
  3. NO IMAGE
  4. NO IMAGE
  5. NO IMAGE
  6. NO IMAGE
  1. 松醤 2013.02.14 4:07下午

    来留个言 踩踩

HTML tag cannot be used in this comment.