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.

308 lines
10 KiB

  1. /**MOD+**********************************************************************/
  2. /* Module: tsaxmain.cpp */
  3. /* */
  4. /* Purpose: Implementation of DLL Exports. Header for this module will */
  5. /* be generated in the respective build directory. */
  6. /* */
  7. /* Copyright(C) Microsoft Corporation 1998 */
  8. /* */
  9. /****************************************************************************/
  10. #include "stdafx.h"
  11. #include "atlwarn.h"
  12. BEGIN_EXTERN_C
  13. #define TRC_GROUP TRC_GROUP_UI
  14. #define TRC_FILE "tsaxmain"
  15. #include <atrcapi.h>
  16. END_EXTERN_C
  17. #include "tsaxiids.h"
  18. #include "initguid.h"
  19. #include "mstsax.h"
  20. #ifndef OS_WINCE
  21. #include "mstsax_i.c"
  22. #endif
  23. #include "mstscax.h"
  24. #include "tsaxmod.h"
  25. //
  26. // Version number (property returns this)
  27. //
  28. #ifndef OS_WINCE
  29. #include "ntverp.h"
  30. #else
  31. #include "ceconfig.h" //get build #
  32. #endif
  33. //Unicode wrapper
  34. #include "wraputl.h"
  35. /****************************************************************************/
  36. /* Module object */
  37. /****************************************************************************/
  38. CMsTscAxModule _Module;
  39. /****************************************************************************/
  40. /* Object map */
  41. /****************************************************************************/
  42. BEGIN_OBJECT_MAP(ObjectMap)
  43. OBJECT_ENTRY(CLSID_MsRdpClient3, CMsTscAx)
  44. OBJECT_ENTRY(CLSID_MsRdpClient2, CMsTscAx)
  45. OBJECT_ENTRY(CLSID_MsRdpClient, CMsTscAx)
  46. OBJECT_ENTRY(CLSID_MsTscAx, CMsTscAx)
  47. END_OBJECT_MAP()
  48. #ifdef ECP_TIMEBOMB
  49. //
  50. // Return's true if timebomb test passed otherwise puts up warning
  51. // UI and return's FALSE
  52. //
  53. BOOL CheckTimeBomb()
  54. {
  55. SYSTEMTIME lclTime;
  56. FILETIME lclFileTime;
  57. GetLocalTime(&lclTime);
  58. DCBOOL bTimeBombOk = TRUE;
  59. //
  60. // Simply check that the local date is less than June 30, 2000
  61. //
  62. if(lclTime.wYear < ECP_TIMEBOMB_YEAR)
  63. {
  64. return TRUE;
  65. }
  66. else if (lclTime.wYear == ECP_TIMEBOMB_YEAR)
  67. {
  68. if(lclTime.wMonth < ECP_TIMEBOMB_MONTH)
  69. {
  70. return TRUE;
  71. }
  72. else if(lclTime.wMonth == ECP_TIMEBOMB_MONTH)
  73. {
  74. if(lclTime.wDay < ECP_TIMEBOMB_DAY)
  75. {
  76. return TRUE;
  77. }
  78. }
  79. }
  80. DCTCHAR timeBombStr[256];
  81. if (LoadString(_Module.GetModuleInstance(),
  82. TIMEBOMB_EXPIRED_STR,
  83. timeBombStr,
  84. SIZEOF_TCHARBUFFER(timeBombStr)) != 0)
  85. {
  86. MessageBox(NULL, timeBombStr, NULL,
  87. MB_ICONERROR | MB_OK);
  88. }
  89. //
  90. // If we reach this point the timebomb should trigger
  91. // so put up a messagebox and return FALSE
  92. // so the calling code can disable functionality
  93. //
  94. return FALSE;
  95. }
  96. #endif
  97. #ifdef UNIWRAP
  98. //It's ok to have a global unicode wrapper
  99. //class. All it does is sets up the g_bRunningOnNT
  100. //flag so it can be shared by multiple instances
  101. //also it is only used from DllMain so there
  102. //are no problems with re-entrancy
  103. CUnicodeWrapper g_uwrp;
  104. #endif
  105. #ifdef OS_WINCE
  106. DECLARE_TRACKER_VARS();
  107. #endif
  108. /**PROC+*********************************************************************/
  109. /* Name: DllMain */
  110. /* */
  111. /* Purpose: DLL entry point */
  112. /* */
  113. /**PROC-*********************************************************************/
  114. extern "C"
  115. #ifndef OS_WINCE
  116. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  117. #else
  118. BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  119. #endif
  120. {
  121. if (dwReason == DLL_PROCESS_ATTACH)
  122. {
  123. #ifdef UNIWRAP
  124. //UNICODE Wrapper intialization has to happen first,
  125. //before anything ELSE. Even DC_BEGIN_FN, which does tracing
  126. g_uwrp.InitializeWrappers();
  127. #endif
  128. TSRNG_Initialize();
  129. CO_StaticInit((HINSTANCE)hInstance);
  130. _Module.Init(ObjectMap, (HINSTANCE)hInstance);
  131. #if ((!defined (OS_WINCE)) || (_WIN32_WCE >= 300) )
  132. DisableThreadLibraryCalls((HINSTANCE)hInstance);
  133. #endif
  134. #ifdef OS_WINCE
  135. CEInitialize();
  136. g_CEConfig = CEGetConfigType(&g_CEUseScanCodes);
  137. #endif
  138. }
  139. else if (dwReason == DLL_PROCESS_DETACH) {
  140. _Module.Term();
  141. CO_StaticTerm();
  142. TSRNG_Shutdown();
  143. #ifdef UNIWRAP
  144. g_uwrp.CleanupWrappers();
  145. #endif
  146. }
  147. return TRUE; // ok
  148. }
  149. /**PROC+*********************************************************************/
  150. /* Name: DllCanUnloadNow */
  151. /* */
  152. /* Purpose: Used to determine whether the DLL can be unloaded by OLE */
  153. /* */
  154. /**PROC-*********************************************************************/
  155. STDAPI DllCanUnloadNow(void)
  156. {
  157. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  158. }
  159. /**PROC+*********************************************************************/
  160. /* Name: DllGetClassObject */
  161. /* */
  162. /* Purpose: Returns a class factory to create an object of the requested */
  163. /* type */
  164. /* */
  165. /**PROC-*********************************************************************/
  166. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  167. {
  168. #ifdef ECP_TIMEBOMB
  169. if(!CheckTimeBomb())
  170. {
  171. //
  172. // Timebomb failed, bail out with an error message
  173. //
  174. return E_OUTOFMEMORY;
  175. }
  176. #endif
  177. return _Module.GetClassObject(rclsid, riid, ppv);
  178. }
  179. /**PROC+*********************************************************************/
  180. /* Name: DllRegisterServer */
  181. /* */
  182. /* Purpose: DllRegisterServer - Adds entries to the system registry */
  183. /* */
  184. /**PROC-*********************************************************************/
  185. STDAPI DllRegisterServer(void)
  186. {
  187. // registers object, typelib and all interfaces in typelib
  188. return _Module.RegisterServer(TRUE);
  189. }
  190. /**PROC+*********************************************************************/
  191. /* Name: DllUnregisterServer */
  192. /* */
  193. /* Purpose: DllUnregisterServer - Removes entries from the system registry*/
  194. /* */
  195. /**PROC-*********************************************************************/
  196. STDAPI DllUnregisterServer(void)
  197. {
  198. return _Module.UnregisterServer();
  199. }
  200. /**PROC+*********************************************************************/
  201. /* Name: DllGetTscCtlVer */
  202. /* */
  203. /* Purpose: Returns version of the tsc control */
  204. /* */
  205. /**PROC-*********************************************************************/
  206. STDAPI_(DWORD) DllGetTscCtlVer(void)
  207. {
  208. #ifndef OS_WINCE
  209. return VER_PRODUCTVERSION_DW;
  210. #else
  211. return CE_TSC_BUILDNO;
  212. #endif
  213. }
  214. #ifndef OS_WINCE
  215. #ifdef CRTREPORT_DEBUG_HACK
  216. /**PROC+*********************************************************************/
  217. /* Name: _CrtDbgReport */
  218. /* */
  219. /* Purpose: Redirect all debug reporting to our tracing functions */
  220. /* */
  221. /**PROC-*********************************************************************/
  222. extern "C"
  223. _CRTIMP int __cdecl _CrtDbgReport(int nRptType,
  224. const char * szFile,
  225. int nLine,
  226. const char * szModule,
  227. const char * szFormat,
  228. ...)
  229. {
  230. static CHAR bigBuf[2048];
  231. va_list vargs;
  232. HRESULT hr;
  233. DC_BEGIN_FN("AtlTraceXXX");
  234. va_start(vargs, szFormat);
  235. hr = StringCchVPrintfA(bigBuf, sizeof(bigBuf), szFormat, vargs);
  236. va_end( vargs );
  237. #ifdef OS_WINCE
  238. #ifndef _CRT_ASSERT
  239. #define _CRT_ASSERT 2
  240. #endif
  241. #endif
  242. if (_CRT_ASSERT == nRptType)
  243. {
  244. #ifdef UNICODE
  245. TRC_ABORT((TB,_T("AtlAssert. File:%S line:%d - %S"), szFile,
  246. nLine, bigBuf));
  247. #else
  248. TRC_ABORT((TB,_T("AtlAssert. File:%s line:%d - %s"), szFile,
  249. nLine, bigBuf));
  250. #endif
  251. }
  252. else
  253. {
  254. #ifdef UNICODE
  255. TRC_ERR((TB,_T("AtlTrace. File:%S line:%d - %S"), szFile,
  256. nLine, bigBuf));
  257. #else
  258. TRC_ERR((TB,_T("AtlTrace. File:%s line:%d - %s"), szFile,
  259. nLine, bigBuf));
  260. #endif
  261. }
  262. DC_END_FN();
  263. return 0;
  264. }
  265. #endif
  266. #endif //OS_WINCE