CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Posts
    6

    Single instance application



    Hi,


    I need to write an application that will never run in more than one instance.

  2. #2
    Join Date
    Apr 1999
    Location
    Canada
    Posts
    12

    Re: Single instance application



    Follow the link below and you'll find how to use shared instances.


    http://www.codeguru.com/win32/previnst.shtml


    If you add also a shared static member of type HWND in which to keep the handler of the main window of the one and only instance, or even the HINSTANCE, you have everything you need.

  3. #3
    Join Date
    Apr 1999
    Posts
    2

    Re: Single instance application

    Hi ....

    Just check for a Named Mutex object, and create one if not exist (ie. first instance).

    Hope this will help you

    bye


    Regards...

    Rajan K

  4. #4
    Join Date
    May 1999
    Posts
    40

    Re: Single instance application

    #pragma data_seg("Shared")
    LONG g_lUsageCount = -1;
    #pragma data_seg()

    #pragma comment(linker,"/section:Shared,rws")

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpszCmdLine, int nCmdShow)
    {
    BOOL fFirstInstance=(InterlockedIncrement(&g_lUsageCount) == 0);

    if (fFirstInstance)
    {
    }
    InterlockedDecrement(&g_lUsageCount);
    return 1;
    }


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