programming with embedded visual c++ 4.0 paul yao the paul yao company

37

Click here to load reader

Upload: julia-king

Post on 22-Dec-2015

227 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company
Page 2: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Programming WithProgramming WitheMbedded Visual C++ eMbedded Visual C++ 4.04.0

Paul YaoPaul YaoThe Paul Yao CompanyThe Paul Yao Companyhttp://www.paulyao.comhttp://www.paulyao.com

Page 3: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

DisplayDisplayUSB or SerialUSB or Serial

ProcessorProcessorMemoryMemory

GSM/GPRSGSM/GPRSCDMA/1xRTTCDMA/1xRTT

Device Device HardwareHardware

WiFiWiFiBluetoothBluetooth

RadioRadio

DriversDrivers

Windows MobileWindows Mobile CE DBCE DBActiveSyncActiveSync

Pocket OutlookPocket OutlookPocket Internet ExplorerPocket Internet ExplorerWindows Media PlayerWindows Media Player

Windows CEWindows CE

Software Platform (APIs)Software Platform (APIs)

Home ScreenHome ScreenUser Interface/ShellUser Interface/ShellHTML ControlHTML Control

GAPIGAPIRemote APIRemote APIConfigurationConfigurationBluetoothBluetoothSecuritySecurity

Connection ManagerConnection Manager TAPITAPISMS SMS MAPI MAPI POOM POOM ActiveSyncActiveSync

MultimediaMultimediaCommunicatioCommunicationn

Device ManagementDevice Management PresentationPresentation

ADO CEADO CEXMLXMLCE DBCE DBOLE DBOLE DB

Data AccessData Access

NativeNative

Win32Win32

MFCMFC ATLATL

ManagedManaged

.NET Compact.NET CompactFrameworkFramework

Server sideServer side

ASP .NETASP .NETMobile ControlsMobile Controls

NativeNative

Win32Win32

MFCMFC ATLATL

ManagedManaged

.NET Compact.NET CompactFrameworkFramework

Server sideServer side

ASP .NETASP .NETMobile ControlsMobile Controls

Windows Mobile Development PlatformWindows Mobile Development Platform:: TodayToday

Embedded VC++Embedded VC++ Visual Studio .NETVisual Studio .NET

Page 4: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

AgendaAgenda

Part 1: The ToolsPart 1: The Tools

Part 2: Tool TipsPart 2: Tool Tips

Part 3: Native or Part 3: Native or Managed?Managed?

Page 5: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Part 1: The ToolsPart 1: The Tools

What is eMbedded Visual C++ 4.0?What is eMbedded Visual C++ 4.0?New features since eVC++ 3.0New features since eVC++ 3.0C++ EnhancementsC++ EnhancementsRemote ToolsRemote Tools

Page 6: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

What Is eVC++ 4.0?What Is eVC++ 4.0?

Stand-alone development Stand-alone development environmentenvironment

Build “native” executablesBuild “native” executablesLanguages: C, C++Languages: C, C++APIs: Win32 API, MFCAPIs: Win32 API, MFCTemplate Libraries: ATL & WTL Template Libraries: ATL & WTL

Companion to Visual Studio .NET Companion to Visual Studio .NET 20032003

Build “managed” executablesBuild “managed” executablesLanguages: C#, Visual Basic .NETLanguages: C#, Visual Basic .NETAPI: .NET Compact FrameworkAPI: .NET Compact Framework

Page 7: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

New Features in eVC++ New Features in eVC++ 4.04.0Since eVC++ 3.0Since eVC++ 3.0

Improved emulatorImproved emulatorGreater fidelity to device OS imageGreater fidelity to device OS imageActiveSync connections (via network ActiveSync connections (via network virtual switch)virtual switch)

Improved DebuggingImproved DebuggingAttach to running processAttach to running processJIT attach to hung processJIT attach to hung process

Page 8: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

C++ EnhancementsC++ Enhancements

C++ structured exception handlingC++ structured exception handlingtrytry

catchcatch

throwthrow

Runtime Type Information (RTTI)Runtime Type Information (RTTI)Standard Template Library (STL)Standard Template Library (STL)

James Pratt
They need to check out this KB article for this http://support.microsoft.com/default.aspx?scid=kb;[LN];830482
Page 9: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Remote ToolsRemote ToolseVC++ 3.0 & eVC++ 4.0eVC++ 3.0 & eVC++ 4.0

Remote Spy++Remote Spy++Remote Registry EditorRemote Registry EditorRemote Heap WalkerRemote Heap WalkerRemote Process ViewerRemote Process ViewerRemote ZoominRemote ZoominRemote File ViewerRemote File Viewer

Page 10: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Remote ToolsRemote ToolsNew with eVC++ 4.0 (1/2)New with eVC++ 4.0 (1/2)

Remote Call ProfilerRemote Call Profiler““Testing Real-Time Systems in Windows Testing Real-Time Systems in Windows CE .NET” by Mike Hall and Steve MailletCE .NET” by Mike Hall and Steve Maillethttp://www.windowsfordevices.com/http://www.windowsfordevices.com/articles/AT2137345992.htmlarticles/AT2137345992.html

Remote Kernel TrackerRemote Kernel TrackerProcessesProcessesThreadsThreadsInterruptsInterrupts

Page 11: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Remote ToolsRemote ToolsNew with eVC++ 4.0 (2/2)New with eVC++ 4.0 (2/2)

Remote Performance MonitorRemote Performance MonitorGraphical display with continual Graphical display with continual monitoringmonitoringTracks: CPU usage, threads, processes, Tracks: CPU usage, threads, processes, memory, network traffic, battery, memory, network traffic, battery, among other valuesamong other values

Remote System InformationRemote System InformationSnapshot of system stateSnapshot of system stateShows: OS version, CPU info, OEM code Shows: OS version, CPU info, OEM code page, memory, power state, object page, memory, power state, object store usage, active devices (COM1:, store usage, active devices (COM1:, COM2:, etc.), user-interface colors, COM2:, etc.), user-interface colors, system metricssystem metrics

Page 12: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Part 2: Tool TipsPart 2: Tool Tips

SetupSetupText EditorText EditorProject SettingsProject SettingsLinkerLinkerEmulatorEmulatorDebugger TipsDebugger Tips

Page 13: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Setup Tip #1:Setup Tip #1:Use the right tool…Use the right tool…

eVC++ 3.0eVC++ 3.0For Windows CE For Windows CE 3.03.0Pocket PCPocket PCPocket PC 2002Pocket PC 2002Smartphone 2002Smartphone 2002

eVC++ 4.0eVC++ 4.0For Windows For Windows CE .NETCE .NET

version 4.0version 4.0version 4.1version 4.1version 4.2version 4.2

Pocket PC 2003Pocket PC 2003Smartphone 2003Smartphone 2003

Page 14: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Setup Tip #2: Setup Tip #2: eVC++ 4.0eVC++ 4.0

Upgrade to Service Pack 3Upgrade to Service Pack 3Before – SP tied to OS version:Before – SP tied to OS version:

Windows CE 4.0 – no service packWindows CE 4.0 – no service packWindows CE 4.1 – required SP1Windows CE 4.1 – required SP1Windows CE 4.2 – required SP2Windows CE 4.2 – required SP2

SP3 Supports:SP3 Supports:Windows CE 4.0Windows CE 4.0Windows CE 4.1Windows CE 4.1Windows CE 4.2Windows CE 4.2

Recommendation: Upgrade – today!Recommendation: Upgrade – today!http://www.microsoft.com/downloads/details.aspx?http://www.microsoft.com/downloads/details.aspx?FamilyID=5bb36f3e-5b3d-419a-9610-FamilyID=5bb36f3e-5b3d-419a-9610-2fe53815ae3b&DisplayLang=en2fe53815ae3b&DisplayLang=en

James Pratt
YOu could provide a link http://www.microsoft.com/downloads/details.aspx?FamilyID=5bb36f3e-5b3d-419a-9610-2fe53815ae3b&DisplayLang=en
Page 15: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Setup Tip #3:Setup Tip #3:Use latest version of ActiveSyncUse latest version of ActiveSync

Latest Version: 3.7.1Latest Version: 3.7.1 Devices and VersionDevices and Version

Pocket PC – ActiveSync 3.1Pocket PC – ActiveSync 3.1Pocket PC 2002 – ActiveSync 3.5Pocket PC 2002 – ActiveSync 3.5Smartphone 2002 – ActiveSync 3.6Smartphone 2002 – ActiveSync 3.6Pocket PC 2003 – ActiveSync 3.7Pocket PC 2003 – ActiveSync 3.7Smartphone 2003 – ActiveSync 3.7.1Smartphone 2003 – ActiveSync 3.7.1

Reference:Reference:Chris De Herrera’s Web siteChris De Herrera’s Web sitehttp://www.cewindows.nethttp://www.cewindows.net

James Pratt
I believe 2003 is supported just fine from 3.7 however 3.7.1 has a ton of stability and perf improvements
Page 16: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Setup Tip #4: Setup Tip #4: Install RTTI on PPC 2003Install RTTI on PPC 2003

Pocket PC 2003 – does not support…Pocket PC 2003 – does not support…C++ structured exceptionsC++ structured exceptionsRun-time Type Information (RTTI)Run-time Type Information (RTTI)Standard Template Library (STL)Standard Template Library (STL)

Support can be added:Support can be added:Download RITTI.EXE from MS web siteDownload RITTI.EXE from MS web sitePortions install on development systemPortions install on development systemPortions install on devicePortions install on device

GoogleGoogle®® for… for…““RTTI Pocket PC” or “KB830482”RTTI Pocket PC” or “KB830482”

James Pratt
RTTI not RITTI!!
Page 17: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Text Editor Tip: Text Editor Tip: Use keyboard shortcutsUse keyboard shortcuts

[F1] - Context Sensitive help[F1] - Context Sensitive help[F4] - [Next] (Error, Search result, [F4] - [Next] (Error, Search result, etc.)etc.)[F6] - [Next Window][F6] - [Next Window][F9] - [Set Breakpoint] at cursor[F9] - [Set Breakpoint] at cursor[Tab] - Indent blocks of text[Tab] - Indent blocks of text[Ctrl] + [End] – Enable auto scroll for [Ctrl] + [End] – Enable auto scroll for output windows (build, debug, find)output windows (build, debug, find)

Page 18: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

IDE Tip For Project IDE Tip For Project Settings:Settings:Use ‘All Configurations’Use ‘All Configurations’

Page 19: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Linker TipLinker TipFinding missing functionsFinding missing functions

Example:Example:Where to find "Where to find "MailOpenMailOpen", "", "MailPutMailPut", and ", and ""MailCloseMailClose""The Answer: The Answer: msgstore.libmsgstore.lib

Solving the general case:Solving the general case:C> dumpbin –linkermember:2 C> dumpbin –linkermember:2

msgstore.lib>msgstore.datmsgstore.lib>msgstore.datC> dumpbin –linkermember:2 msmqrt.lib > C> dumpbin –linkermember:2 msmqrt.lib >

msmqrt.datmsmqrt.dat

Page 20: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Emulator Tip:Emulator Tip:Getting Set UpGetting Set Up

Operating System:Operating System:Use Win 2000 sp2, or WinXPUse Win 2000 sp2, or WinXPCannot use Win 9x/MeCannot use Win 9x/Me

Communications:Communications:Requires TCP/IP (Internet) ProtocolRequires TCP/IP (Internet) ProtocolMachine Name must start with letterMachine Name must start with letter

Tip:Tip:Login with Administrator privilegesLogin with Administrator privilegesInstall Microsoft Loopback AdapterInstall Microsoft Loopback Adapter

Ori Amiga
the emulator coming w/ SP2 also supports drive-mapping, and network VirtualSwitch
James Pratt
REALLY? I didn't know that. Can you explain to me in more detail?
Page 21: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Debugger Tip #1:Debugger Tip #1:USB/Serial ConnectionUSB/Serial Connection

Establish ActiveSync PartnershipEstablish ActiveSync PartnershipUse latest version (3.7.1)Use latest version (3.7.1)

Select correct CPU (WCE Select correct CPU (WCE Configuration Toolbar)Configuration Toolbar)For best performance, hide Watch For best performance, hide Watch and Variables windowsand Variables windowsConsider using network debugging…Consider using network debugging…

Ori Amiga
just fyi... PPC Ozone, and Next version of Smartphone both require ActiveSync 3.7
Page 22: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Debugger Tip #2:Debugger Tip #2:Using a Network At Home (no Using a Network At Home (no DHCP)DHCP)

Establish partnership via Establish partnership via USB/serialUSB/serialStatic IP address on Static IP address on desktopdesktopStatic IP Address on smart Static IP Address on smart devicedevice

Set WINS address to desktop Set WINS address to desktop IP addressIP addressStart->Settings-> Start->Settings-> [Connections][Connections][Network] [Adapters][Network] [Adapters]<Select Adapter><Select Adapter>[Name Servers][Name Servers]

Page 23: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Debugger Tip #3:Debugger Tip #3:Using a network At Work (with Using a network At Work (with DHCP)DHCP)

Desktop-SideDesktop-SideEnable network connectionsEnable network connectionsConnect via USB/serialConnect via USB/serial

Device-SideDevice-SideEnable network connections in ActiveSyncEnable network connections in ActiveSyncEnable DHCP for network adapterEnable DHCP for network adapterAttach network adapterAttach network adapterMight need to reset deviceMight need to reset device

Connect to NetworkConnect to NetworkWiredWiredWirelessWireless

Page 24: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Part 3: Native Or Part 3: Native Or Managed?Managed?

Which is better?Which is better?A comparisonA comparisonWhen to use native code / managed When to use native code / managed codecode

Bridging the gapBridging the gapP/InvokeP/InvokeThe P/Invoke WizardThe P/Invoke Wizard

Building Native DLLsBuilding Native DLLsCompilerCompilerDownload native DLLs for managed Download native DLLs for managed projects from Visual Studio .NETprojects from Visual Studio .NET

Page 25: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

A ComparisonA Comparison

Native CodeNative CodeC/C++ & Win32 APIC/C++ & Win32 APIEXEs & DLLsEXEs & DLLs

Native CPU Native CPU instructionsinstructions

Portable source codePortable source codeManual cleanupManual cleanupActiveX / COMActiveX / COMNo run-time required No run-time required (OS (OS isis the runtime) the runtime)

Managed CodeManaged CodeC#/VB.NET & .NET CFC#/VB.NET & .NET CFEXEs & DLLsEXEs & DLLs

IL instructions; JIT to IL instructions; JIT to native CPU instructionsnative CPU instructions

Portable binary codePortable binary codeGarbage CollectionGarbage CollectionCOM not supportedCOM not supportedRun-time requiredRun-time required

2.0 MB footprint2.0 MB footprintRequires support from Requires support from underlying Windows CE underlying Windows CE operating systemoperating systemIn ROM for all Windows In ROM for all Windows Mobile devicesMobile devices

James Pratt
Included in ROM on ALL 2003 devices
Page 26: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

When To Use…When To Use…Native code…Native code…

Device driversDevice driversShell extensionsShell extensions

Today screenToday screenControl panelControl panelCustom input Custom input panelpanelSkinnable UISkinnable UI

Serial port I/OSerial port I/OApplication setup Application setup (CESetup.dll)(CESetup.dll)Remote API (RAPI) Remote API (RAPI) for device-side for device-side DLLDLLWeb service Web service serverserverReal-time threadsReal-time threads

CE property CE property databasesdatabasesActiveX / COMActiveX / COM

ActiveSync ActiveSync providerproviderMail API (MAPI)Mail API (MAPI)Native XML parserNative XML parserObject exchange Object exchange (OBEX)(OBEX)Pocket Outlook Pocket Outlook Object Model Object Model (POOM)(POOM)

Wrapper for COM Wrapper for COM librarylibrary

Callable from Callable from managed codemanaged code

Page 27: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

When To Use…When To Use…Managed code…Managed code…

On devices On devices with .NET with .NET Compact Compact FrameworkFramework

Windows Mobile Windows Mobile 2003-based 2003-based devicesdevicesCustom display-Custom display-based smart based smart devicesdevices

GUI application GUI application codecode

Forms, controls Forms, controls custom controlscustom controls

Web service Web service clientsclientsDatabase Database (ADO.NET) clients(ADO.NET) clients

Build managed DLLsBuild managed DLLsShared class librariesShared class librariesCustom controlsCustom controls

Managed code Managed code benefits:benefits:

Well designed APIWell designed APIAutomatic garbage Automatic garbage collectioncollectionPortable binary filesPortable binary filesInteroperability with Interoperability with desktop .NET desktop .NET FrameworkFramework

Page 28: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Bridging The GapBridging The GapPlatform Invoke (P/Invoke)Platform Invoke (P/Invoke)

Managed code featureManaged code featureSupports calling native DLLsSupports calling native DLLs

C-callable function names (not C++ C-callable function names (not C++ ‘mangled’ names)‘mangled’ names)Parameter types w/built-in support:Parameter types w/built-in support:

Blittable types – integers (8, 16, 32 bit), Blittable types – integers (8, 16, 32 bit), stringsstringsArrays of blittable typesArrays of blittable types

Other parameter types require more Other parameter types require more effort:effort:

Character arrays within structuresCharacter arrays within structuresNested objectsNested objectsUnionsUnions

Page 29: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

A Helper: The P/Invoke WizardA Helper: The P/Invoke Wizard

Download from: Download from: http://www.paulyao.com/pinvokehttp://www.paulyao.com/pinvoke

Page 30: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Building DLLsBuilding DLLsProblems with C++ “name Problems with C++ “name decorating”decorating”

An Include File:An Include File:#include "MyLen.h"#include "MyLen.h"

The Source Code (MyLen.cpp):The Source Code (MyLen.cpp):_declspec(dllexport) int _cdecl _declspec(dllexport) int _cdecl

MyLen(char * p)MyLen(char * p)

{{

return 4;return 4;

}}

Resulting Exported Function:Resulting Exported Function:?MyLen@@YAHPAD@Z?MyLen@@YAHPAD@Z

Page 31: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Building DLLsBuilding DLLsUnmangling function namesUnmangling function names

Solution:Solution:// MyLen.H// MyLen.H

#ifdef _cplusplus#ifdef _cplusplus

extern "C" {extern "C" {#endif#endif_declspec(dllexport) int _cdecl MyLen(char * p);_declspec(dllexport) int _cdecl MyLen(char * p);

#ifdef _cplusplus#ifdef _cplusplus

}}

#endif#endif

Resulting Exported Function: Resulting Exported Function: MyLenMyLen

Page 32: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Managed Code Project TipManaged Code Project TipDownloading native DLLsDownloading native DLLs

In VS .NET Solution In VS .NET Solution ExplorerExplorerAdd->Add Existing ItemAdd->Add Existing ItemSet Build Action = Set Build Action = “Content”“Content”Example:Example:

Add “Helper.dll”Add “Helper.dll”Downloaded with Downloaded with executableexecutable

Page 33: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Wrap-UpWrap-Up

eVC++ 4.0:eVC++ 4.0:Native code for Windows CE .NET 4.xNative code for Windows CE .NET 4.xUpgrade to Service Pack 3Upgrade to Service Pack 3Certain scenarios require native codeCertain scenarios require native codeBuild native DLLs to support managed Build native DLLs to support managed codecode

Contact Us: Contact Us: [email protected]@paulyao.comThe Paul Yao Company’s The Paul Yao Company’s Weekend Weekend Warrior WorkshopsWarrior Workshops for Windows for Windows Mobile programmerMobile programmerOther training workshopsOther training workshopsOur online Our online eCoaching for eCoaching for ProgrammersProgrammers series series

Page 34: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

After This Session…After This Session…

Visit the Windows Mobile Visit the Windows Mobile booth to:booth to:

Get the Get the Windows Mobile Developer Windows Mobile Developer Resource Kit Resource Kit and start supporting and start supporting landscape and high DPI landscape and high DPI Talk to the Talk to the Technical SupportTechnical Support team teamJoin the Windows Mobile Solutions Join the Windows Mobile Solutions Partner Partner ProgramProgramEnter the Microsoft Enter the Microsoft Mobile2Market Mobile2Market Application ContestApplication Contest

Fill in your evaluation form Fill in your evaluation form sponsored by AT&T Wirelesssponsored by AT&T Wireless

1 MPX200 given away per 1 MPX200 given away per session. See session. See www.mscorpevents.com/mdcwww.mscorpevents.com/mdc

Page 35: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Your Questions…Your Questions…

Page 36: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

Thank You!Thank You!

Page 37: Programming With eMbedded Visual C++ 4.0 Paul Yao The Paul Yao Company

© 2004 Microsoft Corporation. All rights reserved.© 2004 Microsoft Corporation. All rights reserved.MICROSOFT CONFIDENTIAL. INTERNAL USE ONLY.MICROSOFT CONFIDENTIAL. INTERNAL USE ONLY.