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.

141 lines
4.1 KiB

  1. // Copyright (c) Microsoft Corporation
  2. // dll1.cpp
  3. #include "stdinc.h"
  4. #include "resource.h"
  5. #include "initguid.h"
  6. #include "sxstest_idl.h"
  7. #include "CFreeThreaded.h"
  8. #include "CSingleThreaded.h"
  9. #include "CApartmentThreaded.h"
  10. #include "CBothThreaded.h"
  11. #include "CSingleThreadedDual.h"
  12. #include "dlldatax.h"
  13. #include <stdio.h>
  14. #define NUMBER_OF(x) (sizeof(x)/sizeof((x)[0]))
  15. #ifdef _MERGE_PROXYSTUB
  16. extern "C" HINSTANCE hProxyDll;
  17. #endif
  18. CComModule _Module;
  19. #include "sxstest_trace.cpp"
  20. #include "sxstest_formatguid.cpp"
  21. BEGIN_OBJECT_MAP(ObjectMap)
  22. OBJECT_ENTRY(CLSID_CSxsTest_FreeThreaded, CFreeThreaded)
  23. OBJECT_ENTRY(CLSID_CSxsTest_SingleThreaded, CSingleThreaded)
  24. OBJECT_ENTRY(CLSID_CSxsTest_ApartmentThreaded, CApartmentThreaded)
  25. OBJECT_ENTRY(CLSID_CSxsTest_BothThreaded, CCBothThreaded)
  26. OBJECT_ENTRY(CLSID_CSxsTest_SingleThreadedDual, CSingleThreadedDual)
  27. END_OBJECT_MAP()
  28. /////////////////////////////////////////////////////////////////////////////
  29. // DLL Entry Point
  30. extern "C" BOOL WINAPI _DllMainCRTStartup(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved);
  31. extern "C"
  32. BOOL WINAPI SxsTest_Dll1_DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  33. {
  34. lpReserved;
  35. #ifdef _MERGE_PROXYSTUB
  36. if (!PrxDllMain(hInstance, dwReason, lpReserved))
  37. return FALSE;
  38. #endif
  39. if (dwReason == DLL_PROCESS_ATTACH)
  40. {
  41. _Module.Init(ObjectMap, hInstance /*, &LIBID_ATL_DLL1Lib */);
  42. DisableThreadLibraryCalls(hInstance);
  43. }
  44. else if (dwReason == DLL_PROCESS_DETACH)
  45. _Module.Term();
  46. return TRUE; // ok
  47. }
  48. extern "C"
  49. BOOL WINAPI DllEntry(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  50. {
  51. DWORD Detach = DLL_PROCESS_DETACH;
  52. switch (dwReason)
  53. {
  54. case DLL_THREAD_ATTACH:
  55. Detach = DLL_THREAD_DETACH; // FALLTHROUGH
  56. case DLL_PROCESS_ATTACH:
  57. if (!_DllMainCRTStartup(hInstance, dwReason, lpReserved))
  58. return FALSE;
  59. if (!SxsTest_Dll1_DllMain(hInstance, dwReason, lpReserved))
  60. {
  61. _DllMainCRTStartup(hInstance, Detach, lpReserved);
  62. return FALSE;
  63. }
  64. return TRUE;
  65. case DLL_THREAD_DETACH:
  66. case DLL_PROCESS_DETACH:
  67. SxsTest_Dll1_DllMain(hInstance, dwReason, lpReserved);
  68. _DllMainCRTStartup(hInstance, dwReason, lpReserved);
  69. return TRUE;
  70. default:
  71. return FALSE;
  72. }
  73. return FALSE;
  74. }
  75. /////////////////////////////////////////////////////////////////////////////
  76. // Used to determine whether the DLL can be unloaded by OLE
  77. STDAPI DllCanUnloadNow(void)
  78. {
  79. #ifdef _MERGE_PROXYSTUB
  80. if (PrxDllCanUnloadNow() != S_OK)
  81. return S_FALSE;
  82. #endif
  83. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  84. }
  85. /////////////////////////////////////////////////////////////////////////////
  86. // Returns a class factory to create an object of the requested type
  87. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  88. {
  89. WCHAR ClsidBuffer[64];
  90. WCHAR IidBuffer[64];
  91. PrintComctl32Path("DllGetClassObject");
  92. FormatGuid(ClsidBuffer, NUMBER_OF(ClsidBuffer), rclsid);
  93. FormatGuid(IidBuffer, NUMBER_OF(IidBuffer), riid);
  94. Trace("DllGetClassObject(clsid={%ls}, iid={%ls}\n", ClsidBuffer, IidBuffer);
  95. #ifdef _MERGE_PROXYSTUB
  96. if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  97. return S_OK;
  98. #endif
  99. return _Module.GetClassObject(rclsid, riid, ppv);
  100. }
  101. /////////////////////////////////////////////////////////////////////////////
  102. // DllRegisterServer - Adds entries to the system registry
  103. STDAPI DllRegisterServer(void)
  104. {
  105. #ifdef _MERGE_PROXYSTUB
  106. HRESULT hRes = PrxDllRegisterServer();
  107. if (FAILED(hRes))
  108. return hRes;
  109. #endif
  110. // registers object, typelib and all interfaces in typelib
  111. return _Module.RegisterServer(FALSE);
  112. }
  113. /////////////////////////////////////////////////////////////////////////////
  114. // DllUnregisterServer - Removes entries from the system registry
  115. STDAPI DllUnregisterServer(void)
  116. {
  117. #ifdef _MERGE_PROXYSTUB
  118. PrxDllUnregisterServer();
  119. #endif
  120. return _Module.UnregisterServer(TRUE);
  121. }