123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- #ifndef _SCRIPT_H_
- #define _SCRIPT_H_
- #include <activscp.h>
- #include <initguid.h>
- #include <AFXPRIV.H>
- class MyActiveScriptSite : public IActiveScriptSite {
- private:
- ULONG m_dwRef; // Reference count
- public:
- IUnknown *m_pUnkScriptObject; // Pointer to your object that is exposed
- // to the script engine in GetItemInfo().
- MyActiveScriptSite::MyActiveScriptSite() {m_dwRef = 1;}
- MyActiveScriptSite::~MyActiveScriptSite() {}
-
- // IUnknown methods...
- virtual HRESULT _stdcall QueryInterface(REFIID riid, void **ppvObject) {
- *ppvObject = NULL;
- return E_NOTIMPL;
- }
- virtual ULONG _stdcall AddRef(void) {
- return ++m_dwRef;
- }
- virtual ULONG _stdcall Release(void) {
- if(--m_dwRef == 0) return 0;
- return m_dwRef;
- }
-
- // IActiveScriptSite methods...
- virtual HRESULT _stdcall GetLCID(LCID *plcid) {
- return S_OK;
- }
-
- virtual HRESULT _stdcall GetItemInfo(LPCOLESTR pstrName,
- DWORD dwReturnMask, IUnknown **ppunkItem, ITypeInfo **ppti) {
- // Is it expecting an ITypeInfo?
- if(ppti) {
- // Default to NULL.
- *ppti = NULL;
-
- // Return if asking about ITypeInfo...
- if(dwReturnMask & SCRIPTINFO_ITYPEINFO)
- return TYPE_E_ELEMENTNOTFOUND;
- }
-
- // Is the engine passing an IUnknown buffer?
- if(ppunkItem) {
- // Default to NULL.
- *ppunkItem = NULL;
-
- // Is Script Engine looking for an IUnknown for our object?
- if(dwReturnMask & SCRIPTINFO_IUNKNOWN) {
- // Check for our object name...
- if (!_wcsicmp(L"MyObject", pstrName)) {
- // Provide our object.
- *ppunkItem = m_pUnkScriptObject;
- // Addref our object...
- m_pUnkScriptObject->AddRef();
- }
- }
- }
-
- return S_OK;
- }
-
- virtual HRESULT __stdcall GetDocVersionString(BSTR *pbstrVersion) {
- return S_OK;
- }
-
- virtual HRESULT __stdcall OnScriptTerminate(const VARIANT *pvarResult,
- const EXCEPINFO *pexcepInfo) {
- return S_OK;
- }
-
- virtual HRESULT __stdcall OnStateChange(SCRIPTSTATE ssScriptState) {
- return S_OK;
- }
-
- virtual HRESULT __stdcall OnScriptError(
- IActiveScriptError *pscriptError) {
- static BSTR pwcErrorText;
- pscriptError->GetSourceLineText(&pwcErrorText);
- AfxMessageBox(
- CString("脚本存在语法错误,请仔细检查"),
- MB_SETFOREGROUND);
- ::SysFreeString(pwcErrorText);
- return S_OK;
- }
-
- virtual HRESULT __stdcall OnEnterScript(void) {
- return S_OK;
- }
-
- virtual HRESULT __stdcall OnLeaveScript(void) {
- return S_OK;
- }
- };
- #endif
|