123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #include "stdafx.h"
- #include "public.h"
- BOOL PrepareScriptEnviroment();
- BOOL ReleaseScriptEnviroment();
- BOOL RunScript(CString script);
- DEFINE_GUID(CLSID_VBScript, 0xb54f3741, 0x5b07, 0x11cf, 0xa4, 0xb0, 0x0,
- 0xaa, 0x0, 0x4a, 0x55, 0xe8);
- /* 頓契신굶 */
- UINT ScriptRunProc(LPVOID)
- {
- AfxEnableControlContainer();
- OleInitialize(NULL);
- PrepareScriptEnviroment();
- //LOG4C((LOG_NOTICE, "PrepareScriptEnviroment"));
- do
- {
- POSITION pos = g_ScriptParamList.GetHeadPosition();
- while ( pos!=NULL )
- {
- ScriptParam* pScript = g_ScriptParamList.GetNext(pos);
- if (pScript->ShouldRun())
- {
- //LOG4C((LOG_NOTICE, "RunScript"));
- RunScript(pScript->m_strScript);
- Sleep(200);
- }
- }
- }while( WaitForSingleObject( g_hRunObject, 125L ) == WAIT_TIMEOUT );
- ReleaseScriptEnviroment();
- OleUninitialize();
- return 1;
- }
- /* 硫구신굶頓契뻔쓱 */
- BOOL PrepareScriptEnviroment()
- {
- g_iActiveScriptSite.m_pUnkScriptObject =
- m_ScriptObject.GetInterface(&IID_IUnknown);
-
- // Start inproc script engine, VBSCRIPT.DLL
- HRVERIFY(CoCreateInstance(CLSID_VBScript, NULL, CLSCTX_INPROC_SERVER,
- IID_IActiveScript, (void **)&m_iActiveScript),
- "CoCreateInstance() for CLSID_VBScript");
-
- // Get engine's IActiveScriptParse interface.
- HRVERIFY(m_iActiveScript->QueryInterface(IID_IActiveScriptParse,
- (void **)&m_iActiveScriptParse),
- "QueryInterface() for IID_IActiveScriptParse");
-
- // Give engine our IActiveScriptSite interface...
- HRVERIFY(m_iActiveScript->SetScriptSite(&g_iActiveScriptSite),
- "IActiveScript::SetScriptSite()");
-
- // Give the engine a chance to initialize itself...
- HRVERIFY(m_iActiveScriptParse->InitNew(),
- "IActiveScriptParse::InitNew()");
- // Add a root-level item to the engine's name space...
- HRVERIFY(m_iActiveScript->AddNamedItem(L"MyObject",
- SCRIPTITEM_ISVISIBLE | SCRIPTITEM_ISSOURCE),
- "IActiveScript::AddNamedItem()");
- return TRUE;
- }
- /* 頓契신굶 */
- BOOL RunScript(CString script)
- {
- CString csScriptText=script;
-
- // Parse the code scriptlet...
- EXCEPINFO ei;
- BSTR pParseText = csScriptText.AllocSysString();
-
- m_iActiveScriptParse->ParseScriptText(pParseText, L"MyObject", NULL,
- NULL, 0, 0, 0L, NULL, &ei);
-
- SysFreeString( pParseText );
- // Set the engine state. This line actually triggers the execution
- // of the script.
- m_iActiveScript->SetScriptState(SCRIPTSTATE_CONNECTED);
- return TRUE;
- }
- /* 姦렴신굶뇹잿뻔쓱 */
- BOOL ReleaseScriptEnviroment()
- {
- m_iActiveScriptParse->Release();
- m_iActiveScript->Release();
- return TRUE;
- }
|