CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: prevInstance

  1. #1
    Guest

    prevInstance

    How can I define the previous instance of my application in VC6. The member m_hPrevInstance in 32 bit app is always set to NULL. The method FindWindow looks bad to me, because I don't want use window title to search.


  2. #2
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: prevInstance

    And you are right.
    There is many other ways to check if your app is running. For example you can create memory file and check for it’s presence. If it exists refuse to run another instance.
    Named pipes will also do.



    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  3. #3
    Join Date
    Sep 1999
    Location
    Armenia
    Posts
    107

    Re: prevInstance

    You can use Mutex for that.
    First, in InitInstance() you should create it:

    HANDLE test=CreateMutex(NULL,TRUE,"MyMutex");

    If then you run another app copy, this call will
    return ERROR_INVALID_HANDLE and GetLastError() will return ERROR_ALREADY_EXISTS value.
    Don't forget to close mutex after program termination in ExitInstance():

    CloseHandle(test);


    Never say never.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured