How To Determine if a Previous Instance of an eVB Application Is Being Run (258088)



The information in this article applies to:

  • Microsoft eMbedded Visual Basic 3.0

This article was previously published under Q258088

SUMMARY

The PrevInstance method of the App object is not supported in eMbedded Visual Basic (eVB) at this time. The CreateMutex API function call can be used to ensure that only a single instance of an eVB application is running on a Windows CE-based device.

MORE INFORMATION

Step-by-Step Example

The code in this example illustrates the use of CreateMutex.
  1. Create a new Windows CE project in eMbedded Visual Basic. Form1 is created by default.
  2. Paste the following code into Form1:
    Option Explicit
    Const ERROR_ALREADY_EXISTS = 183
    
    Public Declare Function CreateMutex Lib "Coredll" Alias "CreateMutexW" _
       (lpMutexAttributes As Long, _
       ByVal bInitialOwner As Long, _
       ByVal lpName As String) As Long
    
    Public Declare Function GetLastError Lib "Coredll" () As Long
    
    Private Sub Form_Load()
    
     Dim error_code
    
     CreateMutex CLng(0), 1, App.Title
     If GetLastError() = ERROR_ALREADY_EXISTS Then
       MsgBox "Already running", vbOKOnly, App.Title
       App.End
     Else 'run the application
       MsgBox "OK to run"
     End If
    End Sub
    					
  3. Run the project, and target the remote device. Note that a message box appears that indicates that the application can be run.
  4. While the application is still running, start it a second time from the device. By default, it exists in the "My Handheld Device" root.
  5. Note that the application determines that an instance is already being run.

Modification Type:MinorLast Reviewed:7/1/2004
Keywords:kbAPI kbhowto kbToolkit KB258088