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.

95 lines
2.0 KiB

  1. #include "stdafx.h"
  2. #include "Notify.h"
  3. extern
  4. HRESULT
  5. SendMail
  6. (
  7. IN LPCTSTR lpszFrom,
  8. IN LPCTSTR lpszTo,
  9. IN LPCTSTR lpszSubject,
  10. IN LPCTSTR lpszMessage,
  11. IN short nImportance
  12. );
  13. CNotify::CNotify(LPCTSTR lpszNotifyWho, LPCTSTR lpszNotifyWhat)
  14. {
  15. _ASSERTE(lpszNotifyWho != NULL);
  16. m_lpszNotifyWho = new TCHAR[_tcslen(lpszNotifyWho) + 1];
  17. _ASSERTE(m_lpszNotifyWho != NULL);
  18. if(m_lpszNotifyWho) _tcscpy(m_lpszNotifyWho, lpszNotifyWho);
  19. m_lpszNotifyWhat = new TCHAR[_tcslen(lpszNotifyWhat) + 1];
  20. _ASSERTE(m_lpszNotifyWhat != NULL);
  21. if(m_lpszNotifyWhat) _tcscpy(m_lpszNotifyWhat, lpszNotifyWhat);
  22. }
  23. CNotify::~CNotify()
  24. {
  25. if(m_lpszNotifyWho) delete [] m_lpszNotifyWho;
  26. if(m_lpszNotifyWhat) delete [] m_lpszNotifyWhat;
  27. m_lpszNotifyWho = NULL;
  28. m_lpszNotifyWhat = NULL;
  29. }
  30. DWORD CNotify::Notify()
  31. {
  32. _ASSERTE(m_lpszNotifyWho!= NULL);
  33. DWORD dwLastRet = 0L;
  34. if(!m_lpszNotifyWho) return dwLastRet;
  35. if(ShouldNetSend() == true){
  36. dwLastRet = NetSend();
  37. }
  38. else {
  39. dwLastRet = EMail();
  40. }
  41. return dwLastRet;
  42. }
  43. DWORD CNotify::NetSend()
  44. {
  45. DWORD dwLastRet = 0L;
  46. TCHAR *lpszCmd = NULL;
  47. _ASSERTE(m_lpszNotifyWho != NULL);
  48. if(!m_lpszNotifyWho) return dwLastRet;
  49. lpszCmd = new TCHAR[ _tcslen(_T("net send")) + _tcslen(m_lpszNotifyWho) + _tcslen(m_lpszNotifyWhat) + 3]; // room for blank space and null
  50. dwLastRet = GetLastError();
  51. _ASSERTE(lpszCmd != NULL);
  52. if(!lpszCmd) return dwLastRet;
  53. _stprintf(lpszCmd, _T("%s %s %s"), _T("net send"), m_lpszNotifyWho, m_lpszNotifyWhat);
  54. _tsystem(lpszCmd);
  55. if(lpszCmd) delete [] lpszCmd;
  56. return (dwLastRet = 0L);
  57. }
  58. HRESULT CNotify::EMail()
  59. {
  60. // return S_OK;
  61. return SendMail(_T("ExceptionMonitor8.0"), m_lpszNotifyWho, _T("Exception Occured"), m_lpszNotifyWhat, 1);
  62. }
  63. bool CNotify::ShouldNetSend()
  64. {
  65. bool bRet = true; // Assume NetSend.
  66. if(_tcschr(m_lpszNotifyWho, _T('@')) != NULL) bRet = false;
  67. return bRet;
  68. }