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.

187 lines
4.4 KiB

  1. //
  2. // MODULE: TSHOOT.CPP
  3. //
  4. // PURPOSE: Implementation of CTSHOOTApp and DLL registration.
  5. //
  6. // PROJECT: Generic Troubleshooter DLL for Microsoft AnswerPoint
  7. //
  8. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  9. //
  10. // AUTHOR: Roman Mach
  11. //
  12. // ORIGINAL DATE: 8/7/97
  13. //
  14. // NOTES:
  15. // 1.
  16. //
  17. // Version Date By Comments
  18. //--------------------------------------------------------------------
  19. // V0.2 8/7/97 RM Local Version for Memphis
  20. // V0.3 04/09/98 JM/OK+ Local Version for NT5
  21. //
  22. #include "stdafx.h"
  23. #include "TSHOOT.h"
  24. #include "apgts.h"
  25. #include "ErrorEnums.h"
  26. #include "BasicException.h"
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. CTSHOOTApp NEAR theApp;
  33. const GUID CDECL BASED_CODE _tlid =
  34. { 0x4b106871, 0xdd36, 0x11d0, { 0x8b, 0x44, 0, 0xa0, 0x24, 0xdd, 0x9e, 0xff } };
  35. const WORD _wVerMajor = 1;
  36. const WORD _wVerMinor = 0;
  37. ////////////////////////////////////////////////////////////////////////////
  38. // CTSHOOTApp::InitInstance - DLL initialization
  39. BOOL CTSHOOTApp::InitInstance()
  40. {
  41. BOOL bInit = COleControlModule::InitInstance();
  42. if (bInit)
  43. {
  44. ::AfxOleInit();
  45. }
  46. return bInit;
  47. }
  48. ////////////////////////////////////////////////////////////////////////////
  49. // CTSHOOTApp::ExitInstance - DLL termination
  50. int CTSHOOTApp::ExitInstance()
  51. {
  52. // TODO: Add your own module termination code here.
  53. return COleControlModule::ExitInstance();
  54. }
  55. /////////////////////////////////////////////////////////////////////////////
  56. // DllRegisterServer - Adds entries to the system registry
  57. STDAPI DllRegisterServer(void)
  58. {
  59. AFX_MANAGE_STATE(_afxModuleAddrThis);
  60. if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
  61. return ResultFromScode(SELFREG_E_TYPELIB);
  62. if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
  63. return ResultFromScode(SELFREG_E_CLASS);
  64. return NOERROR;
  65. }
  66. /////////////////////////////////////////////////////////////////////////////
  67. // DllUnregisterServer - Removes entries from the system registry
  68. STDAPI DllUnregisterServer(void)
  69. {
  70. AFX_MANAGE_STATE(_afxModuleAddrThis);
  71. if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
  72. return ResultFromScode(SELFREG_E_TYPELIB);
  73. if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
  74. return ResultFromScode(SELFREG_E_CLASS);
  75. return NOERROR;
  76. }
  77. void ReportError(DLSTATTYPES Error)
  78. {
  79. CBasicException *pBExc = new CBasicException;
  80. pBExc->m_dwBErr = Error;
  81. throw pBExc;
  82. return;
  83. }
  84. // ReportWFEvent (Based on Microsoft code)
  85. //
  86. // report an event to the NT event watcher
  87. // pass 1, 2 or 3 strings
  88. //
  89. // no return value
  90. VOID ReportWFEvent(LPTSTR string1,LPTSTR string2,LPTSTR string3,LPTSTR string4,DWORD eventID)
  91. {
  92. CBasicException *pBExc = new CBasicException;
  93. pBExc->m_dwBErr = (DLSTATTYPES) eventID;
  94. throw pBExc;
  95. return;
  96. /*
  97. HANDLE hEvent;
  98. PTSTR pszaStrings[4];
  99. WORD cStrings;
  100. cStrings = 0;
  101. if ((pszaStrings[0] = string1) && (string1[0])) cStrings++;
  102. if ((pszaStrings[1] = string2) && (string2[0])) cStrings++;
  103. if ((pszaStrings[2] = string3) && (string3[0])) cStrings++;
  104. if ((pszaStrings[3] = string4) && (string4[0])) cStrings++;
  105. if (cStrings == 0)
  106. return;
  107. hEvent = RegisterEventSource(
  108. NULL, // server name for source (NULL means this computer)
  109. REG_EVT_ITEM_STR); // source name for registered handle
  110. if (hEvent) {
  111. ReportEvent(hEvent, // handle returned by RegisterEventSource
  112. evtype(eventID), // event type to log
  113. 0, // event category
  114. eventID, // event identifier
  115. 0, // user security identifier (optional)
  116. cStrings, // number of strings to merge with message
  117. 0, // size of binary data, in bytes
  118. (LPCTSTR *)pszaStrings, // array of strings to merge with message
  119. NULL); // address of binary data
  120. DeregisterEventSource(hEvent);
  121. }
  122. */
  123. }
  124. /*
  125. Addbackslash appends a \ to null terminated strings that do
  126. not already have a \.
  127. */
  128. void _addbackslash(LPTSTR sz)
  129. {
  130. int len = _tcslen(sz);
  131. if (len && (0 == _tcsncmp(&sz[len - 1], _T("/"), 1)))
  132. {
  133. sz[len - 1] = _T('\\');
  134. }
  135. else if (len && (0 != _tcsncmp(&sz[len - 1], _T("\\"), 1)))
  136. {
  137. sz[len] = _T('\\');
  138. sz[len + 1] = NULL;
  139. }
  140. return;
  141. }
  142. void _addforwardslash(LPTSTR sz)
  143. {
  144. int len = _tcslen(sz);
  145. if (len && (0 == _tcsncmp(&sz[len - 1], _T("\\"), 1)))
  146. {
  147. sz[len - 1] = _T('/');
  148. }
  149. else if (len && (0 != _tcsncmp(&sz[len - 1], _T("/"), 1)))
  150. {
  151. sz[len] = _T('/');
  152. sz[len + 1] = NULL;
  153. }
  154. return;
  155. }