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.

239 lines
5.1 KiB

  1. //=--------------------------------------------------------------------------=
  2. // insengmn.cpp
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1995-1996 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // various globals which the framewrk requires
  7. //
  8. //
  9. #include "inspch.h"
  10. #include "insobj.h"
  11. #include "insfact.h"
  12. #include "sitefact.h"
  13. #include "insengmn.h"
  14. #include "resource.h"
  15. #include "advpub.h"
  16. LONG g_cLocks = 0;
  17. HINSTANCE g_hInstance = NULL;
  18. HANDLE g_hHeap = NULL;
  19. CRITICAL_SECTION g_cs = {0}; // per-instance
  20. #define GUID_STR_LEN 40
  21. //
  22. // helper macros
  23. //
  24. OBJECTINFO g_ObjectInfo[] =
  25. {
  26. { NULL, &CLSID_InstallEngine, NULL, OI_COCREATEABLE, "InstallEngine",
  27. MAKEINTRESOURCE(IDS_INSTALLENGINE), NULL, NULL, VERSION_0, 0, 0 },
  28. { NULL, &CLSID_DownloadSiteMgr, NULL, OI_COCREATEABLE, "DownloadSiteMgr",
  29. MAKEINTRESOURCE(IDS_DOWNLOADSITEMGR), NULL, NULL, VERSION_0, 0, 0 },
  30. { NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, 0, 0, 0 },
  31. } ;
  32. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
  33. {
  34. if((riid == IID_IClassFactory) || (riid == IID_IUnknown))
  35. {
  36. const OBJECTINFO *pcls;
  37. for (pcls = g_ObjectInfo; pcls->pclsid; pcls++)
  38. {
  39. if(rclsid == *pcls->pclsid)
  40. {
  41. *ppv = pcls->cf;
  42. ((IUnknown *)*ppv)->AddRef();
  43. return NOERROR;
  44. }
  45. }
  46. }
  47. *ppv = NULL;
  48. return CLASS_E_CLASSNOTAVAILABLE;
  49. }
  50. STDAPI DllCanUnloadNow(void)
  51. {
  52. if (g_cLocks)
  53. return S_FALSE;
  54. return S_OK;
  55. }
  56. void InitClassFactories()
  57. {
  58. g_ObjectInfo[0].cf = (void *) new CInstallEngineFactory();
  59. g_ObjectInfo[1].cf = (void *) new CSiteManagerFactory();
  60. }
  61. void DeleteClassFactories()
  62. {
  63. delete g_ObjectInfo[0].cf;
  64. delete g_ObjectInfo[1].cf;
  65. }
  66. STDAPI_(BOOL) DllMain(HANDLE hDll, DWORD dwReason, void *lpReserved)
  67. {
  68. DWORD dwThreadID;
  69. switch(dwReason)
  70. {
  71. case DLL_PROCESS_ATTACH:
  72. g_hInstance = (HINSTANCE)hDll;
  73. g_hHeap = GetProcessHeap();
  74. InitializeCriticalSection(&g_cs);
  75. DisableThreadLibraryCalls(g_hInstance);
  76. InitClassFactories();
  77. break;
  78. case DLL_PROCESS_DETACH:
  79. DeleteCriticalSection(&g_cs);
  80. DeleteClassFactories();
  81. break;
  82. default:
  83. break;
  84. }
  85. return TRUE;
  86. }
  87. void DllAddRef(void)
  88. {
  89. InterlockedIncrement(&g_cLocks);
  90. }
  91. void DllRelease(void)
  92. {
  93. InterlockedDecrement(&g_cLocks);
  94. }
  95. HRESULT PurgeDownloadDirectory(LPCSTR pszDownloadDir)
  96. {
  97. return DelNode(pszDownloadDir, ADN_DONT_DEL_DIR);
  98. }
  99. STDAPI DllRegisterServer(void)
  100. {
  101. // BUGBUG: pass back return from RegInstall ?
  102. RegInstall(g_hInstance, "DllReg", NULL);
  103. return S_OK;
  104. }
  105. STDAPI DllUnregisterServer(void)
  106. {
  107. RegInstall(g_hInstance, "DllUnreg", NULL);
  108. return S_OK;
  109. }
  110. STDAPI DllInstall(BOOL bInstall, LPCSTR lpCmdLine)
  111. {
  112. // BUGBUG: pass back return from RegInstall ?
  113. if (bInstall)
  114. RegInstall(g_hInstance, "DllInstall", NULL);
  115. else
  116. RegInstall(g_hInstance, "DllUninstall", NULL);
  117. return S_OK;
  118. }
  119. //=--------------------------------------------------------------------------=
  120. // CRT stubs
  121. //=--------------------------------------------------------------------------=
  122. // these two things are here so the CRTs aren't needed. this is good.
  123. //
  124. // basically, the CRTs define this to pull in a bunch of stuff. we'll just
  125. // define them here so we don't get an unresolved external.
  126. //
  127. // TODO: if you are going to use the CRTs, then remove this line.
  128. //
  129. extern "C" int _fltused = 1;
  130. extern "C" int _cdecl _purecall(void)
  131. {
  132. // FAIL("Pure virtual function called.");
  133. return 0;
  134. }
  135. void * _cdecl operator new
  136. (
  137. size_t size
  138. )
  139. {
  140. return HeapAlloc(g_hHeap, 0, size);
  141. }
  142. //=---------------------------------------------------------------------------=
  143. // overloaded delete
  144. //=---------------------------------------------------------------------------=
  145. // retail case just uses win32 Local* heap mgmt functions
  146. //
  147. // Parameters:
  148. // void * - [in] free me!
  149. //
  150. // Notes:
  151. //
  152. void _cdecl operator delete ( void *ptr)
  153. {
  154. HeapFree(g_hHeap, 0, ptr);
  155. }
  156. #ifndef _X86_
  157. extern "C" void _fpmath() {}
  158. #endif
  159. void * _cdecl malloc(size_t n)
  160. {
  161. #ifdef _MALLOC_ZEROINIT
  162. void* p = HeapAlloc(g_hHeap, 0, n);
  163. if (p != NULL)
  164. ZeroMemory(p, n);
  165. return p;
  166. #else
  167. return HeapAlloc(g_hHeap, 0, n);
  168. #endif
  169. }
  170. void * _cdecl calloc(size_t n, size_t s)
  171. {
  172. #ifdef _MALLOC_ZEROINIT
  173. return malloc(n * s);
  174. #else
  175. void* p = malloc(n * s);
  176. if (p != NULL)
  177. ZeroMemory(p, n * s);
  178. return p;
  179. #endif
  180. }
  181. void* _cdecl realloc(void* p, size_t n)
  182. {
  183. if (p == NULL)
  184. return malloc(n);
  185. return HeapReAlloc(g_hHeap, 0, p, n);
  186. }
  187. void _cdecl free(void* p)
  188. {
  189. if (p == NULL)
  190. return;
  191. HeapFree(g_hHeap, 0, p);
  192. }