How To Identify a Previous Instance of an Application (106385)
The information in this article applies to:
- Microsoft Platform Software Development Kit (SDK) 1.0
This article was previously published under Q106385 SUMMARY
The entry point of both 16-bit (Win16) and 32-bit (Win32) Windows
applications is documented as follows:
int WinMain( hInstance, hPrevInstance, lpszCmdLine, nCmdShow )
HINSTANCE hInstance; /* Handle of current instance */
HINSTANCE hPrevInstance; /* Handle of previous instance */
LPSTR lpszCmdLine; /* Address of command line */
int nCmdShow; /* Show state of window */
However, under Win32, hPrevInstance is documented to always be NULL.
The reason is that each application runs in its own address space and may
have the same ID as another application.
To determine whether another instance of the application is running, use a
named mutex. If opening the mutex fails, then there are no other instances
of the application running. FindWindow() can be used with the class and
window name. However, note that a second instance of the application could
be started, and could execute the FindWindow() call before the first
instance has created its window. Use a named object to ensure that this
does not happen.
Modification Type: | Minor | Last Reviewed: | 7/11/2005 |
---|
Keywords: | kbhowto KB106385 |
---|
|