|
|
|
|
|
Home
»
VB.NET
»
Invoking Unmanaged DLL Functions from Compact Framework for Pocket PC
|
|
|
Author Rank:
|
|
Total page views :
7822
|
|
Total downloads :
93
|
|
|
|
|
Download
Files:
|
|
|
|
|
|
|
|
|
|
|
|
|
Similar ArticlesMost ReadTop RatedLatest
|
|
|
|
|
|
|
|
|
|
In this example we will use the Compact Framework to create a program containing a launch pad for the Pocket PC. Our program will provide an integrated interface to launch some of the common programs on the Pocket PC. This sample serves to demonstrate the use of the Pinvoke mechanism on the Pocket PC to launch external programs such as Internet Explorer and Calculator. This example can be extended to create a convenient toolbox for launching frequently used Pocket PC programs.
The Compact Framework does not have complete support for COM Interop and interoperating with ActiveX controls. It provides the Platform Invoke mechanism for calling unmanaged DLLs. We will explore this functionality more in detail in this example.
The complete code listing along with sample screenshots follow.
The core of our example consists of using C# 's DLLImport attribute to access the "CreateProcess" function from the unmanaged DLL coredll.dll. This function is invoked in the program to launch the program as specified in the parameters.

Figure: Launchpad Application in Action

Figure: PocketPc.com site opened from the LaunchPad program through a single button click
Complete Code Listing
Imports System Imports System.Drawing Imports System.Collections Imports System.Windows.Forms Imports System.Data Imports System.Runtime.InteropServices Public Class Form1 Inherits System.Windows.Forms.Form Private button1 As System.Windows.Forms.Button Private button3 As System.Windows.Forms.Button Private button2 As System.Windows.Forms.Button Private button4 As System.Windows.Forms.Button Private button5 As System.Windows.Forms.Button Private mainMenu1 As System.Windows.Forms.MainMenu #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) MyBase.Dispose(disposing) End Sub 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Private Sub InitializeComponent() Me.mainMenu1 = New System.Windows.Forms.MainMenu Me.button1 = New System.Windows.Forms.Button Me.button3 = New System.Windows.Forms.Button Me.button2 = New System.Windows.Forms.Button Me.button4 = New System.Windows.Forms.Button Me.button5 = New System.Windows.Forms.Button 'button1 Me.button1.Location = New System.Drawing.Point(40, 16) Me.button1.Size = New System.Drawing.Size(96, 32) Me.button1.Text = "PocketPc.Com" AddHandler button1.Click, AddressOf button1_Click 'button3 Me.button3.Location = New System.Drawing.Point(40, 64) Me.button3.Size = New System.Drawing.Size(96, 32) Me.button3.Text = "IE" AddHandler button3.Click, AddressOf button3_Click 'button2 Me.button2.Location = New System.Drawing.Point(40, 112) Me.button2.Size = New System.Drawing.Size(96, 32) Me.button2.Text = "Calculator" AddHandler button2.Click, AddressOf button2_Click 'button4 Me.button4.Location = New System.Drawing.Point(40, 160) Me.button4.Size = New System.Drawing.Size(96, 32) Me.button4.Text = "Calendar" AddHandler button4.Click, AddressOf button4_Click 'button5 Me.button5.Location = New System.Drawing.Point(40, 208) Me.button5.Size = New System.Drawing.Size(96, 32) Me.button5.Text = "Tasks" AddHandler button5.Click, AddressOf button5_Click 'Form1 Me.Controls.Add(Me.button5) Me.Controls.Add(Me.button4) Me.Controls.Add(Me.button2) Me.Controls.Add(Me.button3) Me.Controls.Add(Me.button1) Me.Menu = Me.mainMenu1 Me.Text = "Form1" End Sub Shared Sub Main() Application.Run(New Form1) End Sub 'Main #End Region Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) ShowPPCWebSite() End Sub Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) StartCalc() End Sub Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) StartIE() End Sub Private Sub button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) StartCalendar() End Sub Private Sub button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) StartTasks() End Sub Private Declare Function CreateProcess Lib "coredll.Dll" (ByVal strImageName As String, ByVal strCmdLine As String, ByVal pProcessAttributes As IntPtr, ByVal pThreadAttributes As IntPtr, ByVal bInheritsHandle As Integer, ByVal dwCreationFlags As Integer, ByVal pEnvironment As IntPtr, ByVal pCurrentDir As IntPtr, ByVal bArray() As [Byte], ByVal oProc As ProcessInfo) As Integer Private Sub ShowPPCWebSite() Dim pi As New ProcessInfo CreateProcess("iexplore.exe", "www.microsoft.com/mobile/pocketpc/default.asp", IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, New [Byte](128) {}, pi) End Sub 'ShowPPCWebSite Private Sub StartIE() Dim pi As New ProcessInfo CreateProcess("iexplore.exe", "", IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, New [Byte](128) {}, pi) End Sub 'StartIE Private Sub StartCalc() Dim pi As New ProcessInfo CreateProcess("calc.exe", "", IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, New [Byte](128) {}, pi) End Sub 'StartCalc Private Sub StartCalendar() Dim pi As New ProcessInfo CreateProcess("calendar.exe", "", IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, New [Byte](128) {}, pi) End Sub 'StartCalendar Private Sub StartTasks() Dim pi As New ProcessInfo CreateProcess("tasks.exe", "", IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, New [Byte](128) {}, pi) End Sub 'StartTasks End Class Public Class ProcessInfo Public Process As Integer Public Thread As Integer Public ProcessID As Integer Public ThreadID As Integer End Class 'ProcessInfo
NOTE:
This article is purely for demonstration. This article should not be construed as a best practices white paper. This article is entirely original, unless specified. Any resemblance to other material is an un-intentional coincidence and should not be misconstrued as malicious, slanderous, or any anything else hereof.
Conclusion:
In this article, we explored the code to launch external applications on Pocket PC using Pinvoke and unmanaged DLLs. I would like to give credit to Scott Swigart for his valuable inputs on support newsgroups.
|
|
|
Login
to add your contents and source code to this article
|
|
|
|
|
|
|
|
Dipal Choksi
Dipal Choksi has over 10 years of industry experience in team-effort projects and also as an individual contributor. She has been working on the .Net platform since the beta releases of .Net 1.0.
|
|
|
|
|
|
|
|
|
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.
|
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.
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|