ID Number: Q84836
1.00
WINDOWS
Summary:
To determine the total number of Microsoft Visual Basic applications
running at any given time, you can use the Windows API functions
GetModuleHandle and GetModuleUsage.
This information applies to Microsoft Visual Basic programming system
version 1.0 for Windows.
More Information:
The following code fragment demonstrates a technique to find the total
number of Visual Basic applications currently executing by determining
the number of instances of the Visual Basic run-time module
(VBRUN100.DLL) with the Windows API functions GetModuleHandle and
GetModuleUsage. Remember that Visual Basic itself is not counted; only
applications created with Visual Basic are included.
Steps to Create Example Program
-------------------------------
1. Start several Visual Basic applications and leave them running.
2. Run Visual Basic, or from the File menu, choose New Project (ALT,
F, N) if Visual Basic is already running. Form1 is created by
default.
3. Enter the following Windows API function declarations into the
global module (GLOBAL.BAS) of your project:
Declare Function GetModuleUsage% Lib "kernel" (ByVal hModule%)
Declare Function GetModuleHandle% Lib "kernel" (ByVal FileName$)
4. Place a command button (Command1) on Form1. Double-click that
button to open the Code window. In the Command1_Click procedure,
add the following code:
Sub Command1_Click ()
msg$ = "Number of executing VB Apps: "
hModule% = GetModuleHandle("VBRUN100.DLL")
nInstances% = GetModuleUsage(hModule%)
msg$ = msg$ + Str$(nInstances%)
MsgBox msg$
End Sub
5. From the File menu, choose Make EXE File.
6. Press F5 to run the file.
7. Click on the command button.
A message box displays the total number of executing Visual Basic
applications.
Note: This program itself will count as one application.
Additional reference words: 1.00