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.

163 lines
5.1 KiB

  1. #include <windows.h>
  2. #include <activscp.h>
  3. class CDeviceScriptSite : public IActiveScriptSite {
  4. private:
  5. ULONG m_dwRef;
  6. public:
  7. IUnknown *m_pUnkScriptObject;
  8. ITypeInfo *m_pTypeInfo;
  9. IUnknown *m_pUnkScriptObjectDeviceAction;
  10. ITypeInfo *m_pTypeInfoDeviceAction;
  11. IUnknown *m_pUnkScriptObjectDeviceControl;
  12. ITypeInfo *m_pTypeInfoDeviceControl;
  13. IUnknown *m_pUnkScriptObjectLastError;
  14. ITypeInfo *m_pTypeInfoLastError;
  15. CDeviceScriptSite::CDeviceScriptSite() {
  16. m_pUnkScriptObject = 0;
  17. m_pTypeInfo = 0;
  18. m_pUnkScriptObjectDeviceAction = 0;
  19. m_pTypeInfoDeviceAction = 0;
  20. m_pUnkScriptObjectDeviceControl = 0;
  21. m_pTypeInfoDeviceControl = 0;
  22. m_pUnkScriptObjectLastError = 0;
  23. m_pTypeInfoLastError = 0;
  24. m_dwRef = 1;
  25. }
  26. // IUnknown methods...
  27. virtual HRESULT __stdcall QueryInterface(REFIID riid,
  28. void **ppvObject) {
  29. *ppvObject = NULL;
  30. return E_NOTIMPL;
  31. }
  32. virtual ULONG _stdcall AddRef(void) {
  33. return ++m_dwRef;
  34. }
  35. virtual ULONG _stdcall Release(void) {
  36. if(--m_dwRef == 0) return 0;
  37. return m_dwRef;
  38. }
  39. // IActiveScriptSite methods...
  40. virtual HRESULT __stdcall GetLCID(LCID *plcid) {
  41. return S_OK;
  42. }
  43. virtual HRESULT __stdcall GetItemInfo(LPCOLESTR pstrName,
  44. DWORD dwReturnMask, IUnknown **ppunkItem, ITypeInfo **ppti) {
  45. // Is it expecting an ITypeInfo?
  46. if(ppti) {
  47. // Default to NULL.
  48. *ppti = NULL;
  49. // See if asking about ITypeInfo...
  50. //
  51. // Note: This needs to be done in a more efficient
  52. // way.
  53. //
  54. if(dwReturnMask & SCRIPTINFO_ITYPEINFO) {
  55. if (!_wcsicmp(L"DeviceProperty", pstrName)) {
  56. *ppti = m_pTypeInfo;
  57. } else if (!_wcsicmp(L"DeviceAction", pstrName)) {
  58. *ppti = m_pTypeInfoDeviceAction;
  59. } else if (!_wcsicmp(L"DeviceControl", pstrName)) {
  60. *ppti = m_pTypeInfoDeviceControl;
  61. } else if (!_wcsicmp(L"LastError", pstrName)) {
  62. *ppti = m_pTypeInfoLastError;
  63. }
  64. }
  65. }
  66. // Is the engine passing an IUnknown buffer?
  67. if(ppunkItem) {
  68. // Default to NULL.
  69. *ppunkItem = NULL;
  70. // Is Script Engine looking for an IUnknown for our object?
  71. //
  72. // Note: This needs to be done in a more efficient
  73. // way.
  74. //
  75. if(dwReturnMask & SCRIPTINFO_IUNKNOWN) {
  76. if (!_wcsicmp(L"DeviceProperty", pstrName)) {
  77. *ppunkItem = m_pUnkScriptObject;
  78. m_pUnkScriptObject->AddRef();
  79. } else if (!_wcsicmp(L"DeviceAction", pstrName)) {
  80. *ppunkItem = m_pUnkScriptObjectDeviceAction;
  81. m_pUnkScriptObjectDeviceAction->AddRef();
  82. } else if (!_wcsicmp(L"DeviceControl", pstrName)) {
  83. *ppunkItem = m_pUnkScriptObjectDeviceControl;
  84. m_pUnkScriptObjectDeviceControl->AddRef();
  85. } else if (!_wcsicmp(L"LastError", pstrName)) {
  86. *ppunkItem = m_pUnkScriptObjectLastError;
  87. m_pUnkScriptObjectLastError->AddRef();
  88. }
  89. }
  90. }
  91. return S_OK;
  92. }
  93. virtual HRESULT __stdcall GetDocVersionString(BSTR *pbstrVersion) {
  94. return S_OK;
  95. }
  96. virtual HRESULT __stdcall OnScriptTerminate(
  97. const VARIANT *pvarResult, const EXCEPINFO *pexcepInfo) {
  98. return S_OK;
  99. }
  100. virtual HRESULT __stdcall OnStateChange(SCRIPTSTATE ssScriptState) {
  101. return S_OK;
  102. }
  103. virtual HRESULT __stdcall OnScriptError(
  104. IActiveScriptError *pscriptError) {
  105. BSTR bstrSourceLine;
  106. DWORD dwSourceContext = 0;
  107. ULONG ulLineNumber = 0;
  108. LONG lchPosition = 0;
  109. HRESULT hr = S_OK;
  110. hr = pscriptError->GetSourceLineText(&bstrSourceLine);
  111. hr = pscriptError->GetSourcePosition(&dwSourceContext,&ulLineNumber,&lchPosition);
  112. TCHAR szErrorDescription[1024];
  113. memset(szErrorDescription,0,sizeof(szErrorDescription));
  114. #ifdef UNICODE
  115. swprintf(szErrorDescription,TEXT("SOURCE: %ws\nLINE: %d\nCHARACTER POS: %d"),
  116. bstrSourceLine,
  117. ulLineNumber,
  118. lchPosition);
  119. #else
  120. sprintf(szErrorDescription,TEXT("SOURCE: %ws\nLINE: %d\nCHARACTER POS: %d"),
  121. bstrSourceLine,
  122. ulLineNumber,
  123. lchPosition);
  124. #endif
  125. #ifdef DEBUG
  126. ::MessageBox(NULL, szErrorDescription, TEXT("WIA Driver Script Error"), MB_SETFOREGROUND);
  127. #endif
  128. return S_OK;
  129. }
  130. virtual HRESULT __stdcall OnEnterScript(void) {
  131. return S_OK;
  132. }
  133. virtual HRESULT __stdcall OnLeaveScript(void) {
  134. return S_OK;
  135. }
  136. };