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.

230 lines
5.7 KiB

  1. /*===================================================================
  2. Microsoft Denali
  3. Microsoft Confidential.
  4. Copyright 1997 Microsoft Corporation. All Rights Reserved.
  5. Component: Transascted Scripts Context Object
  6. File: TxnScrpt.cpp
  7. Implementation of CASPObjectContext
  8. Owner: AndrewS
  9. ===================================================================*/
  10. #include "denpre.h"
  11. #pragma hdrstop
  12. #include "resource.h"
  13. #include <txnsupp.h>
  14. #include <atlbase.h>
  15. #if _IIS_5_1
  16. extern CWamModule _Module;
  17. #elif _IIS_6_0
  18. extern CComModule _Module;
  19. #else
  20. #error "Neither _IIS_6_0 nor _IIS_5_1 is defined"
  21. #endif
  22. #include <atlcom.h>
  23. #include <txnobj.h>
  24. #include <initguid.h>
  25. #include <txnscrpt_i.c>
  26. #include <atlimpl.cpp>
  27. // From denali.h
  28. extern HINSTANCE g_hinstDLL;
  29. class CASPObjectContextZombie :
  30. public CComObject<CASPObjectContext>
  31. {
  32. public:
  33. // These methods fail on a zombie context
  34. STDMETHOD(SetAbort)();
  35. STDMETHOD(SetComplete)();
  36. #ifdef _WIN64
  37. // Win64 fix -- use UINT64 instead of LONG_PTR since LONG_PTR is broken for Win64 1/21/2000
  38. STDMETHOD(Call)(UINT64 pvScriptEngine, LPCOLESTR strEntryPoint, boolean *pfAborted);
  39. STDMETHOD(ResetScript)(UINT64 pvScriptEngine);
  40. #else
  41. STDMETHOD(Call)(LONG_PTR pvScriptEngine, LPCOLESTR strEntryPoint, boolean *pfAborted);
  42. STDMETHOD(ResetScript)(LONG_PTR pvScriptEngine);
  43. #endif
  44. private:
  45. };
  46. //
  47. // atl requires that these be defined. I need to be able to load the
  48. // typelib from asptxn.dll in order to make the local declaration of
  49. // CASPObjectContextZombie
  50. //
  51. BEGIN_OBJECT_MAP(ObjectMap)
  52. END_OBJECT_MAP()
  53. /*===================================================================
  54. Globals
  55. ===================================================================*/
  56. /*
  57. * bug 86404: We want to have one "zombie" ObjectContext object that always
  58. * gives errors on all its methods.
  59. */
  60. IASPObjectContext * g_pIASPObjectContextZombie = NULL;
  61. static HINSTANCE g_hTxnModule = NULL;
  62. const char szTxnModuleName[] = "asptxn.dll";
  63. HRESULT TxnSupportInit()
  64. {
  65. DBG_ASSERT( g_pIASPObjectContextZombie == NULL );
  66. DBG_ASSERT( g_hTxnModule == NULL );
  67. HRESULT hr = S_OK;
  68. // Because we are in either inetinfo or dllhost, we need
  69. // to use the full library path to load the asptxn.dll.
  70. do // Protected block
  71. {
  72. DBG_ASSERT( g_hinstDLL );
  73. // Assume that we are in the same directory as asp.dll.
  74. char szTxnModulePath[MAX_PATH];
  75. DWORD dwErr = GetModuleFileNameA( g_hinstDLL,
  76. szTxnModulePath,
  77. sizeof(szTxnModulePath)/sizeof(szTxnModulePath[0])
  78. );
  79. if( dwErr == 0 )
  80. {
  81. hr = HRESULT_FROM_WIN32( GetLastError() );
  82. break;
  83. }
  84. char * psz = strrchr( szTxnModulePath, '\\' );
  85. if( psz != NULL )
  86. {
  87. strcpy( psz + 1, szTxnModuleName );
  88. }
  89. else
  90. {
  91. DBG_ASSERT(FALSE);
  92. strcpy( szTxnModulePath, szTxnModuleName );
  93. }
  94. g_hTxnModule = LoadLibraryA( szTxnModulePath );
  95. if( g_hTxnModule == NULL )
  96. {
  97. hr = HRESULT_FROM_WIN32( GetLastError() );
  98. DBG_ASSERT( FAILED(hr) );
  99. break;
  100. }
  101. // This is a somewhat sleazy way of allowing us to declare
  102. // the zombie context locally. If at some point the _Module
  103. // can be initied without a HINSTANCE, that would probably
  104. // be a good idea.
  105. _Module.Init( ObjectMap, g_hTxnModule );
  106. CASPObjectContextZombie * pZombie = new CASPObjectContextZombie();
  107. if( !pZombie )
  108. {
  109. hr = E_OUTOFMEMORY;
  110. break;
  111. }
  112. hr = pZombie->QueryInterface( IID_IASPObjectContext,
  113. (void **)&g_pIASPObjectContextZombie
  114. );
  115. } while(FALSE); // Protected block
  116. // This should NOT fail!!
  117. if( FAILED(hr) )
  118. {
  119. DBGPRINTF(( DBG_CONTEXT, "TxnSupportInit Failed: %08x", hr ));
  120. }
  121. DBG_ASSERT(SUCCEEDED(hr));
  122. return hr;
  123. }
  124. HRESULT TxnSupportUnInit()
  125. {
  126. DBG_ASSERT( g_pIASPObjectContextZombie != NULL );
  127. DBG_ASSERT( g_hTxnModule != NULL );
  128. if( g_pIASPObjectContextZombie )
  129. {
  130. g_pIASPObjectContextZombie->Release();
  131. g_pIASPObjectContextZombie = NULL;
  132. }
  133. if( g_hTxnModule )
  134. {
  135. FreeLibrary( g_hTxnModule );
  136. g_hTxnModule = NULL;
  137. }
  138. return S_OK;
  139. }
  140. STDMETHODIMP CASPObjectContextZombie::Call
  141. (
  142. #ifdef _WIN64
  143. // Win64 fix -- use UINT64 instead of LONG_PTR since LONG_PTR is broken for Win64 1/21/2000
  144. UINT64 pvScriptEngine /*CScriptEngine*/,
  145. #else
  146. LONG_PTR pvScriptEngine /*CScriptEngine*/,
  147. #endif
  148. LPCOLESTR strEntryPoint,
  149. boolean *pfAborted
  150. )
  151. {
  152. DBGPRINTF(( DBG_CONTEXT, "Invalid call on Zombie Context.\n" ));
  153. DBG_ASSERT(FALSE);
  154. return E_FAIL;
  155. }
  156. STDMETHODIMP CASPObjectContextZombie::ResetScript
  157. (
  158. #ifdef _WIN64
  159. // Win64 fix -- use UINT64 instead of LONG_PTR since LONG_PTR is broken for Win64 1/21/2000
  160. UINT64 pvScriptEngine /*CScriptEngine*/
  161. #else
  162. LONG_PTR pvScriptEngine /*CScriptEngine*/
  163. #endif
  164. )
  165. {
  166. DBGPRINTF(( DBG_CONTEXT, "Invalid call on Zombie Context.\n" ));
  167. DBG_ASSERT(FALSE);
  168. return E_FAIL;
  169. }
  170. STDMETHODIMP CASPObjectContextZombie::SetComplete()
  171. {
  172. DBGPRINTF(( DBG_CONTEXT, "Invalid call on Zombie Context.\n" ));
  173. ExceptionId(IID_IASPObjectContext, IDE_OBJECTCONTEXT, IDE_OBJECTCONTEXT_NOT_TRANSACTED);
  174. return E_FAIL;
  175. }
  176. STDMETHODIMP CASPObjectContextZombie::SetAbort()
  177. {
  178. DBGPRINTF(( DBG_CONTEXT, "Invalid call on Zombie Context.\n" ));
  179. ExceptionId(IID_IASPObjectContext, IDE_OBJECTCONTEXT, IDE_OBJECTCONTEXT_NOT_TRANSACTED);
  180. return E_FAIL;
  181. }