Source code of Windows XP (NT5)
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.

129 lines
2.5 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "COSInfoService.h"
  4. COSInfoService::COSInfoService()
  5. {
  6. m_MachineName = NULL;
  7. m_pEventSink = NULL;
  8. }
  9. HRESULT COSInfoService::FinalConstruct()
  10. {
  11. HRESULT hr = S_OK;
  12. m_OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  13. if (0 == GetVersionEx(reinterpret_cast<LPOSVERSIONINFO>(&m_OSVersionInfo)))
  14. {
  15. hr = E_FAIL;
  16. }
  17. if(SUCCEEDED(hr))
  18. {
  19. TCHAR szMachineName[MAX_COMPUTERNAME_LENGTH+1];
  20. DWORD dwSize = sizeof(szMachineName) / sizeof(TCHAR); // REVIEW: extend for DNS names?
  21. if(0 != GetComputerName(szMachineName, &dwSize))
  22. {
  23. m_MachineName = SysAllocString(szMachineName);
  24. if(NULL == m_MachineName)
  25. {
  26. hr = E_OUTOFMEMORY;
  27. }
  28. }
  29. else
  30. {
  31. hr = E_FAIL;
  32. }
  33. }
  34. return hr;
  35. }
  36. HRESULT COSInfoService::FinalRelease()
  37. {
  38. HRESULT hr = S_OK;
  39. if(NULL != m_MachineName)
  40. {
  41. SysFreeString(m_MachineName);
  42. }
  43. return hr;
  44. }
  45. // IUPnPEventSource methods
  46. STDMETHODIMP COSInfoService::Advise(IUPnPEventSink *pesSubscriber)
  47. {
  48. HRESULT hr = S_OK;
  49. if(NULL == m_pEventSink)
  50. {
  51. m_pEventSink = pesSubscriber;
  52. m_pEventSink->AddRef();
  53. }
  54. else
  55. {
  56. hr = E_UNEXPECTED;
  57. }
  58. return hr;
  59. }
  60. STDMETHODIMP COSInfoService::Unadvise(IUPnPEventSink *pesSubscriber)
  61. {
  62. HRESULT hr = S_OK;
  63. m_pEventSink->Release();
  64. m_pEventSink = NULL;
  65. return hr;
  66. }
  67. // Functions for IOSInfoService
  68. STDMETHODIMP COSInfoService::get_OSMajorVersion(LONG* pOSMajorVersion)
  69. {
  70. HRESULT hr = S_OK;
  71. *pOSMajorVersion = m_OSVersionInfo.dwMajorVersion;
  72. return hr;
  73. }
  74. STDMETHODIMP COSInfoService::get_OSMinorVersion(LONG* pOSMinorVersion)
  75. {
  76. HRESULT hr = S_OK;
  77. *pOSMinorVersion = m_OSVersionInfo.dwMinorVersion;
  78. return hr;
  79. }
  80. STDMETHODIMP COSInfoService::get_OSBuildNumber(LONG* pOSBuildNumber)
  81. {
  82. HRESULT hr = S_OK;
  83. *pOSBuildNumber = m_OSVersionInfo.dwBuildNumber;
  84. return hr;
  85. }
  86. STDMETHODIMP COSInfoService::get_OSMachineName(BSTR* pMachineName)
  87. {
  88. HRESULT hr = S_OK;
  89. *pMachineName = SysAllocString(m_MachineName);
  90. if(NULL == *pMachineName)
  91. {
  92. hr = E_OUTOFMEMORY;
  93. }
  94. return hr;
  95. }
  96. STDMETHODIMP COSInfoService::MagicOn()
  97. {
  98. // CHECK_POINTER(pbMagic);
  99. // TraceTag(ttidUPnPSampleDevice, "CInternetGatewayDevice::get_Magic");
  100. HRESULT hr = S_OK;
  101. // TraceHr(ttidUPnPSampleDevice, FAL, hr, FALSE, "CInternetGatewayDevice::get_Magic");
  102. return hr;
  103. }