以下是一个简单示例,启动手机中的计算器程序,步骤如下:
1、启动VS.net2003,选Visual Basic 项目,在右边的列表中选智能设备应用程序,在下一个对话框中针对什么平台选Smartphone,类型选Windows应用程序。
2、将上面介绍的辅助类及API声明的代码做成两个模块。
3、为在form1的代码模块顶部加入如下语句:
Imports System.Runtime.InteropServices
4、在 Form1的 load事件中加入启动计算器的代码如下:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim tudtShellExecuteInfo As New SHELLEXECUTEINFO Dim tstrExecutePath As String Dim tudtStartupInfo As STARTUPINFO Dim tudtProcessInfo As PROCESS_INFORMATION Dim tlngTempa As Int32
With tudtStartupInfo .cb = Marshal.SizeOf(GetType(STARTUPINFO)) End With
With tudtShellExecuteInfo .cbSize = Marshal.SizeOf(GetType(SHELLEXECUTEINFO)) .lpFile = clsDAMSMobileMarshal.fnStringToHLocalUni("\windows\calc.exe") .lpParameters = IntPtr.Zero '不使用参数,如使用参数可按lpFile的方法申请字符串指针 End With tlngTempa = ShellExecuteEx(tudtShellExecuteInfo) '启动程序
tudtShellExecuteInfo.Dispose() If tlngTempa = 0 Then '使用shellexecuteex失败,试图使用createprocess再打开试试 tlngTempa = CreateProcess("\windows\calc.exe", "\windows\calc.exe", IntPtr.Zero, IntPtr.Zero, _ 0, 0, IntPtr.Zero, IntPtr.Zero, tudtStartupInfo, tudtProcessInfo) If tlngTempa <> 0 Then Call CloseHandle(tudtProcessInfo.hThread) Call CloseHandle(tudtProcessInfo.hProcess) End If End If End Sub | 以上就是VB.net中启动Smartphone中的应用程序的常规方法,代码在本人的计算机上测试通过,本人的计算机系统配置为WIN2000 高级服务器版+Visual Studio 2003(完全安装)+Smartphone 2003 SDK(开发Smartphone应用程序必备,在微软的网站可以下载,微软提供的免费软件啊!我喜欢8-),网址如下: http://msdn.microsoft.com/mobility/downloads/sdks/default.aspx)。
|
|