The Velo CE Primer

Chapter 9Reference

What Each ROM Has

A selection of functions people reach for, checked against the export lists in exports/. A blank cell means the ROM doesn't export it, so a program that calls it won't compile for that version.

FunctionCE 1.0CE 2.0
Text
wsprintfWYesYes
wcslenYesYes
wcscpyYesYes
wcscmpYesYes
_wcsicmpYesYes
lstrcmpWYes
lstrcmpiWYes
CharUpperWYes
CharLowerWYes
towlowerYes
MultiByteToWideCharYes
WideCharToMultiByteYes
FormatMessageWYes
Dialogs
DialogBoxIndirectParamWYesYes
CreateDialogIndirectParamWYesYes
GetDlgItemYesYes
SetDlgItemTextWYes
GetDlgItemTextWYes
SendDlgItemMessageWYes
SetDlgItemIntYesYes
CheckRadioButtonYesYes
GetOpenFileNameWYesYes
GetSaveFileNameWYesYes
Drawing
CreatePenYes
CreatePenIndirectYesYes
CreateSolidBrushYesYes
CreatePatternBrushYes
CreateDIBSectionYesYes
StretchBltYesYes
TransparentImageYes
DrawFrameControlYes
CreateRectRgnYes
SetROP2Yes
Windows and input
LoadCursorWYes
SetCursorYesYes
RegisterWindowMessageWYes
GetClassLongWYes
DrawMenuBarYes
PlaySoundWYes
sndPlaySoundWYesYes
MessageBeepYesYes
Files and system
GetModuleFileNameWYes
GetTempPathWYes
GetDiskFreeSpaceExWYes
GetStoreInformationYesYes
CopyFileWYesYes
SHCreateShortcutYesYes
ShellExecuteExYesYes
GetVersionExYesYes
GetSystemPowerStatusExYesYes
QueryPerformanceCounterYes
Processes and threads
CreateProcessWYesYes
OpenProcessYes
GetExitCodeProcessYes
CreateMutexWYes
CreateEventWYesYes
CreateThreadYesYes
TerminateThreadYes
Scheduling and databases
CeRunAppAtTimeYes
PegRunAppAtTimeYesYes
CeRunAppAtEventYes
CeCreateDatabaseYes
CeOpenDatabaseYes
PegCreateDatabaseYesYes
PegOpenDatabaseYesYes
CE 1.0 names the database and notification functions Peg where CE 2.0 says Ce: PegOpenDatabase, PegRunAppAtTime. CE 2.0 has both.

Microsoft's SDK headers covered some gaps with macros: DialogBoxParamW, and on CE 1.0 SetDlgItemTextW, GetDlgItemTextW and SendDlgItemMessageW, are built from the functions that are exported. Some functions are exported without the W, such as GetVersionEx and FindResource, though they take wide strings. The toolchain's headers accept either name.

What the headers declare

The toolchain's headers are CeGCC's w32api, patched so constants, structures and signatures match Microsoft's CE 1.0 and 2.0 SDKs. windows.h gives the API as the target version has it, with the C runtime's wide string functions and the object store databases. commctrl.h, commdlg.h, winsock.h and the others add their parts. A function the target ROM doesn't export is marked unavailable, so using it is a compile error that names the version.

Not covered: COM and OLE, telephony, drivers and kernel internals, the address book and mail APIs, and ANSI (A) structures. The toolchain's README.md has the full list. For those, check the export list and declare what you need yourself, with WINAPI.

Gotchas

Everything in this book that's different from what you'd expect, in one place.

SymptomCauseFix
Greys come out black on CE 1.0CE 1.0 uses the low two bits of the red value as the greyUse RGB(0,0,0), RGB(85,85,85), RGB(170,170,170), RGB(255,255,255) or system colours
Controls inside a group box or tab control are invisibleSiblings stack in creation order, first on top, and these paint their insidesCreate the group box or tab control after its contents
"'Function' is unavailable: not in Windows CE 1.0"That ROM doesn't export itUse an alternative, or put it behind #if _WIN32_WCE >= 200
Program crashes reading a struct from a bufferUnaligned access on MIPSCopy with memcpy or read bytes
Program can't find its filesNo current directory, and no GetModuleFileNameW on CE 1.0Full paths, a known install folder, or the folder on the command line
LoadLibraryW(L"mine.dll") failsNeither version searches the program's folderPut DLLs in \Windows or use a full path
The interface freezes during a downloadBlocking socket calls on the interface threadA worker thread, results by PostMessageW
Tap coordinates are huge numbersLOWORD of a negative coordinateCast through short
Nothing happens after LB_SETCURSEL or similarNotifications only follow what the user doesUpdate dependent state yourself
Waiting for a started program returns at once on CE 1.0A new process's handle reports finished therePoll for its window instead
Italic text looks broken on CE 1.0The CE 1.0 ROM's fontsUse bold and size for emphasis
HTTPS failsNo modern TLS on the VeloPlain HTTP through a proxy
SetEvent doesn't linkCE has no such export: it's an inline function over EventModifyUse the toolchain's windows.h
SetWindowLongW(window, GWL_USERDATA, ...) fails on CE 1.0CE 1.0 doesn't support GWL_USERDATAExtra window memory: cbWndExtra and offset 0
MultiByteToWideChar(CP_UTF8, ...) failsCE has no UTF-8 code pageConvert UTF-8 yourself (chapter 5)
BitBlt fails on CE 1.0CE 1.0 only does SRCCOPY, SRCPAINT, SRCAND and SRCINVERTStick to those four
Dividing by zero gives a strange numberInteger division doesn't trapCheck divisors
Program closes silentlyIt crashedRun it under GDB, or with --debug-output and velo-symbolize

Notification Codes

How each control tells its parent something happened.

ControlMessageCodes
Button, check box, radio buttonWM_COMMANDBN_CLICKED. Read a check with BM_GETCHECK.
EditWM_COMMANDEN_CHANGE after each edit
List boxWM_COMMANDLBN_SELCHANGE, LBN_DBLCLK, both only with LBS_NOTIFY
Combo boxWM_COMMANDCBN_SELCHANGE
Menu, accelerator, command bar buttonWM_COMMANDThe command ID in LOWORD(wParam)
List viewWM_NOTIFYLVN_ITEMCHANGED, NM_CLICK, NM_DBLCLK, and LVN_ITEMACTIVATE on CE 2.0
Tree viewWM_NOTIFYTVN_SELCHANGEDW
Tab controlWM_NOTIFYTCN_SELCHANGE
TrackbarWM_HSCROLLIts handle in lParam
Scroll bar on a windowWM_VSCROLL, WM_HSCROLLSB_LINEUP, SB_PAGEDOWN, SB_THUMBTRACK and the rest in LOWORD(wParam)

Glossary

Accelerator
A shortcut key, mapped to a command ID by an ACCELERATORS resource.
Command bar
CE's combined menu bar, toolbar and title bar, at the top of a program's window.
Common controls
The controls in commctrl.dll: list view, tree view, tabs, progress bar, trackbar, up-down, toolbar, status bar. Call InitCommonControls before using them.
Device context (DC)
A drawing surface with its current font, pen, brush and colours. HDC.
Dialog units
The coordinates in dialog resources, which scale with the dialog's font.
GDI
The drawing part of Windows: device contexts, fonts, pens, brushes and bitmaps.
Handle
An opaque value naming something the system owns: HWND, HFONT, HANDLE.
Instance
A loaded program or DLL, HINSTANCE. Needed to load its resources and register its window classes.
Object store
CE's storage in battery-backed RAM: the file system, the registry and databases.
Resource
Data built into the program from a .rc file: menus, dialogs, icons, bitmaps, strings, accelerators.
Window class
A name plus a window procedure and defaults, registered with RegisterClassW, that windows are created from.
Window procedure
The function that handles a window's messages.
_WIN32_WCE
100 when building for CE 1.0, 200 for CE 2.0.

Further Reading