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.

577 lines
11 KiB

  1. /*++
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. llsmgr.cpp
  5. Abstract:
  6. Application object implementation.
  7. Author:
  8. Don Ryan (donryan) 12-Feb-1995
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. Jeff Parham (jeffparh) 16-Jan-1996
  13. Added SetLastTargetServer() to OpenDocumentFile() to help isolate
  14. server connection problems. (Bug #2993.)
  15. --*/
  16. #include "stdafx.h"
  17. #include "llsmgr.h"
  18. #include "mainfrm.h"
  19. #include "llsdoc.h"
  20. #include "llsview.h"
  21. #include "sdomdlg.h"
  22. #include "shellapi.h"
  23. #include <afxpriv.h>
  24. #include <htmlhelp.h>
  25. #include <sbs_res.h>
  26. BOOL IsRestrictedSmallBusSrv( void );
  27. #ifdef _DEBUG
  28. #undef THIS_FILE
  29. static char BASED_CODE THIS_FILE[] = __FILE__;
  30. #endif
  31. CLlsmgrApp theApp; // The one and only CLlsmgrApp object
  32. BEGIN_MESSAGE_MAP(CLlsmgrApp, CWinApp)
  33. //{{AFX_MSG_MAP(CLlsmgrApp)
  34. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  35. //}}AFX_MSG_MAP
  36. END_MESSAGE_MAP()
  37. CLlsmgrApp::CLlsmgrApp()
  38. /*++
  39. Routine Description:
  40. Constructor for application object.
  41. Arguments:
  42. None.
  43. Return Values:
  44. None.
  45. --*/
  46. {
  47. m_pApplication = NULL;
  48. m_bIsAutomated = FALSE;
  49. #ifdef _DEBUG_VERBOSE
  50. afxMemDF |= checkAlwaysMemDF;
  51. #endif
  52. }
  53. int CLlsmgrApp::ExitInstance()
  54. /*++
  55. Routine Description:
  56. Called by framework to exit this instance of an application.
  57. Arguments:
  58. None.
  59. Return Values:
  60. Application's exit code.
  61. --*/
  62. {
  63. if (m_pApplication && !m_bIsAutomated)
  64. m_pApplication->InternalRelease();
  65. #ifdef _DEBUG
  66. CMemoryState exitMem;
  67. CMemoryState diffMem;
  68. exitMem.Checkpoint();
  69. if (!diffMem.Difference(m_initMem, exitMem))
  70. {
  71. diffMem.DumpStatistics();
  72. m_initMem.DumpAllObjectsSince();
  73. }
  74. #endif
  75. return CWinApp::ExitInstance();
  76. }
  77. BOOL CLlsmgrApp::InitInstance()
  78. /*++
  79. Routine Description:
  80. Called by framework to initialize a new instance of an application.
  81. Arguments:
  82. None.
  83. Return Values:
  84. TRUE if initialization succeeds.
  85. --*/
  86. {
  87. #ifdef _DEBUG
  88. m_initMem.Checkpoint();
  89. #endif
  90. //
  91. // Check if this server is a restricted small business server.
  92. // If so, disallow further use of the license manager.
  93. //
  94. if (IsRestrictedSmallBusSrv())
  95. {
  96. //
  97. // Let the user know of the restriction.
  98. //
  99. HINSTANCE hSbsLib = NULL;
  100. if ( hSbsLib = LoadLibrary( SBS_RESOURCE_DLL ) )
  101. {
  102. TCHAR pszText[512+1];
  103. LoadString ( hSbsLib, SBS_License_Error, pszText, 512 );
  104. AfxMessageBox( pszText );
  105. }
  106. else
  107. {
  108. AfxMessageBox(IDP_SBS_RESTRICTED);
  109. }
  110. return FALSE;
  111. }
  112. //
  113. // Initialize OLE libraries
  114. //
  115. if (!AfxOleInit())
  116. {
  117. AfxMessageBox(IDP_OLE_INIT_FAILED);
  118. return FALSE;
  119. }
  120. //
  121. // If the application was launched as an OLE server (run with
  122. // /Embedding or /Automation) then register all OLE server factories
  123. // as running and don't show main window.
  124. //
  125. if (RunEmbedded() || RunAutomated())
  126. {
  127. COleTemplateServer::RegisterAll();
  128. return m_bIsAutomated = TRUE;
  129. }
  130. //
  131. // Create image list for common controls
  132. //
  133. m_smallImages.Create(IDB_SMALL_CTRLS, BMPI_SMALL_SIZE, 0, BMPI_RGB_BKGND);
  134. m_largeImages.Create(IDB_LARGE_CTRLS, BMPI_LARGE_SIZE, 0, BMPI_RGB_BKGND);
  135. //
  136. // Create document template
  137. //
  138. m_pDocTemplate = new CSingleDocTemplate(
  139. IDR_MAINFRAME,
  140. RUNTIME_CLASS(CLlsmgrDoc),
  141. RUNTIME_CLASS(CMainFrame),
  142. RUNTIME_CLASS(CLlsmgrView)
  143. );
  144. AddDocTemplate(m_pDocTemplate);
  145. //
  146. // Create OLE-createable application object. This object
  147. // will save itself in m_pApplication so there should only
  148. // be one and only one. If the application was launched as
  149. // an OLE server then this object is created automatically
  150. // via CreateObject() or GetObject().
  151. //
  152. CApplication* pApplication = new CApplication;
  153. if (pApplication && !pApplication->GetLastStatus())
  154. {
  155. OnFileNew(); // display empty frame ...
  156. m_pMainWnd->PostMessage(WM_COMMAND, ID_APP_STARTUP);
  157. }
  158. else
  159. {
  160. AfxMessageBox(IDP_APP_INIT_FAILED);
  161. return FALSE;
  162. }
  163. return TRUE;
  164. }
  165. void CLlsmgrApp::DisplayStatus(long Status)
  166. /*++
  167. Routine Description:
  168. Retrieves status string and displays.
  169. Arguments:
  170. Status - status code.
  171. Return Values:
  172. None.
  173. --*/
  174. {
  175. m_pApplication->SetLastStatus(Status);
  176. DisplayLastStatus();
  177. }
  178. void CLlsmgrApp::DisplayLastStatus()
  179. /*++
  180. Routine Description:
  181. Retrieves status string and displays.
  182. Arguments:
  183. None.
  184. Return Values:
  185. None.
  186. --*/
  187. {
  188. BSTR LastErrorString = m_pApplication->GetLastErrorString();
  189. AfxMessageBox(LastErrorString);
  190. SysFreeString(LastErrorString);
  191. }
  192. void CLlsmgrApp::OnAppAbout()
  193. /*++
  194. Routine Description:
  195. Message handler for ID_APP_ABOUT.
  196. Arguments:
  197. None.
  198. Return Values:
  199. None.
  200. --*/
  201. {
  202. BSTR AppName = LlsGetApp()->GetName();
  203. ::ShellAbout(m_pMainWnd->GetSafeHwnd(), AppName, AppName, LoadIcon(IDR_MAINFRAME));
  204. SysFreeString(AppName);
  205. }
  206. CDocument* CLlsmgrApp::OpenDocumentFile(LPCTSTR lpszFileName)
  207. /*++
  208. Routine Description:
  209. Message handler for ID_FILE_OPEN.
  210. Arguments:
  211. lpszFileName - file name (actually domain name).
  212. Return Values:
  213. Pointer to object is successful.
  214. --*/
  215. {
  216. BOOL bFocusChanged = FALSE;
  217. VARIANT va;
  218. VariantInit(&va);
  219. BeginWaitCursor();
  220. if (lpszFileName)
  221. {
  222. va.vt = VT_BSTR;
  223. va.bstrVal = SysAllocStringLen(lpszFileName, lstrlen(lpszFileName));
  224. bFocusChanged = LlsGetApp()->SelectDomain(va);
  225. }
  226. else
  227. {
  228. bFocusChanged = LlsGetApp()->SelectEnterprise();
  229. CString eTitle;
  230. eTitle.LoadString(IDS_ENTERPRISE);
  231. lpszFileName = MKSTR(eTitle);
  232. }
  233. EndWaitCursor();
  234. VariantClear(&va); // free system string if necessary...
  235. if (!bFocusChanged)
  236. {
  237. LPTSTR pszLastTargetServer;
  238. if (LlsGetLastStatus() == STATUS_ACCESS_DENIED)
  239. {
  240. AfxMessageBox(IDP_ERROR_NO_PRIVILEGES);
  241. }
  242. else if ( ( ( LlsGetLastStatus() == RPC_S_SERVER_UNAVAILABLE )
  243. || ( LlsGetLastStatus() == RPC_NT_SERVER_UNAVAILABLE ) )
  244. && ( NULL != ( pszLastTargetServer = LlsGetLastTargetServer() ) ) )
  245. {
  246. CString strMessage;
  247. AfxFormatString1( strMessage, IDP_ERROR_NO_RPC_SERVER_FORMAT, pszLastTargetServer );
  248. SysFreeString( pszLastTargetServer );
  249. AfxMessageBox( strMessage );
  250. }
  251. else
  252. {
  253. DisplayLastStatus();
  254. }
  255. return FALSE;
  256. }
  257. //
  258. // Notify framework that focus changed....
  259. //
  260. return m_pDocTemplate->OpenDocumentFile(lpszFileName);
  261. }
  262. BOOL CLlsmgrApp::OnAppStartup()
  263. /*++
  264. Routine Description:
  265. Message handler for ID_APP_STARTUP.
  266. Arguments:
  267. None.
  268. Return Values:
  269. Returns true if successful.
  270. --*/
  271. {
  272. CString strStartingPoint;
  273. //
  274. // Update registry in case it has been damaged
  275. //
  276. COleObjectFactory::UpdateRegistryAll();
  277. //
  278. // Select domain using command line or machine name
  279. //
  280. if (m_lpCmdLine && *m_lpCmdLine)
  281. {
  282. LPCTSTR pszStartingPoint;
  283. pszStartingPoint = m_lpCmdLine;
  284. while (_istspace(*pszStartingPoint))
  285. pszStartingPoint = _tcsinc(pszStartingPoint);
  286. strStartingPoint = pszStartingPoint;
  287. strStartingPoint.TrimRight();
  288. }
  289. else
  290. {
  291. TCHAR szComputerName[MAX_PATH+1];
  292. DWORD cchComputerName = sizeof(szComputerName) / sizeof(TCHAR);
  293. if (::GetComputerName(szComputerName, &cchComputerName))
  294. {
  295. strStartingPoint = _T("\\\\");
  296. strStartingPoint += szComputerName;
  297. }
  298. else
  299. {
  300. DisplayStatus(::GetLastError());
  301. m_pMainWnd->PostMessage(WM_CLOSE);
  302. return FALSE;
  303. }
  304. }
  305. if (!OpenDocumentFile(strStartingPoint))
  306. {
  307. CSelectDomainDialog sdomDlg;
  308. if (sdomDlg.DoModal() != IDOK)
  309. {
  310. m_pMainWnd->PostMessage(WM_CLOSE);
  311. return FALSE;
  312. }
  313. }
  314. return TRUE;
  315. }
  316. void CLlsmgrApp::WinHelp( DWORD_PTR dwData, UINT nCmd )
  317. /*++
  318. Routine Description:
  319. Same as CWinApp::WinHelp with the exception that we trap HELP_CONTEXT on
  320. IDR_MAINFRAME and translate it to a HELP_FINDER call.
  321. Arguments:
  322. None.
  323. Return Values:
  324. None.
  325. --*/
  326. {
  327. UNREFERENCED_PARAMETER( dwData );
  328. UNREFERENCED_PARAMETER( nCmd );
  329. CWnd* pMainWnd = AfxGetMainWnd();
  330. ASSERT_VALID( pMainWnd );
  331. ::HtmlHelp(pMainWnd->m_hWnd, L"liceconcepts.chm", HH_DISPLAY_TOPIC,0);
  332. }
  333. const WCHAR wszProductOptions[] =
  334. L"System\\CurrentControlSet\\Control\\ProductOptions";
  335. const WCHAR wszProductSuite[] =
  336. L"ProductSuite";
  337. const WCHAR wszSBSRestricted[] =
  338. L"Small Business(Restricted)";
  339. BOOL IsRestrictedSmallBusSrv( void )
  340. /*++
  341. Routine Description:
  342. Check if this server is a Microsoft small business restricted server.
  343. Arguments:
  344. None.
  345. Return Values:
  346. TRUE -- This server is a restricted small business server.
  347. FALSE -- No such restriction.
  348. --*/
  349. {
  350. WCHAR wszBuffer[1024] = L"";
  351. DWORD cbBuffer = sizeof(wszBuffer);
  352. DWORD dwType;
  353. LPWSTR pwszSuite;
  354. HKEY hKey;
  355. BOOL bRet = FALSE;
  356. //
  357. // Check if this server is a Microsoft small business restricted server.
  358. // Do so by checking for the existence of the string
  359. // "Small Business(Restricted)"
  360. // in the MULTI_SZ "ProductSuite" value under
  361. // HKLM\CurrentCcntrolSet\Control\ProductOptions.
  362. //
  363. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  364. wszProductOptions,
  365. 0,
  366. KEY_READ,
  367. &hKey) == ERROR_SUCCESS)
  368. {
  369. if (RegQueryValueEx(hKey,
  370. wszProductSuite,
  371. NULL,
  372. &dwType,
  373. (LPBYTE)wszBuffer,
  374. &cbBuffer) == ERROR_SUCCESS)
  375. {
  376. if (dwType == REG_MULTI_SZ && *wszBuffer)
  377. {
  378. pwszSuite = wszBuffer;
  379. while (*pwszSuite)
  380. {
  381. if (lstrcmpi(pwszSuite, wszSBSRestricted) == 0)
  382. {
  383. bRet = TRUE;
  384. break;
  385. }
  386. pwszSuite += wcslen(pwszSuite) + 1;
  387. }
  388. }
  389. }
  390. RegCloseKey(hKey);
  391. }
  392. return bRet;
  393. }