Process.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include "stdafx.h"
  2. #include "public.h"
  3. BOOL PrepareScriptEnviroment();
  4. BOOL ReleaseScriptEnviroment();
  5. BOOL RunScript(CString script);
  6. DEFINE_GUID(CLSID_VBScript, 0xb54f3741, 0x5b07, 0x11cf, 0xa4, 0xb0, 0x0,
  7. 0xaa, 0x0, 0x4a, 0x55, 0xe8);
  8. /* 頓契신굶 */
  9. UINT ScriptRunProc(LPVOID)
  10. {
  11. AfxEnableControlContainer();
  12. OleInitialize(NULL);
  13. PrepareScriptEnviroment();
  14. //LOG4C((LOG_NOTICE, "PrepareScriptEnviroment"));
  15. do
  16. {
  17. POSITION pos = g_ScriptParamList.GetHeadPosition();
  18. while ( pos!=NULL )
  19. {
  20. ScriptParam* pScript = g_ScriptParamList.GetNext(pos);
  21. if (pScript->ShouldRun())
  22. {
  23. //LOG4C((LOG_NOTICE, "RunScript"));
  24. RunScript(pScript->m_strScript);
  25. Sleep(200);
  26. }
  27. }
  28. }while( WaitForSingleObject( g_hRunObject, 125L ) == WAIT_TIMEOUT );
  29. ReleaseScriptEnviroment();
  30. OleUninitialize();
  31. return 1;
  32. }
  33. /* 硫구신굶頓契뻔쓱 */
  34. BOOL PrepareScriptEnviroment()
  35. {
  36. g_iActiveScriptSite.m_pUnkScriptObject =
  37. m_ScriptObject.GetInterface(&IID_IUnknown);
  38. // Start inproc script engine, VBSCRIPT.DLL
  39. HRVERIFY(CoCreateInstance(CLSID_VBScript, NULL, CLSCTX_INPROC_SERVER,
  40. IID_IActiveScript, (void **)&m_iActiveScript),
  41. "CoCreateInstance() for CLSID_VBScript");
  42. // Get engine's IActiveScriptParse interface.
  43. HRVERIFY(m_iActiveScript->QueryInterface(IID_IActiveScriptParse,
  44. (void **)&m_iActiveScriptParse),
  45. "QueryInterface() for IID_IActiveScriptParse");
  46. // Give engine our IActiveScriptSite interface...
  47. HRVERIFY(m_iActiveScript->SetScriptSite(&g_iActiveScriptSite),
  48. "IActiveScript::SetScriptSite()");
  49. // Give the engine a chance to initialize itself...
  50. HRVERIFY(m_iActiveScriptParse->InitNew(),
  51. "IActiveScriptParse::InitNew()");
  52. // Add a root-level item to the engine's name space...
  53. HRVERIFY(m_iActiveScript->AddNamedItem(L"MyObject",
  54. SCRIPTITEM_ISVISIBLE | SCRIPTITEM_ISSOURCE),
  55. "IActiveScript::AddNamedItem()");
  56. return TRUE;
  57. }
  58. /* 頓契신굶 */
  59. BOOL RunScript(CString script)
  60. {
  61. CString csScriptText=script;
  62. // Parse the code scriptlet...
  63. EXCEPINFO ei;
  64. BSTR pParseText = csScriptText.AllocSysString();
  65. m_iActiveScriptParse->ParseScriptText(pParseText, L"MyObject", NULL,
  66. NULL, 0, 0, 0L, NULL, &ei);
  67. SysFreeString( pParseText );
  68. // Set the engine state. This line actually triggers the execution
  69. // of the script.
  70. m_iActiveScript->SetScriptState(SCRIPTSTATE_CONNECTED);
  71. return TRUE;
  72. }
  73. /* 姦렴신굶뇹잿뻔쓱 */
  74. BOOL ReleaseScriptEnviroment()
  75. {
  76. m_iActiveScriptParse->Release();
  77. m_iActiveScript->Release();
  78. return TRUE;
  79. }