Programming With
eMbedded Visual C++ 4.0
Paul Yao
The Paul Yao Company
http://www.paulyao.com
Windows Mobile Development Platform: Today
Visual Studio .NET
Embedded VC++
Managed
Native
MFC
ATL
Server side
ASP .NET
Mobile Controls
.NET Compact
Framework
Win32
Software Platform (APIs)
Device Management
Communication
Presentation
Data Access
Remote API
Configuration
Bluetooth
Security
Connection Manager
TAPI
SMS
MAPI
POOM
ActiveSync
Multimedia
Home Screen
User Interface/Shell
HTML Control
ADO CE
XML
CE DB
OLE DB
GAPI
Windows Mobile
Windows CE
CE DB
ActiveSync
Pocket Outlook
Pocket Internet Explorer
Windows Media Player
Drivers
Device
Hardware
Processor
Memory
Display
USB or Serial
Radio
GSM/GPRS
CDMA/1xRTT
WiFi
Bluetooth
Agenda
Part 1: The Tools
Part 2: Tool Tips
Part 3: Native or Managed?
Part 1: The Tools
What is eMbedded Visual C++ 4.0?
New features since eVC++ 3.0
C++ Enhancements
Remote Tools
What Is eVC++ 4.0?
Stand-alone development environment
Build “native” executables
Languages: C, C++
APIs: Win32 API, MFC
Template Libraries: ATL & WTL
Companion to Visual Studio .NET 2003
Build “managed” executables
Languages: C#, Visual Basic .NET
API: .NET Compact Framework
New Features in eVC++ 4.0
Since eVC++ 3.0
Improved emulator
Greater fidelity to device OS image
ActiveSync connections (via network virtual
switch)
Improved Debugging
Attach to running process
JIT attach to hung process
C++ Enhancements
C++ structured exception handling
try
catch
throw
Runtime Type Information (RTTI)
Standard Template Library (STL)
Remote Tools
eVC++ 3.0 & eVC++ 4.0
Remote Spy++
Remote Registry Editor
Remote Heap Walker
Remote Process Viewer
Remote Zoomin
Remote File Viewer
Remote Tools
New with eVC++ 4.0 (1/2)
Remote Call Profiler
“Testing Real-Time Systems in Windows CE
.NET” by Mike Hall and Steve Maillet
http://www.windowsfordevices.com/articles/A
T2137345992.html
Remote Kernel Tracker
Processes
Threads
Interrupts
Remote Tools
New with eVC++ 4.0 (2/2)
Remote Performance Monitor
Graphical display with continual monitoring
Tracks: CPU usage, threads, processes,
memory, network traffic, battery, among other
values
Remote System Information
Snapshot of system state
Shows: OS version, CPU info, OEM code page,
memory, power state, object store usage,
active devices (COM1:, COM2:, etc.), userinterface colors, system metrics
Part 2: Tool Tips
Setup
Text Editor
Project Settings
Linker
Emulator
Debugger Tips
Setup Tip #1:
Use the right tool…
eVC++ 3.0
For Windows CE 3.0
Pocket PC
Pocket PC 2002
Smartphone 2002
eVC++ 4.0
For Windows CE .NET
version 4.0
version 4.1
version 4.2
Pocket PC 2003
Smartphone 2003
Setup Tip #2:
eVC++ 4.0
Upgrade to Service Pack 3
Before – SP tied to OS version:
Windows CE 4.0 – no service pack
Windows CE 4.1 – required SP1
Windows CE 4.2 – required SP2
SP3 Supports:
Windows CE 4.0
Windows CE 4.1
Windows CE 4.2
Recommendation: Upgrade – today!
http://www.microsoft.com/downloads/details.aspx?FamilyID=5b
b36f3e-5b3d-419a-9610-2fe53815ae3b&DisplayLang=en
Setup Tip #3:
Use latest version of ActiveSync
 Latest Version: 3.7.1 
Devices and Version
Pocket PC – ActiveSync 3.1
Pocket PC 2002 – ActiveSync 3.5
Smartphone 2002 – ActiveSync 3.6
Pocket PC 2003 – ActiveSync 3.7
Smartphone 2003 – ActiveSync 3.7.1
Reference:
Chris De Herrera’s Web site
http://www.cewindows.net
Setup Tip #4:
Install RTTI on PPC 2003
Pocket PC 2003 – does not support…
C++ structured exceptions
Run-time Type Information (RTTI)
Standard Template Library (STL)
Support can be added:
Download RITTI.EXE from MS web site
Portions install on development system
Portions install on device
Google® for…
“RTTI Pocket PC” or “KB830482”
Text Editor Tip:
Use keyboard shortcuts
[F1] - Context Sensitive help
[F4] - [Next] (Error, Search result, etc.)
[F6] - [Next Window]
[F9] - [Set Breakpoint] at cursor
[Tab] - Indent blocks of text
[Ctrl] + [End] – Enable auto scroll for output
windows (build, debug, find)
IDE Tip For Project Settings:
Use ‘All Configurations’
Linker Tip
Finding missing functions
Example:
Where to find "MailOpen", "MailPut", and
"MailClose"
The Answer: msgstore.lib
Solving the general case:
C> dumpbin –linkermember:2 msgstore.lib>msgstore.dat
C> dumpbin –linkermember:2 msmqrt.lib > msmqrt.dat
Emulator Tip:
Getting Set Up
Operating System:
Use Win 2000 sp2, or WinXP
Cannot use Win 9x/Me
Communications:
Requires TCP/IP (Internet) Protocol
Machine Name must start with letter
Tip:
Login with Administrator privileges
Install Microsoft Loopback Adapter
Debugger Tip #1:
USB/Serial Connection
Establish ActiveSync Partnership
Use latest version (3.7.1)
Select correct CPU (WCE Configuration
Toolbar)
For best performance, hide Watch and
Variables windows
Consider using network debugging…
Debugger Tip #2:
Using a Network At Home (no DHCP)
Establish partnership via
USB/serial
Static IP address on desktop
Static IP Address on smart
device
Set WINS address to desktop IP
address
Start->Settings-> [Connections]
[Network] [Adapters]
<Select Adapter>
[Name Servers]
Debugger Tip #3:
Using a network At Work (with DHCP)
Desktop-Side
Enable network connections
Connect via USB/serial
Device-Side
Enable network connections in ActiveSync
Enable DHCP for network adapter
Attach network adapter
Might need to reset device
Connect to Network
Wired
Wireless
Part 3: Native Or Managed?
Which is better?
A comparison
When to use native code / managed code
Bridging the gap
P/Invoke
The P/Invoke Wizard
Building Native DLLs
Compiler
Download native DLLs for managed projects
from Visual Studio .NET
A Comparison
Native Code
C/C++ & Win32 API
EXEs & DLLs
Native CPU instructions
Portable source code
Manual cleanup
ActiveX / COM
No run-time required (OS
is the runtime)
Managed Code
C#/VB.NET & .NET CF
EXEs & DLLs
IL instructions; JIT to native
CPU instructions
Portable binary code
Garbage Collection
COM not supported
Run-time required
2.0 MB footprint
Requires support from
underlying Windows CE
operating system
In ROM for all Windows
Mobile devices
When To Use…
Native code…
Device drivers
Shell extensions
Today screen
Control panel
Custom input panel
Skinnable UI
Serial port I/O
Application setup
(CESetup.dll)
Remote API (RAPI)
for device-side DLL
Web service server
Real-time threads
CE property
databases
ActiveX / COM
ActiveSync provider
Mail API (MAPI)
Native XML parser
Object exchange
(OBEX)
Pocket Outlook
Object Model (POOM)
Wrapper for COM
library
Callable from
managed code
When To Use…
Managed code…
On devices with .NET
Compact Framework
Windows Mobile
2003-based devices
Custom display-based
smart devices
GUI application code
Forms, controls
custom controls
Web service clients
Database (ADO.NET)
clients
Build managed DLLs
Shared class libraries
Custom controls
Managed code benefits:
Well designed API
Automatic garbage
collection
Portable binary files
Interoperability with
desktop .NET Framework
Bridging The Gap
Platform Invoke (P/Invoke)
Managed code feature
Supports calling native DLLs
C-callable function names (not C++ ‘mangled’
names)
Parameter types w/built-in support:
Blittable types – integers (8, 16, 32 bit), strings
Arrays of blittable types
Other parameter types require more effort:
Character arrays within structures
Nested objects
Unions
A Helper: The P/Invoke Wizard
Download from: http://www.paulyao.com/pinvoke
Building DLLs
Problems with C++ “name decorating”
An Include File:
#include "MyLen.h"
The Source Code (MyLen.cpp):
_declspec(dllexport) int _cdecl
MyLen(char * p)
{
return 4;
}
Resulting Exported Function:
?MyLen@@YAHPAD@Z
Building DLLs
Unmangling function names
Solution:
// MyLen.H
#ifdef _cplusplus
extern "C" {
#endif
_declspec(dllexport) int _cdecl MyLen(char * p);
#ifdef _cplusplus
}
#endif
Resulting Exported Function:
MyLen
Managed Code Project Tip
Downloading native DLLs
In VS .NET Solution Explorer
Add->Add Existing Item
Set Build Action = “Content”
Example:
Add “Helper.dll”
Downloaded with executable
Wrap-Up
eVC++ 4.0:
Native code for Windows CE .NET 4.x
Upgrade to Service Pack 3
Certain scenarios require native code
Build native DLLs to support managed code
Contact Us: info@paulyao.com
The Paul Yao Company’s Weekend Warrior
Workshops for Windows Mobile programmer
Other training workshops
Our online eCoaching for Programmers series
After This Session…
Visit the Windows Mobile booth to:
Get the Windows Mobile Developer Resource Kit
and start supporting landscape and high DPI
Talk to the Technical Support team
Join the Windows Mobile Solutions Partner
Program
Enter the Microsoft Mobile2Market Application
Contest
Fill in your evaluation form
sponsored by AT&T Wireless
1 MPX200 given away per session.
See www.mscorpevents.com/mdc
Your Questions…
Thank You!
© 2004 Microsoft Corporation. All rights reserved.
MICROSOFT CONFIDENTIAL. INTERNAL USE ONLY.