The following code sample shows how to Invoke Unmanaged DLL Functions from Compact Framework for Pocket PC
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
|
No responses found. Be the first to respond and make money from revenue sharing program.
|