Windows CE上でのShellExecuteEx呼び出し

例によって投稿の使いまわし。

Imports System.Text
Imports System.Runtime.InteropServices

Structure SHELLEXECUTEINFO
    Public cbSize As Int32
    Public fMask As Int32
    Public hwnd As IntPtr
    Public lpVerb As IntPtr
    Public lpFile As IntPtr
    Public lpParameters As IntPtr
    Public lpDirectory As IntPtr
    Public nShow As Integer
    Public hInstApp As IntPtr
    Public lpIDList As IntPtr
    Public lpClass As IntPtr
    Public hkeyClass As IntPtr
    Public dwHotKey As Int32
    Public hIcon As IntPtr
    Public hProcess As IntPtr
End Structure 

Public Class Form1
    Inherits System.Windows.Forms.Form
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu

    <DllImport("coredll")> _
    Private Shared Function ShellExecuteEx(ByRef ex As SHELLEXECUTEINFO) As Integer
    End Function

    <DllImport("coredll")> _
    Private Shared Function LocalAlloc(ByVal flags As Integer, ByVal size As Integer) As IntPtr
    End Function

    <DllImport("coredll")> _
    Private Shared Sub LocalFree(ByVal ptr As IntPtr)
    End Sub


#Region " Windows フォーム デザイナで生成されたコード "

    Public Sub New()
        MyBase.New()

        InitializeComponent()

    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        MyBase.Dispose(disposing)
    End Sub

    Private Sub InitializeComponent()
        Me.MainMenu1 = New System.Windows.Forms.MainMenu
        Me.Button1 = New System.Windows.Forms.Button
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(16, 8)
        Me.Button1.Text = "Button1"
        '
        'Form1
        '
        Me.Controls.Add(Me.Button1)
        Me.Menu = Me.MainMenu1
        Me.Text = "Form1"

    End Sub

#End Region

    Private Sub Execute(ByVal file As String, ByVal cmd As String)
        Dim fb As Byte() = Encoding.Unicode.GetBytes(file)
        Dim cb As Byte() = Encoding.Unicode.GetBytes(cmd)
        Dim pData As IntPtr = LocalAlloc(&H40, fb.Length + 1)
        Dim pVerb As IntPtr = LocalAlloc(&H40, cb.Length + 1)

        Marshal.Copy(fb, 0, pData, fb.Length)
        Marshal.Copy(cb, 0, pVerb, cb.Length)

        Dim info As New SHELLEXECUTEINFO
        With info
            .cbSize = 60
            .lpVerb = pVerb
            .lpFile = pData
            .nShow = 5
        End With

        ShellExecuteEx(info)

        LocalFree(pVerb)
        LocalFree(pData)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Execute("\windows\default.htm", "open")

    End Sub
End Class

VB6開発で気をよくして、VB.NETな質問に答えてみたり。(^^;