Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

255 lines
6.5 KiB

  1. // LCWiz.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "LCWiz.h"
  5. #include "LCWizSht.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CLicCompWizApp
  13. BEGIN_MESSAGE_MAP(CLicCompWizApp, CWinApp)
  14. //{{AFX_MSG_MAP(CLicCompWizApp)
  15. // NOTE - the ClassWizard will add and remove mapping macros here.
  16. // DO NOT EDIT what you see in these blocks of generated code!
  17. //}}AFX_MSG
  18. //ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  19. END_MESSAGE_MAP()
  20. /////////////////////////////////////////////////////////////////////////////
  21. // Global variables
  22. TCHAR pszMutex[] = _T("LicenseMutex");
  23. TCHAR pszLicenseEvent[] = _T("LicenseThread");
  24. TCHAR pszTreeEvent[] = _T("TreeThread");
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CLicCompWizApp construction
  27. CLicCompWizApp::CLicCompWizApp()
  28. : m_pLicenseThread(NULL), m_bExitLicenseThread(FALSE),
  29. m_event(TRUE, TRUE, pszLicenseEvent), m_nRemote(0)
  30. {
  31. m_strEnterprise.Empty();
  32. m_strDomain.Empty();
  33. m_strEnterpriseServer.Empty();
  34. m_strUser.Empty();
  35. // Create a mutex object for use when checking for
  36. // multiple instances.
  37. m_hMutex = ::CreateMutex(NULL, TRUE, pszMutex);
  38. // Place all significant initialization in InitInstance
  39. }
  40. CLicCompWizApp::~CLicCompWizApp()
  41. {
  42. ::ReleaseMutex(m_hMutex);
  43. }
  44. /////////////////////////////////////////////////////////////////////////////
  45. // The one and only CLicCompWizApp object
  46. CLicCompWizApp theApp;
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CLicCompWizApp initialization
  49. BOOL CLicCompWizApp::InitInstance()
  50. {
  51. // Make sure we're running on the correct OS version.
  52. OSVERSIONINFO os;
  53. os.dwOSVersionInfoSize = sizeof(os);
  54. ::GetVersionEx(&os);
  55. if (os.dwMajorVersion < 4 || os.dwPlatformId != VER_PLATFORM_WIN32_NT)
  56. {
  57. AfxMessageBox(IDS_BAD_VERSION, MB_OK | MB_ICONSTOP);
  58. return FALSE;
  59. }
  60. // If there's an instance already running, bring it to the
  61. // top and exit.
  62. if (::WaitForSingleObject(m_hMutex, 0) != WAIT_OBJECT_0)
  63. {
  64. CString strWindow;
  65. strWindow.LoadString(AFX_IDS_APP_TITLE);
  66. HWND hwnd = ::FindWindow(NULL, (LPCTSTR)strWindow);
  67. if (hwnd != NULL)
  68. ::SetForegroundWindow(hwnd);
  69. else
  70. {
  71. TRACE(_T("%lu: FindWindow\n"), ::GetLastError());
  72. }
  73. return FALSE;
  74. }
  75. #ifdef OLE_AUTO
  76. // Initialize OLE libraries
  77. if (!AfxOleInit())
  78. {
  79. AfxMessageBox(IDP_OLE_INIT_FAILED);
  80. return FALSE;
  81. }
  82. #endif // OLE_AUTO
  83. // Standard initialization
  84. // If you are not using these features and wish to reduce the size
  85. // of your final executable, you should remove from the following
  86. // the specific initialization routines you do not need.
  87. #ifdef _AFXDLL
  88. Enable3dControls(); // Call this when using MFC in a shared DLL
  89. #else
  90. Enable3dControlsStatic(); // Call this when linking to MFC statically
  91. #endif
  92. #ifdef OLE_AUTO
  93. // Parse the command line to see if launched as OLE server
  94. if (RunEmbedded() || RunAutomated())
  95. {
  96. // Register all OLE server (factories) as running. This enables the
  97. // OLE libraries to create objects from other applications.
  98. COleTemplateServer::RegisterAll();
  99. // Application was run with /Embedding or /Automation. Don't show the
  100. // main window in this case.
  101. return TRUE;
  102. }
  103. // When a server application is launched stand-alone, it is a good idea
  104. // to update the system registry in case it has been damaged.
  105. COleObjectFactory::UpdateRegistryAll();
  106. #endif // OLE_AUTO
  107. PLLS_CONNECT_INFO_0 pllsci;
  108. // Get the default domain and license server.
  109. NTSTATUS status = ::LlsEnterpriseServerFind(NULL, 0, (LPBYTE*)&pllsci);
  110. if (NT_SUCCESS(status))
  111. {
  112. m_strDomain = pllsci->Domain;
  113. m_strEnterpriseServer = pllsci->EnterpriseServer;
  114. // Free embedded pointers.
  115. //::LlsFreeMemory(pllsci->Domain);
  116. //::LlsFreeMemory(pllsci->EnterpriseServer);
  117. ::LlsFreeMemory(pllsci);
  118. }
  119. else
  120. {
  121. // There is no license server if this is a workstation
  122. // so get the local computer name instead.
  123. DWORD dwBufSize = BUFFER_SIZE;
  124. LPTSTR pszTemp = m_strEnterpriseServer.GetBuffer(dwBufSize);
  125. ::GetComputerName(pszTemp, &dwBufSize);
  126. m_strDomain.ReleaseBuffer();
  127. // Get the default domain name from the registry.
  128. GetRegString(m_strDomain, IDS_SUBKEY, IDS_REG_VALUE);
  129. }
  130. CString strDomain, strUser;
  131. // Get the user's name and domain.
  132. GetRegString(strDomain, IDS_SUBKEY, IDS_REG_VALUE_DOMAIN);
  133. GetRegString(strUser, IDS_SUBKEY, IDS_REG_VALUE_USER);
  134. m_strUser.Format(IDS_DOMAIN_USER, strDomain, strUser);
  135. // Launch the wizard.
  136. OnWizard();
  137. // Since the dialog has been closed, return FALSE so that we exit the
  138. // application, rather than start the application's message pump.
  139. return FALSE;
  140. }
  141. void CLicCompWizApp::OnWizard()
  142. {
  143. // The property sheet attached to your project
  144. // via this function is not hooked up to any message
  145. // handler. In order to actually use the property sheet,
  146. // you will need to associate this function with a control
  147. // in your project such as a menu item or tool bar button.
  148. CLicCompWizSheet propSheet;
  149. m_pMainWnd = &propSheet;
  150. propSheet.DoModal();
  151. // This is where you would retrieve information from the property
  152. // sheet if propSheet.DoModal() returned IDOK. We aren't doing
  153. // anything for simplicity.
  154. }
  155. BOOL CLicCompWizApp::GetRegString(CString& strIn, UINT nSubKey, UINT nValue, HKEY hHive /* = HKEY_LOCAL_MACHINE */)
  156. {
  157. BOOL bReturn = FALSE;
  158. HKEY hKey;
  159. LPTSTR pszTemp;
  160. DWORD dwBufSize = BUFFER_SIZE;
  161. CString strSubkey;
  162. strSubkey.LoadString(nSubKey);
  163. if (::RegOpenKeyEx(hHive, (LPCTSTR)strSubkey, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
  164. {
  165. DWORD dwType = REG_SZ;
  166. CString strValue;
  167. strValue.LoadString(nValue);
  168. pszTemp = strIn.GetBuffer(dwBufSize);
  169. ::RegQueryValueEx(hKey, (LPCTSTR)strValue, NULL, &dwType, (LPBYTE)pszTemp, &dwBufSize);
  170. ::RegCloseKey(hKey);
  171. strIn.ReleaseBuffer();
  172. bReturn = TRUE;
  173. }
  174. return bReturn;
  175. }
  176. int CLicCompWizApp::ExitInstance()
  177. {
  178. ExitThreads();
  179. return CWinApp::ExitInstance();
  180. }
  181. void CLicCompWizApp::NotifyLicenseThread(BOOL bExit)
  182. {
  183. CCriticalSection cs;
  184. if (cs.Lock())
  185. {
  186. m_bExitLicenseThread = bExit;
  187. cs.Unlock();
  188. }
  189. }
  190. void CLicCompWizApp::ExitThreads()
  191. {
  192. // Make sure the license thread knows it's supposed to quit.
  193. if (m_pLicenseThread != NULL)
  194. NotifyLicenseThread(TRUE);
  195. // Create a lock object for the event object.
  196. CSingleLock lock(&m_event);
  197. // Lock the lock object and make the main thread wait for the
  198. // threads to signal their event objects.
  199. lock.Lock();
  200. }