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.

237 lines
5.5 KiB

  1. /*****************************************************************/
  2. /** Microsoft **/
  3. /** Copyright (C) Microsoft Corp., 1991-1998 **/
  4. /*****************************************************************/
  5. //
  6. // DLLENTRY.CPP -
  7. //
  8. // HISTORY:
  9. //
  10. // 05/14/98 donaldm created
  11. //
  12. #include "pre.h"
  13. #include "registry.h"
  14. #include "webvwids.h"
  15. // We encapsulate the control of this COM server (eg, lock and object
  16. // counting) in a server control C++ object. Here is it's pointer.
  17. CServer* g_pServer = NULL;
  18. const CLSID * aClassObjects[] =
  19. {
  20. &CLSID_ICWWEBVIEW,
  21. &CLSID_ICWWALKER,
  22. &CLSID_ICWGIFCONVERT,
  23. &CLSID_ICWISPDATA
  24. };
  25. #define NUM_CLASS_OBJECTS sizeof(aClassObjects) / sizeof(aClassObjects[0])
  26. #define MAX_ID_SIZE 100
  27. const TCHAR acszFriendlyNames[][MAX_ID_SIZE] =
  28. {
  29. TEXT("CLSID_ICWWebView"),
  30. TEXT("CLSID_ICWWalker"),
  31. TEXT("CLSID_ICWGifConvert"),
  32. TEXT("CLSID_ICWISPData")
  33. };
  34. const TCHAR acszIndProgIDs[][MAX_ID_SIZE] =
  35. {
  36. TEXT("ICWCONN.WebView"),
  37. TEXT("ICWCONN.Walker"),
  38. TEXT("ICWCONN.GifConvert"),
  39. TEXT("ICWCONN.ISPData")
  40. };
  41. const TCHAR acszProgIDs[][MAX_ID_SIZE] =
  42. {
  43. TEXT("ICWCONN.WebView.1"),
  44. TEXT("ICWCONN.Walker.1"),
  45. TEXT("ICWCONN.GifConvert.1"),
  46. TEXT("ICWCONN.ISPData.1")
  47. };
  48. // instance handle must be in per-instance data segment
  49. HINSTANCE ghInstance=NULL;
  50. INT _convert; // For string conversion
  51. const VARIANT c_vaEmpty = {0};
  52. void RegWebOCClass();
  53. typedef UINT RETERR;
  54. #ifdef __cplusplus
  55. extern "C"
  56. {
  57. #endif // __cplusplus
  58. BOOL _stdcall DllEntryPoint(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpReserved);
  59. #ifdef __cplusplus
  60. }
  61. #endif // __cplusplus
  62. /*******************************************************************
  63. NAME: DllEntryPoint
  64. SYNOPSIS: Entry point for DLL.
  65. NOTES: Initializes thunk layer to WIZ16.DLL
  66. ********************************************************************/
  67. BOOL _stdcall DllEntryPoint(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpReserved)
  68. {
  69. BOOL bRet = TRUE;
  70. if(fdwReason == DLL_PROCESS_ATTACH)
  71. {
  72. bRet = FALSE;
  73. // Instantiate the CServer utility class.
  74. g_pServer = new CServer;
  75. if (NULL != g_pServer)
  76. {
  77. // Remember the DLL Instance handle.
  78. g_pServer->m_hDllInst = hInstDll;
  79. ghInstance = hInstDll;
  80. // Register the window class that will be used to embed web browser object into dialogs
  81. RegWebOCClass();
  82. bRet = TRUE;
  83. }
  84. }
  85. if (fdwReason == DLL_PROCESS_DETACH)
  86. {
  87. if(g_pServer)
  88. {
  89. // We return S_OK of there are no longer any living objects AND
  90. // there are no outstanding client locks on this server.
  91. HRESULT hr = (0L==g_pServer->m_cObjects && 0L==g_pServer->m_cLocks) ? S_OK : S_FALSE;
  92. if(hr == S_OK)
  93. DELETE_POINTER(g_pServer);
  94. }
  95. }
  96. return bRet;
  97. }
  98. #ifdef __cplusplus
  99. extern "C"
  100. {
  101. #endif // __cplusplus
  102. void __cdecl main() {};
  103. #ifdef __cplusplus
  104. }
  105. #endif // __cplusplus
  106. ///////////////////////////////////////////////////////////
  107. //
  108. // Exported functions
  109. //
  110. // These are the functions that COM expects to find
  111. //
  112. //
  113. // Can DLL unload now?
  114. //
  115. STDAPI DllCanUnloadNow()
  116. {
  117. HRESULT hr = S_OK;
  118. if(g_pServer)
  119. {
  120. // We return S_OK of there are no longer any living objects AND
  121. // there are no outstanding client locks on this server.
  122. hr = (0L==g_pServer->m_cObjects && 0L==g_pServer->m_cLocks) ? S_OK : S_FALSE;
  123. if(hr == S_OK)
  124. DELETE_POINTER(g_pServer);
  125. }
  126. return hr;
  127. }
  128. //
  129. // Get class factory
  130. //
  131. STDAPI DllGetClassObject
  132. (
  133. const CLSID& rclsid,
  134. const IID& riid,
  135. void** ppv
  136. )
  137. {
  138. TraceMsg(TF_CLASSFACTORY, "DllGetClassObject:\tCreate class factory.") ;
  139. HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;
  140. IUnknown* pCob = NULL;
  141. hr = E_OUTOFMEMORY;
  142. pCob = new ClassFactory(g_pServer, &rclsid);
  143. if (NULL != pCob)
  144. {
  145. g_pServer->ObjectsUp();
  146. hr = pCob->QueryInterface(riid, ppv);
  147. if (FAILED(hr))
  148. {
  149. g_pServer->ObjectsDown();
  150. DELETE_POINTER(pCob);
  151. }
  152. }
  153. return hr;
  154. }
  155. // The following two exported functions are what regsvr32 uses to
  156. // self-register and unregister the dll. See REGISTRY.CPP for
  157. // actual implementation
  158. //
  159. // Server registration
  160. //
  161. STDAPI DllRegisterServer()
  162. {
  163. BOOL bRet = TRUE;
  164. for (int i = 0; i < NUM_CLASS_OBJECTS; i++)
  165. {
  166. bRet = RegisterServer(ghInstance,
  167. *aClassObjects[i],
  168. (LPTSTR)acszFriendlyNames[i],
  169. (LPTSTR)acszIndProgIDs[i],
  170. (LPTSTR)acszProgIDs[i]);
  171. }
  172. return (bRet ? S_OK : E_FAIL);
  173. }
  174. //
  175. // Server unregistration
  176. //
  177. STDAPI DllUnregisterServer()
  178. {
  179. BOOL bRet = TRUE;
  180. for (int i = 0; i < NUM_CLASS_OBJECTS; i++)
  181. {
  182. bRet = UnregisterServer(*aClassObjects[i],
  183. (LPTSTR)acszIndProgIDs[i],
  184. (LPTSTR)acszProgIDs[i]);
  185. }
  186. return (bRet ? S_OK : E_FAIL);
  187. }
  188. //