Microsoft KB Archive/258088

= How To Determine if a Previous Instance of an eVB Application Is Being Run =

Article ID: 258088

Article Last Modified on 7/1/2004

-

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.



Step-by-Step Example
The code in this example illustrates the use of CreateMutex.  Create a new Windows CE project in eMbedded Visual Basic. Form1 is created by default.  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  Run the project, and target the remote device. Note that a message box appears that indicates that the application can be run. While the application is still running, start it a second time from the device. By default, it exists in the "My Handheld Device" root. Note that the application determines that an instance is already being run.

Additional query words: vbce vbce6 wce

Keywords: kbhowto kbapi kbtoolkit KB258088

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.