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.

153 lines
4.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: ComAPIs.cxx (16 bit target)
  7. //
  8. // Contents: CompObj APIs
  9. //
  10. // Functions:
  11. //
  12. // History: 16-Dec-93 JohannP Created
  13. //
  14. //--------------------------------------------------------------------------
  15. #include <headers.cxx>
  16. #pragma hdrstop
  17. #include <ole2sp.h>
  18. #include <olecoll.h>
  19. #include <map_kv.h>
  20. #include <stdlib.h>
  21. #include "map_htsk.h"
  22. #include "etask.hxx"
  23. #include "call32.hxx"
  24. #include "apilist.hxx"
  25. // Opmodes should be removed
  26. // They don't seem to be necessary any more
  27. DECLARE_INFOLEVEL(thk1);
  28. DECLARE_INFOLEVEL(Stack1);
  29. CMapHandleEtask NEAR v_mapToEtask(MEMCTX_SHARED);
  30. //+---------------------------------------------------------------------------
  31. //
  32. // Function: LibMain, public
  33. //
  34. // Synopsis: DLL initialization function
  35. //
  36. // Arguments: [hinst] - Instance handle
  37. // [wDataSeg] - Current DS
  38. // [cbHeapSize] - Heap size for the DLL
  39. // [lpszCmdLine] - Command line information
  40. //
  41. // Returns: One for success, zero for failure
  42. //
  43. // History: 21-Feb-94 DrewB Created
  44. //
  45. //----------------------------------------------------------------------------
  46. #if DBG == 1
  47. static char achInfoLevel[32];
  48. #endif
  49. extern "C" int CALLBACK LibMain(HINSTANCE hinst,
  50. WORD wDataSeg,
  51. WORD cbHeapSize,
  52. LPSTR lpszCmdLine)
  53. {
  54. #if DBG == 1
  55. if (GetProfileString("olethk32", "InfoLevel", "3", achInfoLevel,
  56. sizeof(achInfoLevel)) > 0)
  57. {
  58. thk1InfoLevel = strtoul(achInfoLevel, NULL, 0);
  59. }
  60. #endif
  61. thkDebugOut((DEB_DLLS16, "CompObj16: LibMain called on Process (%X) \n", GetCurrentProcess() ));
  62. if (!Call32Initialize())
  63. {
  64. return 0;
  65. }
  66. #ifdef _DEBUG
  67. v_mapToEtask.AssertValid();
  68. #endif
  69. UNREFERENCED(cbHeapSize);
  70. // Leave our DS unlocked when we're not running
  71. UnlockData( 0 );
  72. #if defined(_CHIC_INIT_IN_LIBMAIN_)
  73. if (SetupSharedAllocator(getask) == FALSE)
  74. {
  75. return FALSE;
  76. }
  77. #endif // _CHIC_INIT_IN_LIBMAIN_
  78. thkDebugOut((DEB_DLLS16, "CompObj16: LibMain called on Process (%X) Exitype (%ld)\n", GetCurrentProcess() ));
  79. return TRUE;
  80. }
  81. //+---------------------------------------------------------------------------
  82. //
  83. // Function: WEP, public
  84. //
  85. // Synopsis: Windows Exit Point routine, for receiving DLL unload
  86. // notification
  87. //
  88. // Arguments: [nExitType] - Type of exit occurring
  89. //
  90. // Returns: One for success, zero for failure
  91. //
  92. // History: 21-Feb-94 DrewB Created
  93. //
  94. // Note: Does nothing on WIN95. Call32Unitialize is called in
  95. // DllEntryPoint when load count goes to zero.
  96. //
  97. //----------------------------------------------------------------------------
  98. extern "C" int CALLBACK WEP(int nExitType)
  99. {
  100. thkDebugOut((DEB_DLLS16, "CompObj16: WEP called on Process (%X) Exitype (%ld)\n", GetCurrentProcess(),nExitType));
  101. HTASK htask;
  102. Etask etask;
  103. if (LookupEtask(htask, etask))
  104. {
  105. //
  106. // There is an etask. Check to see if the etask for this task has
  107. // its init count set to ETASK_FAKE_INIT. If it does, we cheated
  108. // and called CoInitialize on the processes behalf, but it never
  109. // called CoUninitialize(). Some apps that only make storage calls
  110. // demonstrate this behaviour. If it is ETASK_FAKE_INIT, then we
  111. // are going to call CoUninitialize on the apps behalf.
  112. //
  113. if (etask.m_inits == ETASK_FAKE_INIT)
  114. {
  115. //
  116. // We are going to set the m_inits == 1, since we called it
  117. // once. Then we are going to call our very own CoUninitialize()
  118. // to let it handle the rest of the cleanup.
  119. //
  120. etask.m_inits = 1;
  121. thkVerify(SetEtask(htask, etask));
  122. CoUninitialize();
  123. }
  124. }
  125. //
  126. // Now uninit the thunk layer
  127. //
  128. Call32Uninitialize();
  129. thkDebugOut((DEB_DLLS16, "CompObj16: WEP called on Process (%X) done\n", GetCurrentProcess()));
  130. return 1;
  131. }