Tải bản đầy đủ - 0 (trang)
Chapter 1.  .NET Compact Framework Architecture

Chapter 1.  .NET Compact Framework Architecture

Tải bản đầy đủ - 0trang

Chapter1..NETCompactFramework

Architecture

The.NETCompactFrameworkisaprogramming

interfaceandruntimelibrarycreatedatthenexusof

twoMicrosofttechnologies:(1)WindowsCE,an

operatingsystemformobileandembeddedsmart

devices,and(2).NET,Microsoft'sreinventionofits

programminginterfacesanddevelopertools.This

chaptercoverskeyelementsofWindowsCEandkey

elementsof.NETtoshowhowtheyworktogetherin

version1.0ofthe.NETCompactFramework.

Intheearly1990S,Microsoftdeclaredthattwo

technologieswerecoretoitslong-termstrategicplans:

Win32andCOM.MicrosoftcreatedWin32,the32-bit

WindowsApplicationProgrammingInterface(API),[1]asa

successortoitsthen-dominantWin16API.COM,

Microsoft'sarchitectureforbuildingdistributed

components,wasintroducedasawaytosnaptogether

softwarecomponentsinafashionanalogoustotheway

thatelectronicintegratedcircuitsaresnappedtogether.

[1]AnAPIisaninterfacethatanoperatingsystemprovidesforthedevelopmentof

applicationsoftware.



TheWin32APIwascreatedasanupgradetotheWin16

API,whichprovidedthecoreprogramminginterfacefor

Windowsversion1.x.The16-bitinterfacewasbuiltfor16bitprocessors,andhadtighttiestoMS-DOS(whichwas

requiredforearlyversionsofWindows).TheWin16API

servesasthecoreprogramminginterfaceforthefollowing

versionsofWindows:Windows1.x,2.x,3.x,Windows95,

Windows98,andWindowsMe.



TheWin32APIwasdesignedtoprovideasmooth

migrationfromtheWin16API.Thegoalwastomakeit

easyforadevelopertotakeWin16codeandmodifyitto

runundertheWin32API.TheWin32APIistheprimary

programminginterfaceforthefollowingversionsof

Windows:WindowsNT3.1,WindowsNT3.5,WindowsNT

4.0,Windows2000,WindowsXP,andWindowsServer

2003.Tofurthersmooththepathbetweenthetwo

programminginterfaces,Win32supportwasaddedtothe

16-bitversionsofWindows,startingwithWindows3.1.

ThisallowsasingleWin32programtorunonboth16-bit

and32-bitversionsofWindows.

MicrosoftshippedthefirstversionofWindowsCEin1996,

withtheWin32APIatitscore.WindowsCEwasdesigned

tobeamodular,configurableoperatingsystemthatwas

optimizedformobile,battery-poweredsmartdevices.

Microsoftmadeitpossiblefordeveloperstocustomize

WindowsCEforapplication-specificuses.Incontrast,

desktopversionsofWindowshavealwaysshippedasa

monolithic,noncustomizablesetoflibrariesand

applications.Bycontrast,adevelopercanconfigure

WindowsCEtoincludesupportforadisplayscreenorto

runinaheadlessconfiguration(withnodisplayscreen).In

addition,WindowsCEcanbeconfiguredtouseastandard

keyboard,acustomkeyboard,ornokeyboardatall.

WindowsCEcanalsobeconfiguredtosupportaharddrive

ornotbecausetheonlyrequiredstorageisaRAM-resident

objectstore.

WindowsCEisMicrosoft'sonlyoperatingsystemwith

Win32astheprimaryAPIforbothapplicationdevelopment

anddevicedriverdevelopment.[2]Insomerespects,

WindowsCEwasdevelopedasasmaller,lightweight

versionofMicrosoft's32-bitoperatingsystems—akindof

"WindowsXPLite."ButWindowsCEshareslittleifany

codewiththeheavierdesktopoperatingsystems,having



beenwrittenfromscratchtoaddresstheneedsof

hardwareandsoftwareengineersworkingtodevelop

mobileandembeddedsmartdevices.

[2]Bycontrast,othermembersoftheMicrosoftWindowsoperatingsystemfamilyuse

eitherVxDs(forWindows95,Windows98,andWindowsMe)orakernel-modedriver

interface(forWindowsNT,Windows2000,WindowsXP,andWindowsServer2003)thatis

decidedlynottheWin32API.



OnWindowsCEtoday,Win32isstillavalidoptionfor

applicationdevelopment.Insomecases,Win32provides

theonlywaytoaccomplishsomethings.Real-time

programming,forexample,isbestdoneinWin32because

unexpecteddelayscanoccurinthe.NETCompact

Frameworkruntime.Also,extensionstotheoperating

systemortotheoperatingsystemshellcanbedoneonly

byusingWin32code.Thisincludescontrolpanelapplets,

itemsonthePocketPCTodayscreen,device-side

ActiveSyncproviders,andanykindofdevicedriver.

COMprovidesthebuildingblocksforawiderangeof

components.COMfirstsupportedcompounddocuments

withtheObjectLinkingandEmbedding(OLE)specification.

OLEprovidestheabilitytoembedanobjectsuchasa

spreadsheetorabitmapintoacontainerdocument,such

asawordprocessingdocument.MicrosoftrenamedCOM

toActiveXwhenInternetExplorer,withitssupportfor

ActiveXcontrols,wasintroduced.COM/ActiveX

componentsallowthirdpartiestoaddnewcomponentsin

theformofcontrols,plug-ins,andotherkindsof

extensions.COMcanbeusedtobuildstand-alone

componentsthathavenouserinterfaceelementbut

providesometypeofusefulservice.

COMprovidestheglueforconnectingcomponents.As

such,itaddressessomecriticaldevelopmentissues,

includingcodereuseandprogrammerproductivity.But

COMiscomplexandquirky,requiringbothdevelopersand

consumersofcomponentstohandleadministrativechores



thatwouldbebetterhandledifautomated.Forexample,

COMcomponentsmusttrackconnectionstoexternal

clientswithareferencecount.Althoughsimpleinprinciple,

COMprogramminginpracticerequiresaserious

investmentoftimeandenergytomaster.

COMwasdesignedtoprovideversioncontrolsupport

throughtheuseofinterfacesandinterfacenegotiation.

Thegoalwastoallownewversionsofaprogram(orofthe

componentsusedbyaprogram)tobedeployedwithout

breakingexistingprograms.COMdidnotliveuptothis

goal,andinstead—forbothCOMcomponentsandregular

Win32software—thespreadofincompatiblecomponents

andtheresultingbrokensoftwarehascometobeknown

asDLLhell.The.NETinitiativeaddressesthisproblemfor

.NETprogramsthroughtheuseofstrongnaming,which

providesbuilt-inversioncontrolsothataprogramruns

onlywiththelibrariesandcomponentsforwhichitwas

tested.

Whenthe.NETinitiativewasannouncedin2000,it

heraldedareplacementforbothWin32andCOM.While

MicrosoftcontinuesaddingWin32extensionstoitsvarious

operatingsystems,Win32isnolongerthecore

programminginterface.Thatrolenowfallstothe.NET

FrameworkondesktopversionsofWindowsandthe.NET

CompactFrameworkonmobiledevicesincludingWindows

CEplatformssuchasthePocketPC.Andwhilesupportfor

COMcontinues,[3]theroleofnewsoftwarecomponentsis

playedby.NETassembliesandnotbyCOMcomponents.

[3]The.NETFrameworksupportsCOMwithafeaturereferredtoasCOMinterop.Version

1.0ofthe.NETCompactFrameworkhasnoCOMsupport;afutureversionwilladdCOM

interopsupport.



The.NETCompactFrameworkbringsthetechnologiesof

the.NETFrameworktothemobileandembeddedworldof

WindowsCE.Tobetterunderstandthedynamicofthis

mix,thischapterstartswithadiscussionofWindowsCE.



Wenextlookatthebroaderscopeof.NETasimplemented

inthe.NETFrameworkwithitssupportforWindows

Forms,WebForms,andWebServices.Weconcludethe

chapterwithadiscussionofthe.NETCompactFramework

—whatitis,howitworks,andwhereitisgoing.

Amazon



Prev



don'tbeafraidofbuyingbooks



Next



WindowsCEOverview

Asofthiswriting,thePocketPCisthemostsuccessful

WindowsCE–powereddevice.Asaresultofthatsuccess,

the.NETCompactFrameworksupportsallversionsofthe

PocketPC,includingthefirsttwogenerations(thePocket

PC2000andthePocketPC2002),whicharebuilton

WindowsCE3.0.Thisisnoteworthybecause,exceptfor

thePocketPC,allWindowsCE–poweredplatformsmust

runWindowsCEversion4.1orlatertosupportthe.NET

CompactFramework.(ThethirdgenerationofPocketPC,

thePocketPC2003,runsthislaterversionoftheoperating

system.)Itisworthnotingthatthe.NETCompact

FrameworkcomespreinstalledonthePocketPC2003in

deviceROMbutmustbemanuallyinstalledforthePocket

PCandPocketPC2002devices.

Tomanypeople,PocketPCandWindowsCEareoneand

thesame.Thisisdue,inpart,totheuseoftheterm

PocketPCOStorefertothesoftwarethatrunsaPocket

PC.SomepeopleseemtoassumethatthePocketPCis

runningnotWindowsCEbutsomeotheroperatingsystem.

However,thatisnotthecase:thePocketPCisbuiltonthe

WindowsCEoperatingsystem.

Wearenotbeingnitpicky;wejustwanttomakesurethat

PocketPCdevelopersunderstandthatsomeusefultools

andtechnologiesaresometimeslabeledasbeingWindows

CEcompatible.Ifunawareofthiscommonthread,a

developermightmisssomethingthatmightprovehelpful.

Understandingthiscommonthread,adevelopercanstart

toseethewiderimpactthatWindowsCEhashad—andwill

continuetohave—andhowitaddressestheneedsof



embeddedsystems.WindowsCEisthefoundationfora

widerangeofothersmartdevices.

Inthesummerof2003,Microsoftlaunchedamarketing

campaignwithanewbrand,WindowsMobileDevices,to

tiethePocketPCandtheSmartphonetogetherasmobile

extensionstotheWindowsbrandname.InAugust2003,

Microsoftmadeavailableaversionofthe.NETCompact

FrameworkthatiscompatiblewiththeSmartphone2003.

WhilethefocusofthisbookisonthePocketPC,wehave

nodoubtthatSmartphonesupportisgoingtobe

importanttomanysoftwaredevelopers.

BeyondthePocketPCandtheSmartphone,manyother

smartdevicesarepoweredbyWindowsCE,[4]including

barcodescannersfromcompanieslikeIntermec,Psion

Teklogix,andSymbolTechnologies;smartdisplaysfrom

companieslikeViewSonicandPhilips;andautomobilebasednavigationandentertainmentsystems—runningCE

forAutomotive—incarsfromBMW(developedbySiemens

VDOAutomotiveAG),Citroen,Fiat,Mitsubishi,Subaru,

Toyota,andVolvo.

[4]Insomecases,vendorssupportbothPocketPCandnon–PocketPCsmartdevices.The

underlyingoperatingsystemforbothtypesofdevicesisthesame:WindowsCE.



BecausethePocketPCandWindowsCEareconnectedin

themindsofsomany,developersnewtoWindowsCE

oftenassumethatarequiredPocketPCfeatureisalso

requiredforallWindowsCEdevices.ButWindowsCEisa

highlyconfigurableoperatingsystem,withhundredsof

systemcomponentsanddevicedriverstochoosefrom.

WhilemanyWindowsCE–powereddeviceshavedisplay

screens,headlessconfigurations—suchasnetworkrouters

andset-topboxes—arealsopossible.ManyWindowsCE–

poweredsmartdevicesrunasmobile,battery-powered

devices;butwall-powered,stationarysmartdevicesare

alsopossible,andWindowsCEhasbeenincorporatedinto



automatictellermachinesandcomputerprinters.And

whilesomeWindowsCE–powereddevicesrelysolelyon

RAMwithnorotatingstoragemedia,WindowsCEsupports

AdvancedTechnologyAttachment(ATA)drivesandother

installablefilesystemstoextendavailablestoragebeyond

whatisavailableintheobjectstore.[5]

[5]TheobjectstoreisaRAM-basedstorageareawiththreeelements:afilesystem,a

registry,andtheCEpropertydatabases.ThesearediscussedindetailinChapter11.



WeWroteOurSampleCodeforthe

PocketPC

BecauseofthesuccessofthePocketPC,wewrote

thisbookexpectingthatPocketPCprogrammers

wouldmakeupthemajorityofourreaders.Mostof

ourexamples,infact,arebuiltforquarter-VGA

portrait-modedisplayscreens—thesizeand

orientationthat,untilthepresent,hasbeen

standardonaPocketPC.

Fordeveloperswritingprogramsfordevicesother

thanthePocketPC,oursamplesshouldrunwith

fewifanychanges.Theonlythingrequiredisthata

platformbecompatiblewiththe.NETCompact

Framework,installedeitherinROMoratruntime

intotheobjectstore.



DesignGoals

Whenstartingtolookatanytechnology,ithelpstoknow

whatthecreatorsofthetechnologyhadinmindduring

theirdevelopmentprocess.Westart,then,witha

discussionofthedesigngoalsforWindowsCE.Wehave

foundthateachdesigngoalhasarealimpactonwhatan

applicationprogrammercandoandthatlearningabout

thesedesigngoalshelpsprogrammersunderstandawide

rangeofchoicesmadebytheWindowsCEdevelopment

teams.



Welearnedaboutthesedesigngoalsthroughdiscussions

withtheoriginalWindowsCEdevelopmentteam.These

designgoalsstillplayanimportantrolebecausethey

describetherequirementsthatsubsequentdevelopment

teamshavefollowedastheyenhancedandfine-tunedthis

operatingsystem:

Small

Modular

Portable

Compatible

Connected

Realtime

Thefollowingsubsectionsdiscusseachofthesedesign

goals.

Small



Thefirstdesigngoalisalsothemostimportant:Windows

CEwasbuilttobesmall.ThesmallestWindowsCEimage

islessthan500K—thetinykernelthathasnodisplay

screenandnodevicedrivers.Byitself,thetinykernel

imagecansupportafilesystem,runprocesses,start

threads,loaddynamiclinklibraries(DLLs),andaccess

memory.Thetinykerneldoesnotsupportenoughofthe

Win32APItosupportthe.NETCompactFrameworkbutis

certainlyenoughforsimpledeviceslikeadumbprinteror

aportablemusicplayer.

Amoretypicaldeviceimagemightoccupy5MBor10MBof

RAM—adequatetosupportadisplayscreenandenough

networkprotocolstorunaWebbrowser.Devicessuchas



thePocketPCmighthavea32MB(orlarger)ROMimage,

consistinglargelyofapplicationprogramsandoptional

devicedrivers.

Thisisnotsmallbythestandardsofotherembedded

operatingsystems,whichmighthaveaminimumfootprint

evensmallerthanthetinykernel.However,WindowsCE

doesprovideafeature-rich,configurableoperatingsystem.

Bywayofcomparison,considerthevariousdesktop

versionsofWindows.WindowsMe,forexample,requires

100MBofdiskspace;WindowsXPrequires500MBofdisk

space.IntheMicrosoftWindowsfamilyofoperating

systems,WindowsCEisdefinitelytheverysmall—and

veryflexible—sibling.

TheemphasisonmakingWindowsCEsmallwasintended

toreducetherequiredhardware,therebymakingWindows

CEagoodfitforhigh-volume,low-costconsumer

electronicdevices.Inthathighlycompetitivemarket,

developmentteamsworkhardtoreducecostsbyscaling

backontherequiredhardware—theRAM,theROM,the

CPU,andthemyriadcomponents—becauselowercosts

createacompetitiveadvantageintheprice-conscious

worldofconsumerelectronics.

The"smallisgood"mind-setforWindowsCEmostly

affectsdeveloperswhocometoWindowsCEwithWin32or

.NETFrameworkexperiencefromdesktopversionsof

Windows.Suchprogrammersoften"stubtheirtoes,"which

occurswhenprogrammersnewtoWindowsCEstarttoget

comfortablewithwhateverAPItheyareusing.Justwhen

theythinktheyhavedevice-sideprogrammingfiguredout,

theyfindtheywanttouseanoldfamiliarfriendfromthe

desktopthatisnotimplementedunderWindowsCE.It

mightbeaWin32functioncall.Itcouldbea.NET

Frameworknamespace,class,property,method,orevent.

Atfirst,thesecanbefrustratingexperiencesthatmake

youwonderwhatglobalconspiracyhasdeprivedyouof



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 1.  .NET Compact Framework Architecture

Tải bản đầy đủ ngay(0 tr)

×