Copyright Liu Xia 2012. All Rights Reserved. 1

T n o R i

t s c e r w u u t c e o t i d h c d r

o A

e r n h

T i

t

-

1 t

r n a

I P W Metro & Desktop

R C

i o

g

p

h

y

t

s r

i

g

R

h

e

t

s

L

e

i

u

r

v

X

e

d

i

a

.

METRO_MONITOR_MODE:: 2

0

MMM_DESKTOP 1

2

.

A

l

l

2

METRO_MONITOR_MODE:: MMM_METRO Difference Between Metro & Desktop App

Display Life Cycle Interaction Message loop based GDI or DirectX Managed by system configuration Complex tasks, precise control. paint. (windows service) or manually (windowed application).

No message loop. Pure DirectX Managed by system resource Simple task, touch oriented,

R C

powered graphics. manager. manual free. i o

g

p

h

y

t

s r

i

g

R

h

e

t

s

L

e

i

u

r

v Share & Communication Portablility OS Access

X

e

d

i

a

.

Named pipe, MM file, Socket, etc. x86, x64 Opened 2

0

All the way you want. 1

2

.

A

l

l 16 built-in contracts. (e.g. account x86, x64, ARM Processor Restricted picture provider, autoplay, camera, print)

3 The Windows API Architecture

Metro Style Application Traditional Windows App & (Windows Store Application) Windows Services

HTML, C#, C++ CLI, VB.NET, C++ C++/CX C#, VB.NET, XAML Javascript, CSS, F#, XAML, etc. XAML XAML (Managed) XAML etc. (Managed) C/C++ (Native) HTML, (Native) (Native) Javascript, CSS

R C

(Managed) i o

g

p

h

Windows RT XAML WRL y

t

s r

Framework (Managed) Silverlight i

g

(Native) R

h

e

t

s

L

e

Chakra (JS .NET 4.5 i

u

IE 10 r

v Engine) & CRT, STL,

X (Partial)(Managed) .NET 1,2,3,4 e

d (Layout i MFC, ATL, a

. Chakra & (Managed) Engine) (Native) Boost 2 CLR (Native) 0

Trident 1

2

JS Engine .

A

(Native) l

Windows RT (Native) CLR (Native) l

Windows Sub-system/Win32 (RPC, COM, DCOM, COM+, DirectX, ODBC, WinSock, etc.) (Native)

NT Kernel (Native) 4 Win RT is JUST for Metro App

· Win RT is designed for client metro application. · Win RT is aimed at Metro style client application deployed on Windows 8 / Windows 8 ARM, and possibly Windows Phone 8.

· Win RT is for simple deployment, no shared will be R C

i o

g

p

h

y

t

s r

deployed, nor does inter-process communications. i

g

R

h

e

t

s

L

e

i

u

r

v

X

e

d

i

a

.

2

0

1

2

.

A

l

l

5 Win RT Relies on COM

· Win RT is reinvention of Window API. · The WRL is the first-class library to consume Win RT, however, you can use ATL or any technique that supports COM programming to consume Win RT.

R C

i o

g

p

h

y

t

s r

i

g

R

h

e

t

s

L

e

i

u

r

v

X

e

d

i

a

.

2

0

1

2

.

A

l

l

6 Win RT Restricts Direct Access To Windows sub-system · The safest way to make system call is going through Win RT. · Most traditional Win32 API is not support and only partial of .NET framework 4.5 is supported. · Making system call in a metro application (either using C to make direct call or using P-Invoke under .NET Framework) is ok technically, while

R C

i o

g

p

may cause runtime exception or be prohibited by Windows Store. h

y

t

s r

i

g

R

· Considerable effort may be paid even if you have large native COM h

e

t

s

L

e

i

u codebase. r

v

X

e

d

i

a

· .

Using C++/CX seems like the best way to develop new metro style

2

0

1

application (rapid, portability, efficiency, accuracy, library safe). 2

.

A

l

l

7 Explain

Your Managed Metro Application Your C++/CX application

.NET Framework 1,2,3,4 .NET Framework 4.5 (Partial) WRL (Native)

R C

i o

g

p

CLR (Native) h

y

t

s r

i

g CLR (Native) R

h

e

t

s

L

e

Windows RT (Native) i

u

r

v

X

e

d

i

a

.

2

0

1

2

.

ODBC, DirectX, RPC etc. A

l

l

Windows Sub-system

NT Kernel (Native) 8 Why C++/CX

HSTRING hstring; HRESULT hr; IInspectable *pInspApp; const wchar_t *appClassName = L"Windows.UI.Xaml.Application";

hr = ::RoInitialize(RO_INIT_MULTITHREADED); CHECK_RESULT(hr);

hr = ::WindowsCreateString(appClassName, static_cast(::wcslen(appClassName)), &hstring); CHECK_RESULT(hr);

hr = ::RoActivateInstance(hstring, &pInspApp); R C

i o

g

p

::WindowDeleteString(hstring); h

y

t

CHECK_RESULT(hr); s r

i

g

R

h

e

t

s Windows::UI::Xaml::IApplication *pApplication; L

e

i

u

r

v

hr = pInspApp->QueryInterface(__uuidof(pApplication), reinterpret_cast(&pApplication));

X

e

d pInspApp->Release(); i

a

.

CHECK_RESULT(hr); 2

0

1

2

pApplication->Run(); .

A

CHECK_RESULT(hr); l

l

VS

int main(lang::array^ args) { auto app = ref new App(); 9 app->Application::Run(); } C++/CX is NATIVE

· C++/CX (Native) and C++ CLI (Managed) are almost syntactically the ~same~. · No garbage collector exists. The “ref class” is reference counted. The delete logic is wrapped just like “Visual Basic

6”. R C

i o

g

p

h

y

t

s r

· Inter-reference might exist and cause memory leak. Weak i

g

R

h

e

t

s

L

e

Reference to the rescue. i

u

r

v

X

e

d

i

a

.

2

0

1

2

.

A

l

l · Personally, I think C++/CX is introduced because we cannot use visual basic 6 in Visual Studio 2012 :-).

10 Method Comparision

Code Efficiency

Development Speed

Great

R C

i o

g

p

h

y

t

s r

i

g

R

h

e

t

s

L

e

i

u

r

v

X

Good e

d

i

a

.

2

0

1

2

.

A

l

l

Poor

11

Native C++ (COM) C++/CX CLR/HTML+JS+CSS Cheat Sheet

1. Rapid prototype development. 1. Support early versions of 2. Efficiency is not that critical. Windows OS. 3. Have large CLR codebase. 2. Complex operations, precise control. 2. Used as Windows services. 3. Heavy IPC interactions.

1. Support Windows 8 under

different processors (ARM incl.) R C

C#/HTML+JS+CSS i o

g

2. Portable to Windows Phone 8. p

h

y

t 3. Simple and have rich client s r

i

g

R experience. h

e

t

1. Critical on performance and

s

L

e

i

u

battery efficiency. r

Desktop App v

X 2. Heavy graphics operations (e.g. e

d

i

a

.

Games). 2

0

3. Precise memory management. 1

2

4. Cross compiler code. .

A

l

l

Metro App

C++ or 12 C++/CX References

· Win RT: An Object Orientated Replacement for Win32. http://www.infoq.com/news/2011/09/WinRT- API · An Accurate Windows 8 Platform Architecture Diagram?. http://www.bitcrazed.com/post/2012/01/ 27/An-Accurate-Windows-8-Platform-Architecture-Diagram.aspx · Win8, Metro Apps and Silverlight. http://wildermuth.com/2011/9/20/ Win8_Metro_Apps_and_Silverlight · A bad picture is worth a thousand long discussions. http://dougseven.com/2011/09/15/a-bad-picture- is-worth-a-thousand-long-discussions/

R C

i o

· Windows RT Wikipedia. http://en.wikipedia.org/wiki/Windows_RT g

p

h

y

t

· Windows Runtime Wikipedia. http://en.wikipedia.org/wiki/WinRT s r

i

g

R

h

· Windows Runtime XAML Framework Wikipedia. http://en.wikipedia.org/wiki/ e

t

s

L

e

Windows_Runtime_XAML_Framework i

u

r

v

X · Windows 8 and Windows RT Compatible Logo Usage Guidelines. http://msdn.microsoft.com/en-us/ e

d

i

a

.

library/windows/hardware/jj591630.aspx 2

0

· Windows API reference for Metro style apps. http://msdn.microsoft.com/en-us/library/windows/ 1

2

.

apps/br211377.aspx A

l

l

13 Copyright Liu Xia 2012. All 4

Rights Reserved. 1

A

/ Q