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.

124 lines
2.6 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // File: dlltest.cxx
  4. //
  5. // Contents: This file contins the DLL entry points
  6. // LibMain
  7. // DllGetClassObject (Bindings key func)
  8. // CAdvBndCF (class factory)
  9. // CAdvBnd (actual class implementation)
  10. //
  11. // Classes: CAdvBndCF, CAdvBnd
  12. //
  13. //
  14. // History: 30-Nov-92 SarahJ Created
  15. //
  16. //---------------------------------------------------------------------
  17. #include <windows.h>
  18. #include <ole2.h>
  19. // #include <debnot.h>
  20. #include <sem.hxx>
  21. #include <actcf.hxx>
  22. static GUID CLSID_TestNoRegister =
  23. {0x99999999,0x0000,0x0008,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x52}};
  24. static GUID CLSID_TestRegister =
  25. {0x99999999,0x0000,0x0008,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x53}};
  26. // The class objects can be totally static in a DLL
  27. CActClassFactory clsfactNoRegister(CLSID_TestNoRegister, FALSE);
  28. CActClassFactory clsfactRegister(CLSID_TestRegister, FALSE);
  29. CMutexSem mxsUnloadTest;
  30. BOOL fUnload = FALSE;
  31. DWORD dwRegistration;
  32. ULONG gUsage = 0;
  33. extern "C" BOOL WINAPI DllMain (HANDLE hDll,
  34. DWORD dwReason,
  35. LPVOID pvReserved)
  36. {
  37. return TRUE;
  38. }
  39. void GlobalRefs(BOOL fAddRef)
  40. {
  41. if (fAddRef)
  42. {
  43. gUsage++;
  44. }
  45. else
  46. {
  47. gUsage--;
  48. }
  49. }
  50. STDAPI DllCanUnloadNow(void)
  51. {
  52. CLock clk(mxsUnloadTest);
  53. if (gUsage == 0)
  54. {
  55. fUnload = TRUE;
  56. if (dwRegistration != 0)
  57. {
  58. HRESULT hr = CoRevokeClassObject(dwRegistration);
  59. Win4Assert(SUCCEEDED(hr) && "CoRevokeClassObject failed!!");
  60. }
  61. }
  62. return (gUsage == 0);
  63. }
  64. STDAPI DllGetClassObject(REFCLSID clsid, REFIID iid, void FAR* FAR* ppv)
  65. {
  66. CLock clk(mxsUnloadTest);
  67. if (fUnload)
  68. {
  69. return E_UNEXPECTED;
  70. }
  71. if (IsEqualCLSID(clsid, CLSID_TestNoRegister))
  72. {
  73. clsfactNoRegister.AddRef();
  74. *ppv = &clsfactNoRegister;
  75. }
  76. else if (IsEqualCLSID(clsid, CLSID_TestRegister))
  77. {
  78. clsfactNoRegister.AddRef();
  79. *ppv = &clsfactNoRegister;
  80. if (dwRegistration == 0)
  81. {
  82. // Register the class
  83. HRESULT hr = CoRegisterClassObject(CLSID_TestRegister,
  84. &clsfactRegister, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE,
  85. &dwRegistration);
  86. Win4Assert(SUCCEEDED(hr) && "CoRegisterClassObject failed!!");
  87. // Decrement the global reference count since the registration
  88. // bumped the reference count because it does an addref
  89. gUsage--;
  90. }
  91. }
  92. else
  93. {
  94. return E_UNEXPECTED;
  95. }
  96. return S_OK;
  97. }