Blue Theme Orange Theme Green Theme Red Theme
 
ANTS Performance Profiler 6.0
Home | Forums | Videos | Photos | Blogs | Beginners
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
ANTS Performance Profiler 6.0
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » VB.NET » Using the .NET compact Framework in VB.Net

Using the .NET compact Framework in VB.Net


In this article, we will see how to write a simple .NET Compact Framework application and deploy it onto a device. This article provides a step-by-step instruction on how to write the application.

Total page views :  21471
Total downloads : 
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Become a Sponsor

Microsoft created the .NET Compact Framework for one single reason. To develop applications!! The .NET Compact Framework is used to develop applications for smart devices. By smart devices we mean devices that run the Pocket PC 2000, Pocket PC 2002 and Windows CE.NET operating systems. These operating systems are targetted for mobile devices (like PDA, Pocket PC) that have small display areas, small storage areas and run on batteries.

Developing applications for devices has never been easier! Earlier, people had to grapple with the eMbedded Visual Tools kit from Microsoft. This toolkit essentially consists of an operating system and development tools like embedded Visual Basic and embedded Visual C++). Application also had to deal with different programming models and understand and work with the API of the operating system. With the advent of the .NET Compact Framework, Microsoft has unified the programming models between developing applications for PC's and applications for devices. The .NET Compact Framework provides a managed execution environment for applications on devices and makes writing applications extremenly easy.

In this article, we will see how to write a simple .NET Compact Framework application and deploy it onto a device. This article provides a step-by-step instruction on how to write the application.

The .NET Compact Framework.

The .NET Compact Framework is a subset of the functionality found in the .NET Framework. Major portions of the .NET Framework were removed, since these did not make sense in the devices world. When we say removed, it does not mean that the code was simply cut-off and the remaining code got renamed as Compact Framework :-) Microsoft re-wrote large chunks of the code to take into account the form factor of small devices.

Common Language Runtime.

The CLR is the most important part of the .NET Compact Framework. It is responsible for taking a .NET assembly and then setting up an application domain for it to run. A native just-in-time (JIT) compiler is used to compile the MSIL code to the actual machine bits. The CLR provides the services of memory management, garbage collection and class loading. The CLR also manages the security structure in which the application executes.

The CLR consists of two parts. One is the direct execution engine which is responsible for execution of the code and the other is the base class libraries which is a set of reusable classes that contain a basic set of building blocks that applications can use. The following figure shows a typical contruction of the .NET Compact Framework.

The diagram is pretty straight forward.

  1. Applications, device libraries and base class libraries occupy the managed space. The CLR provides the execution environment for these applications along with a set of base services.

  2. The execution engine itself is a native executable, as is the Platform Adaptation Layer which is an abstration between the execution engine and the underlying operating system. These two layers are packaged as a single executable called MSCOREE.

In the .NET Compact Framework, there is one implementation of the MSCOREE for each of the supported processors. If future platforms become available with more capabilities, it is only the PAL that needs to be changed, since it contains platform specific features that will change between each hardware.

Features Missing From .NET Compact Framework.

As mentioned earlier, the .NET Compact Framework is a subset of the full .NET Framework and major sections were ignored because they implemented features that were specific to the PC platform, which did not make sense in the device world. The following is a brief summary of the features that are excluded from the .NET Compact Framework.

  1. No application configuration files.
  2. No support for COM Interop.
  3. No support for remoting.
  4. No support for printing.
  5. No support for the SoapFormatter or the BinaryFormatter classes.
  6. No support for XPath and XSLT.
  7. No support for the System.Web namespace.

Ok, enough of basics!! Entire books have been written on the Compact Framework, but we don't have space for it. So let's start writing a simple application.

Availability of .NET Compact Framework.

Visual Studio .NET includes all the capabilities that allow you to write and debug a device application (called Smart Device Extensions). You use all the tools and techniques that are available for developing normal application when writing device applications too. Instead of using the .NET Framework class libraries, you use the Compact Framework specific libraries.

Note that as of now, the .NET Compact Framework supports only the Visual Basic.NET and the C# language.

Developing a Sample Application.

Let us now see the steps in developing a simple application using the .NET Compact Framework. We will write an application that displays a simple message to the user. Since you might not have access to an actual device, we will see how to write and deploy an application to the emulator that is supplied with Visual Studio .NET.

Step - 1: Creating the Project.

The first step in creating a device application is to select the appropriate project type. A device project in Visual Studio .NET is called a Smart Device Extensions project. You need to select this project and provide a name for it, as shown in the following figure.

After deciding the application name, click on the [Ok] button.

Step - 2: Deciding the Profile.

After deciding the application name, Visual Studio provides a set of device profiles. A device profile is a set of project types targetted for a specific platform. The profile dialog box allows you to select the profile that you want to use, as shown in the following figure.

Here, select the Pocket PC platform and the Windows Application project. This means that we
are targetting the Pocket PC platform and we are going to write a windows application. After
making the selection, click on the [Ok] button.

Step - 3: Design the Application.

After deciding the target environment and the type of application, all that is left is to design
the application. Note that based on your selection, Visual Studio .NET might display different
design environments. For our selection of Pocket PC/Windows application, the following interface
is shown:

Note that the design surface is very similar to that of a desktop application. You simply drag and drop the appropriate controls onto the design surface. The final interface will be as shown:

Note that you use very similar controls to that of the desktop application. It is recommended thatyou do not resize the form, since Visual Studio .NET has decided the interface size based on the device profile that you selected. Now let's write some code to:

  1. Populate the combo-box with some values.
  2. Display some text when the button is clicked.

Here is the source code for these actions.

Private Sub frmTest_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
ComboBox1.Items.Add("Robin Cook")
ComboBox1.Items.Add("Wilbur Smith")
ComboBox1.Items.Add("J.K. Rowling")
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim strResult As String = Nothing
strResult = "You Entered:" & System.Environment.NewLine
strResult = strResult & TextBox1.Text & System.Environment.NewLine & System.Environment.NewLine
strResult = strResult & "You Selected:" & System.Environment.NewLine
strResult = strResult & ComboBox1.SelectedItem
MessageBox.Show(strResult, "Message", MessageBoxButtons.OK)
End Sub

You can see that the code is very similar to that of a desktop application. That's that commanality you have between desktop applications and device applications. Amazing!!

Step - 4: Executing the Application.

Having written the application, the final step is to execute the application. Choose the execute button. You are now presented with the following dialog box:

Here, you choose the deployment options. You can decide to deploy to either an emulator or to the actual device. We will choose the emulator. Now begins the interesting part!! The emulator is launched and the application deployment starts. Since the application uses the .NET Compact Framework libraries, the .NET Compact Framework is deployed first, as shown in the following figure.

Where does Visual Studio .NET get the files for the .NET Compact Framework?? You can see all the relevant files at the following location: C:\Program Files\Microsoft Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows CE. Below this folder you will see the various version of the Windows CE operating system and within these folders, the relevant files for the various processors are present. After the relevant dependent files are installed, the actual application files are copied over and the application is started as shown in the following figure.

Note that once we click the button, we get a meesage box informing us about our selection. One immediate thing that you would have noticed while working with the application is that there is no tab key to move between fields. This is one of the challenges of developing for a device. We need to keep in mind that the only entry method for users is a stylus pen, thus they have to tap through the various fields of the interface.

OK, we are done!! When you close the emulator, you are given the option to either Save the emulator state or to Turn off the emulator. Each option has its own advantages.

  1. When you choose Save the emulator state, any installation that Visual Studio .NET did (for example the .NET Compact Framework) is retained. Thus, when you re-execute a project, these files are not deployed again.

  2. When you choose Turn off the emulator, we are essentially resetting the machine. Thus, all files will be re-deployed everytime to execute it.

Note that everytime you Save the emulator state and you close your application (by clicking on the (x) icon), the application is actually not closed, but rather pushed into the background. Thus you need to stop this application from running, otherwise, you will not be able to deploy the application again (you will get a sharing violation error). To stop the application from running, choose Start / Settings / System / Memory / Running Programs and then click the application that you want to stop and click the [Stop] button. This is shown in the following figure:

Ok, that was an interesting journey :-) One other thing to keep in mind is to definitely test your application with an actual device before deploying it into production. This is important because, the emulator is not the actual representation of how an application might execute in real time. You need to remember that an emulator actually executes in your desktop PC, which is more powerful than the actual device. Also, when working with the emulator, you have access to the keyboard, but in the real-world the user only has a stylus. Thus you should not develop interfaces that have too many input fields.

Conclusion.

In this article we have seen how to use the .NET Compact Framework to develop a simple application and also how to deploy the application onto the device. The Visual Studio .NET development environment provides a very productive IDE for developing smart-device applications and also provides excellent emulation and debugging support. There are many different types of applications that you can write using the .NET Compact Framework and this hopefully helped you make a start. Have fun!!


Login to add your contents and source code to this article
 About the author
 
Srinivas Sampath
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
SQL and .NET performance profiling in one place
Investigate SQL and .NET code side-by-side with ANTS Performance Profiler 6, so you can see which is causing the problem without switching tools.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
60 FREE UI Controls from DevExpress
Register for your FREE copy on over 60 free presentation controls from DevExpress - Absolutely Free-of-Charge without any royalties or distribution costs. Visit Devexpress.com/60 today. Free controls include advanced lists box, dropdown calendar, rich text edit, spin edit, tab control and so much more!

DevExpress engineers feature rich presentation controls and reporting tools for WinForms, ASP.NET, WPF, and Silverlight. Our technologies help you build your best, see complex software with greater clarity and deliver compelling business solutions for Windows and the web in the shortest possible time.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010
Visualize your workspace with new multiple monitor support, powerful Web development, new SharePoint support with tons of templates and Web parts, and more accurate targeting of any version of the .NET Framework. Get set to unleash your creativity.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Developer-Ready ASP.NET 2.0 Web Hosting with 3 MONTHS FREE
Now supporting .NET 3.0 Framework with Windows Workflow Foundation, Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), windows CardSpace (WCS)! Providing more flexibility for Developers with Web Services Support and a User/Permission Manger. Also supporting MS SQL 2005/2000 with Real-Time Backups, FREE Automated Attach .MDF Tool, FREE SQL Restore and Shrink SQL DB Tools, and SQL
Read the Top 10 Books for Microsoft Developers, 15 Days FREE
Read the Top 10 Books for Microsoft Developers, 15 Days FREE
Try Safari Books Online - 15 Days FREE + 15% Off for 1 Year
Try Safari Books Online - 15 Days FREE + 15% Off for 1 Year
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Nevron Chart
Become a Sponsor
 Comments
Using the .NET compact Framework in VB.Net by ram On August 11, 2007
Dear Sir; Can you please expain step by step on how to connect to sqlserver 2005. I'm using visual studio 2005
Reply | Email | Delete | Modify | 
connecting pocket pc to database through wireless lan by bernardine On October 5, 2007
hello, is it possible to develop an application for pocket pc wherein it will have to connect to a database through wireless lan?
Reply | Email | Delete | Modify | 
programming vb.net with pocket pc by vutha On October 22, 2008
How to connect form vb.net to sql server
Reply | Email | Delete | Modify | 
ANTS Performance Profiler 6.0
 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2010.8.14
 © 2010  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.