科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道基础软件用VB.net实现Smartphone中进程启动

用VB.net实现Smartphone中进程启动

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

近日心血来潮,花巨资购进多普达智能手机一台, 系统为微软的Smartphone2003.

作者:莫艺潜 来源:天极网 2007年12月28日

关键字:

  • 评论
  • 分享微博
  • 分享邮件
#Region "Structure STARTUPINFO"
<StructLayout(LayoutKind.Sequential)> _
Public Structure STARTUPINFO
Public cb As Int32
Public lpReserved As IntPtr
Public lpDesktop As IntPtr
Public lpTitle As IntPtr
Public dwX As Int32
Public dwY As Int32
Public dwXSize As Int32
Public dwYSize As Int32
Public dwXCountChars As Int32
Public dwYCountChars As Int32
Public dwFillAttribute As Int32
Public dwFlags As Int32
Public wShowWindow As Int16
Public cbReserved2 As Int16
Public lpReserved2 As Int32
Public hStdInput As Int32
Public hStdOutput As Int32
Public hStdError As Int32
End Structure
#End Region


#Region "Structure PROCESS_INFORMATION"
<StructLayout(LayoutKind.Sequential)> _
Public Structure PROCESS_INFORMATION
Public hProcess As IntPtr
Public hThread As IntPtr
Public dwProcessId As Int32
Public dwThreadId As Int32
End Structure
#End Region

REM api函数声明---------------------------------
#Region "Function CreateProcess"
public Overloads Declare Function CreateProcess Lib "coredll.dll" (ByVal imageName As String, _
ByVal cmdLine As String, _
ByVal lpProcessAttributes As IntPtr, _
ByVal lpThreadAttributes As IntPtr, _
ByVal boolInheritHandles As Int32, _
ByVal dwCreationFlags As Int32, _
ByVal lpEnvironment As IntPtr, _
ByVal lpszCurrentDir As IntPtr, _
ByRef si As STARTUPINFO, _
ByRef pi As PROCESS_INFORMATION _
) As Integer
#End Region

#Region "Function CloseHandle"
Public Declare Function CloseHandle Lib "CoreDll.dll" (ByVal Handle As IntPtr) As Int32
#End Region

#Region "Function WaitForSingleObjectEx"
Public Declare Function WaitForSingleObjectEx Lib "coredll.dll" (ByVal hHandle As IntPtr, _
ByVal dwMilliseconds As Int32, _
ByVal bAlertable As Int32 _
) As Int32
#End Region

#Region "Function ShellExecuteEx"
Public Declare Function ShellExecuteEx Lib "coredll.dll" (ByRef lpExecInfo As SHELLEXECUTEINFO) As Int32
#End Region

  下面是一个简单示例,启动手机中的计算器程序,步骤如下:

  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)。有问题可以 和我联系:missilecat@163.com。

查看本文来源

    • 评论
    • 分享微博
    • 分享邮件
    邮件订阅

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章