TCObj.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /////////////////////////////////////////////////////////////////////////////
  2. // TCObj.cpp | Implementation of DLL Exports.
  3. //
  4. #include "pch.h"
  5. #include "SrcInc.h"
  6. #include <TCObj.h>
  7. #include <..\TCLib\WinApp.h>
  8. #include "TCIDL_i.c"
  9. #include "TCObj_i.c"
  10. /////////////////////////////////////////////////////////////////////////////
  11. // Note: Proxy/Stub Information
  12. // To merge the proxy/stub code into the object DLL, add the file
  13. // dlldatax.c to the project. Make sure precompiled headers
  14. // are turned off for this file, and add _MERGE_PROXYSTUB to the
  15. // defines for the project.
  16. //
  17. // If you are not running WinNT4.0 or Win95 with DCOM, then you
  18. // need to remove the following define from dlldatax.c
  19. // #define _WIN32_WINNT 0x0400
  20. //
  21. // Further, if you are running MIDL without /Oicf switch, you also
  22. // need to remove the following define from dlldatax.c.
  23. // #define USE_STUBLESS_PROXY
  24. //
  25. // Modify the custom build rule for TCObj.idl by adding the following
  26. // files to the Outputs.
  27. // TCObj_p.c
  28. // dlldata.c
  29. // To build a separate proxy/stub DLL,
  30. // run nmake -f TCObjps.mk in the project directory.
  31. /////////////////////////////////////////////////////////////////////////////
  32. // External Declarations
  33. TC_OBJECT_EXTERN(CTCStrings)
  34. TC_OBJECT_EXTERN(CTCMarshalByValue)
  35. TC_OBJECT_EXTERN(CTCNullStream)
  36. //TC_OBJECT_EXTERN(CTCPropBagOnRegKey)
  37. TC_OBJECT_EXTERN(CTCUtility)
  38. /////////////////////////////////////////////////////////////////////////////
  39. // Global Initialization
  40. #ifdef _MERGE_PROXYSTUB
  41. extern "C" HINSTANCE hProxyDll;
  42. #endif
  43. CComModule _Module; // ATL mandatory symbol
  44. TCWinAppDLL g_app;
  45. /////////////////////////////////////////////////////////////////////////////
  46. // Object Map
  47. BEGIN_OBJECT_MAP(ObjectMap)
  48. TC_OBJECT_ENTRY_STD(TCStrings)
  49. TC_OBJECT_ENTRY_STD(TCMarshalByValue)
  50. TC_OBJECT_ENTRY_STD(TCNullStream)
  51. // TC_OBJECT_ENTRY_STD(TCPropBagOnRegKey)
  52. TC_OBJECT_ENTRY_STD(TCUtility)
  53. END_OBJECT_MAP()
  54. /////////////////////////////////////////////////////////////////////////////
  55. // DLL Entry Point
  56. extern "C"
  57. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  58. {
  59. lpReserved;
  60. #ifdef _MERGE_PROXYSTUB
  61. if (!PrxDllMain(hInstance, dwReason, lpReserved))
  62. return false;
  63. #endif
  64. if (DLL_PROCESS_ATTACH == dwReason)
  65. {
  66. TRACE_MODULE_INIT(hInstance, true);
  67. _Module.Init(ObjectMap, hInstance);
  68. DisableThreadLibraryCalls(hInstance);
  69. }
  70. else if (DLL_PROCESS_DETACH == dwReason)
  71. {
  72. _Module.Term();
  73. TRACE_MODULE_INIT(hInstance, false);
  74. }
  75. return true; // ok
  76. }
  77. /////////////////////////////////////////////////////////////////////////////
  78. // Used to determine whether the DLL can be unloaded by OLE
  79. STDAPI DllCanUnloadNow(void)
  80. {
  81. #ifdef _MERGE_PROXYSTUB
  82. if (S_OK != PrxDllCanUnloadNow())
  83. return S_FALSE;
  84. #endif
  85. return _Module.GetLockCount() ? S_FALSE : S_OK;
  86. }
  87. /////////////////////////////////////////////////////////////////////////////
  88. // Returns a class factory to create an object of the requested type
  89. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  90. {
  91. // Initialize the application, if needed
  92. g_papp->Initialize(ZString());
  93. #ifdef _MERGE_PROXYSTUB
  94. if (S_OK == PrxDllGetClassObject(rclsid, riid, ppv))
  95. return S_OK;
  96. #endif
  97. return _Module.GetClassObject(rclsid, riid, ppv);
  98. }
  99. /////////////////////////////////////////////////////////////////////////////
  100. // DllRegisterServer - Adds entries to the system registry
  101. STDAPI DllRegisterServer(void)
  102. {
  103. #ifdef _MERGE_PROXYSTUB
  104. RETURN_FAILED(PrxDllRegisterServer());
  105. #endif
  106. // registers object, typelib and all interfaces in typelib
  107. RETURN_FAILED(_Module.RegisterServer(TRUE));
  108. // Register the component category
  109. return RegisterComponentCategory(CATID_TCObj,
  110. L"Allegiance Test Common Objects");
  111. }
  112. /////////////////////////////////////////////////////////////////////////////
  113. // DllUnregisterServer - Removes entries from the system registry
  114. STDAPI DllUnregisterServer(void)
  115. {
  116. #ifdef _MERGE_PROXYSTUB
  117. PrxDllUnregisterServer();
  118. #endif
  119. // Unregister the component category
  120. UnregisterComponentCategory(CATID_TCObj);
  121. _Module.UnregisterServer();
  122. return S_OK;
  123. }