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.

214 lines
5.5 KiB

  1. // BitmapSurfaces.cpp : Implementation of DLL Exports.
  2. // You will need the NT SUR Beta 2 SDK or VC 4.2 in order to build this
  3. // project. This is because you will need MIDL 3.00.15 or higher and new
  4. // headers and libs. If you have VC 4.2 installed, then everything should
  5. // already be configured correctly.
  6. // Note: Proxy/Stub Information
  7. // To merge the proxy/stub code into the object DLL, add the file
  8. // dlldatax.c to the project. Make sure precompiled headers
  9. // are turned off for this file, and add _MERGE_PROXYSTUB to the
  10. // defines for the project.
  11. //
  12. // Modify the custom build rule for BitmapSurfaces.idl by adding the following
  13. // files to the Outputs. You can select all of the .IDL files by
  14. // expanding each project and holding Ctrl while clicking on each of them.
  15. // BitmapSurfaces_p.c
  16. // dlldata.c
  17. // To build a separate proxy/stub DLL,
  18. // run nmake -f BitmapSurfacesps.mak in the project directory.
  19. #include "stdafx.h"
  20. #include "resource.h"
  21. #include <advpub.h>
  22. #include "initguid.h"
  23. #include "imgutil.h"
  24. #include "csnfstrm.h"
  25. #include "cmimeid.h"
  26. #include "cmapmime.h"
  27. #include "cdithtbl.h"
  28. #include "dithers.h"
  29. #include "cdith8.h"
  30. #include "dlldatax.h"
  31. #ifdef _MERGE_PROXYSTUB
  32. extern "C" HINSTANCE hProxyDll;
  33. #endif
  34. CComModule _Module;
  35. BEGIN_OBJECT_MAP( ObjectMap )
  36. OBJECT_ENTRY( CLSID_CoSniffStream, CSniffStream )
  37. OBJECT_ENTRY( CLSID_CoMapMIMEToCLSID, CMapMIMEToCLSID )
  38. #ifndef MINSUPPORT
  39. OBJECT_ENTRY( CLSID_CoDitherToRGB8, CDitherToRGB8 )
  40. #endif
  41. END_OBJECT_MAP()
  42. /////////////////////////////////////////////////////////////////////////////
  43. // DLL Entry Point
  44. extern "C"
  45. BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved )
  46. {
  47. lpReserved;
  48. #ifdef _MERGE_PROXYSTUB
  49. if (!PrxDllMain(hInstance, dwReason, lpReserved))
  50. return FALSE;
  51. #endif
  52. if (dwReason == DLL_PROCESS_ATTACH)
  53. {
  54. _Module.Init(ObjectMap, hInstance);
  55. DisableThreadLibraryCalls(hInstance);
  56. InitMIMEIdentifier();
  57. InitDefaultMappings();
  58. #ifndef MINSUPPORT
  59. CDitherToRGB8::InitTableCache();
  60. #endif
  61. }
  62. else if (dwReason == DLL_PROCESS_DETACH)
  63. {
  64. #ifndef MINSUPPORT
  65. CDitherToRGB8::CleanupTableCache();
  66. #endif
  67. CleanupMIMEIdentifier();
  68. CleanupDefaultMappings();
  69. _Module.Term();
  70. }
  71. return TRUE; // ok
  72. }
  73. /////////////////////////////////////////////////////////////////////////////
  74. // Used to determine whether the DLL can be unloaded by OLE
  75. STDAPI DllCanUnloadNow(void)
  76. {
  77. #ifdef _MERGE_PROXYSTUB
  78. if (PrxDllCanUnloadNow() != S_OK)
  79. return S_FALSE;
  80. #endif
  81. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  82. }
  83. /////////////////////////////////////////////////////////////////////////////
  84. // Returns a class factory to create an object of the requested type
  85. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  86. {
  87. #ifdef _MERGE_PROXYSTUB
  88. if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  89. return S_OK;
  90. #endif
  91. return( _Module.GetClassObject(rclsid, riid, ppv) );
  92. }
  93. /////////////////////////////////////////////////////////////////////////////
  94. // DllRegisterServer - Adds entries to the system registry
  95. STDAPI ie3_DllRegisterServer(void)
  96. {
  97. #ifdef _MERGE_PROXYSTUB
  98. HRESULT hRes = PrxDllRegisterServer();
  99. if (FAILED(hRes))
  100. return hRes;
  101. #endif
  102. // registers object, typelib and all interfaces in typelib
  103. return _Module.RegisterServer(FALSE);
  104. }
  105. /////////////////////////////////////////////////////////////////////////////
  106. // DllUnregisterServer - Removes entries from the system registry
  107. STDAPI ie3_DllUnregisterServer(void)
  108. {
  109. #ifdef _MERGE_PROXYSTUB
  110. PrxDllUnregisterServer();
  111. #endif
  112. _Module.UnregisterServer();
  113. return S_OK;
  114. }
  115. static HINSTANCE hAdvPackLib;
  116. REGINSTALL GetRegInstallFn(void)
  117. {
  118. hAdvPackLib = LoadLibraryA("advpack.dll");
  119. if (!hAdvPackLib)
  120. return NULL;
  121. return (REGINSTALL)GetProcAddress(hAdvPackLib, achREGINSTALL);
  122. }
  123. inline void UnloadAdvPack(void)
  124. {
  125. FreeLibrary(hAdvPackLib);
  126. }
  127. STDAPI ie4_DllRegisterServer(void)
  128. {
  129. REGINSTALL pfnReg = GetRegInstallFn();
  130. HRESULT hr;
  131. #ifdef _MERGE_PROXYSTUB
  132. HRESULT hRes = PrxDllRegisterServer();
  133. if (FAILED(hRes))
  134. return hRes;
  135. #endif
  136. if (pfnReg == NULL)
  137. return E_FAIL;
  138. // Delete any old registration entries, then add the new ones.
  139. hr = (*pfnReg)(_Module.GetResourceInstance(), "UnReg", NULL);
  140. if (SUCCEEDED(hr))
  141. hr = (*pfnReg)(_Module.GetResourceInstance(), "Reg", NULL);
  142. UnloadAdvPack();
  143. return hr;
  144. }
  145. STDAPI
  146. ie4_DllUnregisterServer(void)
  147. {
  148. REGINSTALL pfnReg = GetRegInstallFn();
  149. HRESULT hr;
  150. #ifdef _MERGE_PROXYSTUB
  151. PrxDllUnregisterServer();
  152. #endif
  153. if (pfnReg == NULL)
  154. return E_FAIL;
  155. hr = (*pfnReg)( _Module.GetResourceInstance(), "UnReg", NULL);
  156. UnloadAdvPack();
  157. return hr;
  158. }
  159. STDAPI DllRegisterServer(void)
  160. {
  161. REGINSTALL pfnReg = GetRegInstallFn();
  162. UnloadAdvPack();
  163. if (pfnReg)
  164. return ie4_DllRegisterServer();
  165. else
  166. return ie3_DllRegisterServer();
  167. }
  168. STDAPI
  169. DllUnregisterServer(void)
  170. {
  171. REGINSTALL pfnReg = GetRegInstallFn();
  172. UnloadAdvPack();
  173. if (pfnReg)
  174. return ie4_DllUnregisterServer();
  175. else
  176. return ie3_DllUnregisterServer();
  177. }