Programming the .NET Compact Framework in C# By Paul Yao & David Durant
Chapter 4 – Calling Native Functions Page 4 Draft – 2002Nov17
Copyright © 2002 Paul Yao & David Durant
must create a set of unmanaged functions that wrap the COM
components. You can find one example of a sample wrapper for a
COM interface on the web site www.gotdotnet.com
, which shows
how to wrap the Pocket Outlook Object Model (POOM) in a
Common Dialog Boxes Common dialog boxes provide pre-built dialog boxes for opening
and closing files, allowing a user to select a font or a color, and
printing. The Compact Framework supports the file open & save
dialogs, but not the font and color pickers. In such cases, direct
calls to the underlying Win32 functions help fill this need.
Cryptography API The Crypto API provides encryption and decryption support to
supplement the support provided in the System.Security
Custom Controls Custom controls implemented in unmanaged DLLs can be
supported in Compact Framework Windows Forms applications.
Custom, Third-Party Unmanaged
Dynamic Link Libraries (DLLs)
Can access exported C-callable functions in a DLL.
Microsoft Message Queue (MSMQ) MSMQ allows for asynchronous communication between
Point-To-Point Message Queues This inter-process communication feature was introduced in
Windows CE .NET version 4.0. Provides anonymous pipe support
for inter-process or inter-thread communication.
Real-Time Threads Windows CE provides great real-time support, with very
consistent response times for the highest priority thread in the
system and for the highest priority interrupt. When you have hard
real-time requirements, the safest approach to take is to delegate
that work to Win32 code. Unexpected delays can occur in
managed code due to any of the following: (1) IL JIT – time taken
to convert IL to native machine instructions, (2) Garbage
Collection – all managed threads are blocked during memory
cleanup (unmanaged P/Invoke threads run freely without blocking,
and block only on return to managed code if garbage collection is
Registry Read and write to the system registry. In the Desktop Framework,
this is supported by the Microsoft.Win32.Registry class
– but not supported in the Compact Framework.
Call the Win32 CreateProcess function to run a program.
Shell functions Some very useful Win32 functions have a prefix of SH – which
stands for "Shell." Some of the interesting ones include
SHGetSpecialFolderPath, SHBrowseForFolder (CE
.NET 4.0 and later)
Sounds Compact Framework does not support sounds, which are available
with the Win32 sndPlaySound function.
Stream interface driver control codes
Windows CE uses
stream interface drivers
for system services
such as a web server (HTTPD), Microsoft Message Queue
(MSMQ), Universal Plug and Play (UPNP), and the Audio
Compression Manager (ACM). This type of driver is also used for
device drivers for various types of hardware including the serial
port, the infrared port, and various kinds of disk drives. Full access
to these drivers requires the Win32 file I/O functions, including
the DeviceIoControl function to send driver-specific control
Chapter 1, 1
Thank you for taking the time to read this preview chapter. We hope it has provided you
insights and tips to help with your Compact Framework programming project. You can help us
create a better book by clicking the comment link at the end of each paragraph, and sending your
comments and suggestions on our review web site.
Preview Chapter Text
Our public review site provides the complete table of contents for the Compact Framework
book at this link: http://www.paulyao.com/cfbook.htm
. That table of contents contains links to all
the preview chapters. The preview chapter provides the complete outline of topics covered in a
chapter, and also the first section or two from each chapter.
Complete Chapter Text
You can get the complete text for each chapter, available to readers who register at our web
site. Registration is simply and easy – we only ask for an email address. To register, click on this
When you register, you can download the available chapters from the full-text Table of
Contents, available at this link: http://www.paulyao.com/ReaderFeedback/default.aspx
. We notify
registered readers of new chapters – and chapter updates – as they become available.