With Terminal Services (or Cytrix, or another similar product) running on the machine where I have the application and the HASP key, I can start two instances of the application from two different machines. That is because the mutex is created per session.
In order to fix the problem, I created a global mutex by adding "Global\\" in front of the mutex name. It works fine for Windows 2000 and later versions, but on earlier versions the "Global" keyword is ignored.(see 'Kernel Object Name Spaces' in MSDN).
The problem is serious. Even if I use a HASP key; the users can pay for one license and run as many applications as they want using Terminal Services.
The string returned by GetClassName method is destroyed after the second line. We cannot rely the CFrameWnd::PreCreateWindow work ok.
OK, 2 simple changes:
Posted by richardwyllie
on 05/23/2008 06:21pm
Change the definition of GetClassName in the CSingleInstance header and code files to:
LPCTSTR GetClassName() const;
and then change the code in PreCreateWindow to:
cs.lpszClass = ((CMyDerivedWinApp *) AfxGetApp())->m_singleInstance.GetClassName();