VSD FAQ
Sticky
-
Friday, May 07, 2010 3:01 AM
We are happy to announce the release of our first wave of FAQs for Smart Device Development. These FAQs are aimed at helping developers find answers to frequentlyasked questions in forum more easily and effectively. They cover the main areas of the smart device development, from native C++ to managed .NET CF, from emulators to devices. The topics are grouped into their most related sub-forum.
Thanks to Ilya, Christopher, Alex, Michael and many others for your efforts and contributions to the Smart Device Forums, and the useful contents in the FAQs. Additionally, thanks to everyone who has contributed to these FAQs and the Smart Device Forums.
Contents
1. What tools do I need to develop applications for smart devices?
2. How to play video and audio files?
3. What is supported by Compact WCF?
4. How can I add Design-Time Support to my custom controls?
5. How to develop an application that is Resolution-Aware and Orientation-Aware?
7. I have trouble developing the Kiosk Mode application in Windows Mobile.
8. I've got questions on ASP.NET applications for smart devices.
9. There is no relative paths or driver letters in Windows Mobile/CE
10. How do I detect the platform and Windows Mobile version?
11. How do I extend the existing controls in the .NET Compact Framework?
12. How do I develop Bluetooth applications for smart devices in .NET CF?
13. How do I use VS2005 in Windows Vista/7 for smart device development?
14. Why do I often get OOM exceptions when handling bitmaps?
All Replies
-
Friday, May 07, 2010 3:03 AM
1. What tools do I need to develop applications for smart devices?
In order to develop applications for smart devices, you need to use Visual Studio 2005 standard edition or above with SP1, or Visual Studio 2008 professional edition or above. All express editions do not support mobile development.
In addition, the Windows Mobile 6 SDK needs to be installed before you can create projects for the Windows Mobile 6 platform. The order to install them is:
1.Uninstall WM6 SDK if previously installed
2.Install VS 2008
3.Install WM6 SDK
Related Thread:
http://social.msdn.microsoft.com/forums/en-US/windowsmobiledev/thread/090261cd-2e2b-4649-ad75-61dbe5a23c8f/ -
Friday, May 07, 2010 3:04 AM
2. How to play video and audio files?
You can use the SystemSound class to play a system sound in .NET CF 3.5. To play wav audio files, you can P/Invoke the PlaySound or the SndSetSound function. There is even a SoundPlayer class added in the .NET CF 3.5 so you can play wav audio easily.
When you need to play mp3 or wmv audio files, you will find that there is no API to play those formats in the FCL. The easiest way to go is to let the shell do it for you:
Code Sample:
string path = "path to the audio file";
ProcessStartInfo info = newProcessStartInfo() { FileName = path, UseShellExecute = true};
Process.Start(info);
Another option is to use the wmp.dll. First add the C:\windows\system32\wmp.dll as a reference for your project. Then use the following code to play the file:
Code Sample:
WMPLib.WindowsMediaPlayer player = newWMPLib.WindowsMediaPlayer();
player.URL = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
+ "\\song.mp3";
player.settings.volume = 100;
player.controls.play();
For video files, you can let the shell handle them for you too. When you need to embed a media player control into your form, the easiest way is to use 3rd party media player controls, such as the OpenNETCF Media Player Controls.
Another way is to create the player control yourself, as shown in the following article, however it's not easy:
Hosting ActiveX Controls in Compact Framework 2.0 Applications
Related Thread:
http://social.msdn.microsoft.com/forums/en-US/vssmartdevicesvbcs/thread/4e35bad0-9eae-4ed8-ada5-bd249411fa1f/ -
Friday, May 07, 2010 3:05 AM
3. What is supported by Compact WCF?
With the release of .NET Compact Framework 3.5, a subset of Windows Communication Foundation (which is called Compact WCF), has been added to .NET CF. Since it is a subset, you shouldn't expect all features in desktop WCF. In particular, the server side is not supported.
To get the detailed features supported by Compact WCF, please refer to following links:
The WCF subset supported by NetCF
Messaging in the .NET Compact Framework -
Friday, May 07, 2010 3:07 AM
4. How can I add Design-Time Support to my custom controls?
The pattern of the design-time support for Windows Forms controls in .NET CF is different from that of the desktop in that it separates the runtime code and the design-time code into different assemblies. The assembly that contains the design-time support is built for desktop, and an xml file (.xmta) is used to configure design-time support. In fact you will find the pattern used in .NET CF is quite similar to that of WPF if you are familiar with it.
The resources for design-time support are limited, here are a couple of related links:
Creating a Custom Control (Visual C#)
MSDN Webcast: Creating Custom Controls for Managed Code in Visual Studio 2005 (Level 200) (Download Sample)
Related Thread:
http://social.msdn.microsoft.com/forums/en-US/netfxcompact/thread/cbffc07a-5639-4c57-9e7d-1dc344a72ae5/ -
Friday, May 07, 2010 3:08 AM
5. How to develop an application that is Resolution-Aware and Orientation-Aware?
Allowing your applications to become adaptable to different form factors and different orientations is an exciting feature. There is an "Adapt Your App" initiative that will help you develop such applications.
Here are some helpful articles regarding this topic:
Step by Step: Developing Orientation-Aware and Resolution-Aware Windows Mobile-based Applications in Native Code(It's native but should not prevent you from getting the idea.)
Developing DPI-Aware Applications
Related Thread:
http://social.msdn.microsoft.com/forums/en-US/netfxcompact/thread/13c4e7be-4172-4846-92e2-9d390ab962f4/ -
Friday, May 07, 2010 3:10 AM
The MessageInterceptor class is capable of intercepting an SMS that meets certaincriteria, then you can delete it directly, or allow the message to be copied into your application.
You can even allow your application to be launched automatically on the arrival of an SMS, as shown in the sample code of the following blog entry:
http://www.peterfoot.net/UsingMessageInterceptorToLaunchAnApplicationOnSMS.aspx
Sometimes, if you are not satisfied with the functions exposed by the MessageInterceptor class, you can create a native Message Rule Client which implements the IMailRuleClient interface, as explained in the following article:
Receiving SMS Messages Inside a Managed Application -
Friday, May 07, 2010 3:11 AM
7. I have trouble developing the Kiosk Mode application in Windows Mobile.
The Windows Mobile platform does not support a Kiosk mode application. That's by design and if you are trying to build one on it you will have to wrestle with some problems, for example the taskbar may flicker when switching forms.
Related Thread:
Supporting Kiosk-Applications on Windows Mobile ("Technically achievable" vs. "supported")
Windows CE Kiosk Mode - Part 11
Create a Windows CE Image That Boots to Kiosk Mode -
Friday, May 07, 2010 3:11 AM
8. I've got questions on ASP.NET applications for smart devices.
There is a dedicated forum for ASP.NET applications targeting mobile devices:
I believe you can get better help there. -
Friday, May 07, 2010 3:13 AM
9. There are no relative paths or driver letters in Windows Mobile/CE
Windows Mobile/CE does not support relative paths. In other words, there is no concept of “current directory”. All paths are relative to the root directory represented with “\”. Hence, you should always use the full path to a file starting with the root folder “\”, such as “\full\path\to\a\file.txt”.
If you use File.OpenText(“test.htm”) in your application, it does not look for the file in the current directory or application folder; instead it looks for it in the root folder “\”. Therefore, the path “text.htm” is equivalent to “\text.htm”. For clearance, we recommend that you use the latter (starting with the root folder “\” explicitly).
In order to open a file in the application folder, you need to get the full path of the application folder, and then combine it with the file name. The following code snippet will show you the idea:
Code Sample:
string appFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
string filePath = Path.Combine(appFolder, "filename.txt");
As all paths are relative to the root directory, there is no driver letters in Windows Mobile/CE. When you run an application on a device, it opens files on the device rather than those on the desktop PC. So you can never use paths like “C:\some\file.txt” or “D:\some\file.txt” in a smart device application.
Related Threads:
http://social.msdn.microsoft.com/Forums/en/vssmartdevicesvbcs/thread/93f2377c-281a-4c0a-be1c-93ba2b3118c6
http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesnative/thread/376f5ec9-d206-49c7-8922-8f6ba35e9b0b
http://social.msdn.microsoft.com/Forums/en/vssmartdevicesvbcs/thread/0ddcf92f-3c52-4edf-a8b0-6e90847d11c2 -
Friday, May 07, 2010 3:14 AM
10. How do I detect the platform and Windows Mobile version?
To determine whether the application is running on a desktop PC or a Windows CE based device, you can use the Environment.OSVersion property. The following code snippet shows how to use the property:
Code Sample:
if (Environment.OSVersion.Platform == PlatformID.WinCE)
{
//The OS is Windows CE or Windows Mobile.
}
The OSVersion property can also tell you the version of Windows CE on the device. You can get the same information by calling the native GetVersionEx function or the SystemParameterInfo function with SPI_GETPLATFORMVERSION flag.
Regarding how to differentiate Windows Mobile (WM) from CE: In .NET Compact Framework 3.5 there is a new property ‘SystemSettings.Platform’ which has this information. This property can have three values - WinCEGeneric, PocketPC or Smartphone. For an earlier version of .NET CF, we can P/Invoke the SystemParametersInfo function with the SPI_GETPLATFORMTYPE flag. If the return value is “PocketPC”, then it is a Windows Mobile Professional or Classic device; if the return value is “SmartPhone”, then it is a Windows Mobile Standard device.
How does one get the version of Windows Mobile? As we know, Windows Mobile is based on Windows CE, but the version of Windows Mobile does not equal to the version of Windows CE. For example, WM 5.0 is based on CE 5.1; WM 6.0 is based on CE 5.2. You can find more information about the relationship of WM and CE in the following page:
Versions of Windows CE / Windows Mobile
Things become more complicated if you want to differentiate WM 6.0 from WM6.1 or WM6.5, as they all based on CE 5.2. In this case, we need to compare the Build number or AKU number, as each version has its own range of Build number or AKU number. The AKU is saved in the “Aku” value under the registry key [HKLM\SYSTEM\Versions]. The relations of WM and their associated AKUs and Build numbers are listed in the following wiki page:
List of known Adaptation Kit Update (AKU) releases and their associated build number
Related Threads:
http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesnative/thread/80b986eb-d6cd-4342-802a-936e42085bc7 -
Friday, May 07, 2010 3:15 AM
11. How do I extend the existing controls in the .NET Compact Framework?
The Windows Forms controls in .NET Compact Framework (.NET CF) are designed to run on resource-constrained devices, so they are limited in number and functionality (methods, properties and events) compared with Windows Forms on desktop.
The first way to create new controls or extend the existing controls is making Custom Controls. You can find more information from the following pages:
Custom Control Development
http://msdn.microsoft.com/en-us/library/4yf3whkx.aspx
How to Create a Microsoft .NET Compact Framework-based Image Button
http://msdn.microsoft.com/en-us/library/aa446518.aspxRegarding how to add design-time support for custom controls, please refer to a former FAQ: How can I add Design-Time Support to my custom controls?
Sometimes you may find that, some functions available in native Windows controls are not exposed by .NET CF. For example you may want to process a message but find that there is no associated event. The desktop Windows Forms allows you to override WndProc method, however it is not supported by .NET CF. To process native Windows message in .NET CF you need to use a technique called “subclassing”. The articles below will show you how to use this technique:
Interop: Extending GUI Functionality
http://blogs.msdn.com/netcfteam/archive/2005/07/24/442616.aspx
Subclassing Controls with a Managed Window Procedure
http://msdn.microsoft.com/en-us/library/ms229681.aspx
Add Keyboard Support to Compact Framework Apps by Trapping Windows Messages
http://msdn.microsoft.com/en-us/magazine/cc188736.aspx
An example of using the “subclassing” technique is to create owner-drawn controls and custom-drawn controls in .NET CF. This is useful when you want to draw the list items of some list controls in your own way. Nevertheless, subclassing is a not quite an easy way, so you may choose to create a custom control instead, or simply use some ready-made controls. Here are some articles on creating owner-drawn list controls:
How to: Create an Owner-Drawn List Box
http://msdn.microsoft.com/en-us/library/ms229679.aspx
Step by Step: Implement Style List Controls by Using the .NET Compact Framework on Smartphone
http://msdn.microsoft.com/en-us/library/ms839421.aspx
Creating Owner-drawn List Controls in the .NET Compact Framework
http://www.opennetcf.com/Default.aspx?tabid=120%20
Lastly, the following article will show you how to paint the cells of a Datagrid control by overriding its OnPaint method:
.Net Compact Framework V2 Service Pack 1 Data Grid control enhancements.
http://blogs.msdn.com/netcfteam/archive/2006/04/25/583542.aspx -
Friday, May 07, 2010 3:17 AM
12. How do I develop Bluetooth applications for smart devices in .NET CF?
Microsoft provides a shared-source library to help managed developers develop Bluetooth application much more rapidly than using native APIs. The library is Windows Embedded Source Tools for Bluetooth Technology, which is a wrapper over native APIs. The library can expose Bluetooth services, enumerate devices or services, and connect to services. The following wiki page on Channel 9 can get you started quickly:
http://channel9.msdn.com/wiki/default.aspx/Channel9.BluetoothDevelopment
A sample called SpaceWar2D in the Windows Mobile 5/6 SDK describes how to use that library. You can find the sample in the following folder:
%Program Files%\Windows Mobile 5 or 6 SDK\Samples\Common\CS\Bluetooth\SpaceWar2D
There is also a third party Bluetooth library called 32Feet.NET. The library is also a shared source project hosted at CodePlex:
http://www.codeplex.com/32feet/
Since managed wrappers are already there, it is best that you do not need to go for Win32 API yourself. Nevertheless, I list the resources for developing native Bluetooth applications in case you need it:
Bluetooth Application Development
http://msdn.microsoft.com/en-us/library/aa916530.aspx -
Friday, May 07, 2010 3:18 AM
13. How do I use VS2005 in Windows Vista/7 for smart device development?
Visual Studio 2005 (VS2005) has known compatibility issues with Windows Vista/7. If you want to use VS2005 on Windows Vista, the first two things you need to do are:
1. Make sure you install Visual Studio 2005 Service Pack 1 and Visual Studio 2005 Service Pack 1 Update for Windows Vista.
2. Run VS2005 as Administrator. To do so, right click on the shortcut to VS2005 and then select "Run as Administrator. Note that this operation is not equivalent to logging in as an administrator. For more information please read the following article about User Account Control (UAC):
Understanding and Configuring User Account Control in Windows Vista
http://technet.microsoft.com/en-us/library/cc709628(WS.10).aspxThe known issue list and more other information are available in the following page:
Visual Studio on Windows Vista and Windows 7
http://msdn.microsoft.com/en-us/vstudio/aa948853.aspxVisual Studio 2008 and later has much better support for Windows Vista/7, so you may also consider upgrading your Visual Studio. You do not need to run VS2008 as administer on Windows 7/Vista. If you do so, you may find that remote tools cannot connect to an emulator started by VS2008. The error message is as follows:
Error: The current VMID is in use. Wait for the other application to exit.
To solve the problem, make sure the remote tool and Visual Studio have the same privilege. In other words, make sure both are elevated (i.e. run as administrator), or neither are.
When you try to run Cellular Emulator on 64-bit version of Windows Vista/7, the following error occurs:
There are not seven pairs of XPVCOM in system.
That is because the Cellular Emulator does not support x64 OS for now. -
Friday, May 07, 2010 3:18 AM
14. Why do I often get OOM exceptions when handling bitmaps?
Many users use large bitmaps in their applications but do not aware that bitmaps in .NET CF are uncompressed in memory, so they can consume a lot of memory. Besides, there is a 32M virtual memory limitation for devices prior to Windows CE 6.0. Therefore, using large bitmaps carelessly in your application often leads to OutOfMemoryException (OOM).
Below are some recommendations of using bitmaps:
1. Release the bitmap objects as soon as possible to free memory. To do that, call Bitmap. Dispose or remove the reference to the bitmap object after you no longer need the object. For more information about an object’s lifetime please refer to the following article:
Managing Object Lifetime
http://msdn.microsoft.com/en-us/magazine/cc163316.aspx
2. Do not load very large bitmaps into memory. Instead, load a thumbnail of a proper size according to the screen resolution of the target device. The Imaging API IImage::GetThumbnail can create a thumbnail for an image file. A managed wrapper of this API is OpenNETCF.Drawing.ImageUtils.CreateThumbnail in OpenNETCF’s SDF.
3. If you have already encountered OOM exceptions, the .NET CF Remote Performance Monitor tool can help you find the cause. The tool is included in Power Toys for .NET Compact Framework 3.5. Here is an introduction:
Finding Managed Memory leaks using the .Net CF Remote Performance Monitor
Related Threads: http://social.msdn.microsoft.com/forums/en-US/vssmartdevicesvbcs/thread/bb1acd62-e11d-4617-ac28-4a301aa817c2/
http://social.msdn.microsoft.com/Forums/en-US/netfxcompact/thread/8236a973-f61b-4689-b875-8b8cdff32df5/

