Leaked source code of windows server 2003
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.

264 lines
6.7 KiB

  1. //
  2. // clshell.cpp
  3. //
  4. // Main entry point for the tsc client shell
  5. // This is an ActiveX client container that hosts an IMsRdpClient control
  6. //
  7. // Copyright(C) Microsoft Corporation 1997-2000
  8. // Author: Nadim Abdo (nadima)
  9. //
  10. //
  11. #include "stdafx.h"
  12. #define TRC_GROUP TRC_GROUP_UI
  13. #define TRC_FILE "clshell"
  14. #include <atrcapi.h>
  15. #include "resource.h"
  16. #include "tscapp.h"
  17. //Unicode wrapper
  18. #include "wraputl.h"
  19. #ifdef OS_WINCE
  20. #include <ceconfig.h>
  21. #endif
  22. #ifdef OS_WINCE
  23. DECLARE_TRACKER_VARS();
  24. #endif
  25. //
  26. // Name: WinMain
  27. //
  28. // Purpose: Main procedure
  29. //
  30. // Returns: See Windows documentation
  31. //
  32. //
  33. int WINAPI WinMain(HINSTANCE hInstance,
  34. HINSTANCE hPrevInstance,
  35. #ifndef OS_WINCE
  36. LPSTR lpCmdLine,
  37. #else
  38. LPWSTR lpwszCmdLine,
  39. #endif
  40. int nCmdShow)
  41. {
  42. #ifdef UNIWRAP
  43. //UNICODE Wrapper intialization has to happen first,
  44. //before anything ELSE. Even DC_BEGIN_FN, which does tracing
  45. CUnicodeWrapper uwrp;
  46. uwrp.InitializeWrappers();
  47. #endif //UNIWRAP
  48. DC_BEGIN_FN("WinMain");
  49. UNREFERENCED_PARAMETER(nCmdShow);
  50. #ifndef OS_WINCE
  51. UNREFERENCED_PARAMETER(lpCmdLine);
  52. #else
  53. UNREFERENCED_PARAMETER(lpwszCmdLine);
  54. #endif
  55. MSG msg;
  56. #ifndef OS_WINCE
  57. HRESULT hr;
  58. #endif
  59. HACCEL hAccel;
  60. #ifndef OS_WINCE
  61. hr = CoInitialize(NULL);
  62. if (FAILED(hr))
  63. {
  64. return 0;
  65. }
  66. #endif
  67. TSRNG_Initialize();
  68. //
  69. // Don't bother failing the load if we can't get accels
  70. //
  71. hAccel = (HACCEL)
  72. LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATORS));
  73. TRC_ASSERT(hAccel, (TB,_T("Could not load accelerators")));
  74. //Ensure CTscApp and all child objects
  75. //get destroyed before the CoUninitalize call below.
  76. //Yes, I could use a function but this has much less overheard
  77. {
  78. CTscApp app;
  79. //GetCommandLineW is available on all platforms.
  80. #ifndef OS_WINCE
  81. LPWSTR lpszCmd = GetCommandLineW();
  82. if (lpszCmd)
  83. {
  84. //
  85. // GetCommandLine also includes the app path, so strip that off
  86. // (walk past the first space)
  87. //
  88. if ( *lpszCmd == TEXT('\"') ) {
  89. //
  90. // Scan, and skip over, subsequent characters until
  91. // another double-quote or a null is encountered.
  92. //
  93. while ( *++lpszCmd && (*lpszCmd!= TEXT('\"')) );
  94. //
  95. // If we stopped on a double-quote (usual case), skip
  96. // over it.
  97. //
  98. if ( *lpszCmd == TEXT('\"') )
  99. lpszCmd++;
  100. }
  101. else {
  102. while (*lpszCmd > TEXT(' '))
  103. lpszCmd++;
  104. }
  105. //
  106. // Skip past any white space preceeding the second token.
  107. //
  108. while (*lpszCmd && (*lpszCmd <= TEXT(' '))) {
  109. lpszCmd++;
  110. }
  111. }
  112. else
  113. {
  114. TRC_ERR((TB,_T("cmd line is NULL\n")));
  115. return 0;
  116. }
  117. #else
  118. /************************************************************************/
  119. /* On Windows CE, we have only one binary that works for WBT, Maxall, */
  120. /* Minshell, and Rapier devices. We have to get info about what */
  121. /* config we're running on and if we have to use software UUIDs here. */
  122. /************************************************************************/
  123. CEInitialize();
  124. g_CEConfig = CEGetConfigType(&g_CEUseScanCodes);
  125. if (g_CEConfig == CE_CONFIG_WBT)
  126. {
  127. UTREG_UI_DEDICATED_TERMINAL_DFLT = TRUE;
  128. }
  129. else
  130. {
  131. UTREG_UI_DEDICATED_TERMINAL_DFLT = FALSE;
  132. }
  133. RETAILMSG(1,(L"MSTSC client started, g_CEConfig = %d, g_CEUseScanCodes = %d\r\n",g_CEConfig, g_CEUseScanCodes));
  134. // CE directly gives us the cmd line in the format we want
  135. LPWSTR lpszCmd = lpwszCmdLine;
  136. #endif
  137. //
  138. // GetCommandLine also includes the app path, so strip that off
  139. //
  140. if(!app.StartShell(hInstance, hPrevInstance, lpszCmd))
  141. {
  142. TRC_ERR((TB,_T("Error: app.StartShell returned FALSE. Exiting\n")));
  143. return 1;
  144. }
  145. HWND hwndMainDlg = app.GetTscDialogHandle();
  146. //
  147. // Main message pump
  148. //
  149. while (GetMessage(&msg, 0, 0, 0))
  150. {
  151. //
  152. // Translate accelerators for the main dialog
  153. // so that CTRL-TAB can be used to switch between
  154. // tabs.
  155. //
  156. if(!TranslateAccelerator(hwndMainDlg, hAccel, &msg))
  157. {
  158. if(!IsDialogMessage( hwndMainDlg, &msg))
  159. {
  160. TranslateMessage(&msg);
  161. DispatchMessage(&msg);
  162. }
  163. }
  164. }
  165. if(!app.EndShell())
  166. {
  167. TRC_ERR((TB,_T("Error: app.EndShell returned FALSE.")));
  168. }
  169. }
  170. #ifndef OS_WINCE
  171. CoUninitialize();
  172. #endif
  173. TSRNG_Shutdown();
  174. DC_END_FN();
  175. #ifdef UNIWRAP
  176. uwrp.CleanupWrappers();
  177. #endif //UNIWRAP
  178. return 0;
  179. }
  180. #ifndef OS_WINCE
  181. #ifdef DEBUG
  182. //
  183. // Purpose: Redirect all debug messages to our tracing
  184. //
  185. extern "C"
  186. _CRTIMP int __cdecl _CrtDbgReport(int nRptType,
  187. const char * szFile,
  188. int nLine,
  189. const char * szModule,
  190. const char * szFormat,
  191. ...)
  192. {
  193. static CHAR bigBuf[2048];
  194. va_list vargs;
  195. DC_BEGIN_FN("AtlTraceXXX");
  196. va_start(vargs, szFormat);
  197. wvsprintfA(bigBuf, szFormat, vargs);
  198. va_end( vargs );
  199. #ifdef OS_WINCE
  200. #ifndef _CRT_ASSERT
  201. #define _CRT_ASSERT 2
  202. #endif
  203. #endif
  204. if (_CRT_ASSERT == nRptType)
  205. {
  206. #ifdef UNICODE
  207. TRC_ABORT((TB,_T("_CrtDbgReport. File:%S line:%d - %S"), szFile,
  208. nLine, bigBuf));
  209. #else
  210. TRC_ABORT((TB,_T("_CrtDbgReport. File:%s line:%d - %s"), szFile,
  211. nLine, bigBuf));
  212. #endif
  213. }
  214. else
  215. {
  216. #ifdef UNICODE
  217. TRC_ERR((TB,_T("_CrtDbgReport. File:%S line:%d - %S"), szFile,
  218. nLine, bigBuf));
  219. #else
  220. TRC_ERR((TB,_T("_CrtDbgReport. File:%s line:%d - %s"), szFile,
  221. nLine, bigBuf));
  222. #endif
  223. }
  224. DC_END_FN();
  225. return 0;
  226. }
  227. #endif
  228. #endif //OS_WINCE