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.

107 lines
1.6 KiB

  1. #include "precomp.hpp"
  2. #include "comtest.h"
  3. #include "ComBase.hpp"
  4. #include "HelloWorld.hpp"
  5. #include <initguid.h>
  6. #include "comtest_i.c"
  7. HINSTANCE globalInstanceHandle = NULL;
  8. LONG globalComponentCount = 0;
  9. //
  10. // DLL entrypoint
  11. //
  12. extern "C" BOOL WINAPI
  13. DllMain(
  14. HINSTANCE hInstance,
  15. DWORD dwReason,
  16. VOID* lpReserved
  17. )
  18. {
  19. switch (dwReason)
  20. {
  21. case DLL_PROCESS_ATTACH:
  22. DisableThreadLibraryCalls(hInstance);
  23. globalInstanceHandle = hInstance;
  24. break;
  25. case DLL_PROCESS_DETACH:
  26. break;
  27. }
  28. return TRUE;
  29. }
  30. //
  31. // Determine whether the DLL can be safely unloaded
  32. //
  33. STDAPI
  34. DllCanUnloadNow()
  35. {
  36. return (globalComponentCount == 0) ? S_OK : S_FALSE;
  37. }
  38. //
  39. // Return a class factory object
  40. //
  41. STDAPI
  42. DllGetClassObject(
  43. REFCLSID rclsid,
  44. REFIID riid,
  45. VOID** ppv
  46. )
  47. {
  48. if (rclsid != CLSID_HelloWorld)
  49. return CLASS_E_CLASSNOTAVAILABLE;
  50. CHelloWorldFactory* factory = new CHelloWorldFactory();
  51. if (factory == NULL)
  52. return E_OUTOFMEMORY;
  53. HRESULT hr = factory->QueryInterface(riid, ppv);
  54. factory->Release();
  55. return hr;
  56. }
  57. //
  58. // Register our component
  59. //
  60. static const ComponentRegData compRegData =
  61. {
  62. &CLSID_HelloWorld,
  63. L"Skeleton COM Component",
  64. L"comtest.HelloWorld.1",
  65. L"comtest.HelloWorld"
  66. };
  67. STDAPI
  68. DllRegisterServer()
  69. {
  70. return RegisterComponent(compRegData, TRUE);
  71. }
  72. //
  73. // Unregister our component
  74. //
  75. STDAPI
  76. DllUnregisterServer()
  77. {
  78. return RegisterComponent(compRegData, FALSE);
  79. }