|
@@ -57,3 +57,91 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
|
|
|
|
|
|
return nRetCode;
|
|
|
}
|
|
|
+
|
|
|
+// 全局变量;
|
|
|
+std::vector<CScriptExecutor*> g_vtScriptExcutor;
|
|
|
+
|
|
|
+RUNPYTHON_API DWORD RunPyScript(LPCTSTR lpScriptFile, LPCTSTR lpExtraSentence, LPCTSTR lpScriptLog, BOOL bSubProcess)
|
|
|
+{
|
|
|
+ CScriptExecutor *pExcutor = new CScriptExecutor();
|
|
|
+ if ( pExcutor )
|
|
|
+ {
|
|
|
+ // 初始化脚本;
|
|
|
+ pExcutor->InitScript(lpScriptFile, lpScriptLog, lpExtraSentence, bSubProcess ? SUBPROCESS : EMBEDDED);
|
|
|
+ // 执行脚本;
|
|
|
+ if ( !pExcutor->StartScript() )
|
|
|
+ {
|
|
|
+ delete pExcutor;
|
|
|
+ pExcutor = NULL;
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 压入全局变量;
|
|
|
+ g_vtScriptExcutor.push_back(pExcutor);
|
|
|
+
|
|
|
+ // 返回脚本Id;
|
|
|
+ return pExcutor->GetScriptId();
|
|
|
+ }
|
|
|
+
|
|
|
+ return -1;
|
|
|
+}
|
|
|
+
|
|
|
+RUNPYTHON_API bool StopPyScript(DWORD dwScriptId, BOOL bSubProcess)
|
|
|
+{
|
|
|
+ bool ret = false;
|
|
|
+ CScriptExecutor *pExcutor = NULL;
|
|
|
+ std::vector<CScriptExecutor*>::iterator it = g_vtScriptExcutor.begin();
|
|
|
+ for ( ; it != g_vtScriptExcutor.end(); it++ )
|
|
|
+ {
|
|
|
+ pExcutor = *it;
|
|
|
+ if ( pExcutor->GetScriptId() == dwScriptId )
|
|
|
+ {
|
|
|
+ ret = true;
|
|
|
+ pExcutor->StopScript();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+RUNPYTHON_API bool IsPyScriptOver(DWORD dwScriptId, BOOL bSubProcess)
|
|
|
+{
|
|
|
+ bool ret = false;
|
|
|
+ CScriptExecutor *pExcutor = NULL;
|
|
|
+ std::vector<CScriptExecutor*>::iterator it = g_vtScriptExcutor.begin();
|
|
|
+ for ( ; it != g_vtScriptExcutor.end(); it++ )
|
|
|
+ {
|
|
|
+ pExcutor = *it;
|
|
|
+ if ( pExcutor->GetScriptId() == dwScriptId )
|
|
|
+ {
|
|
|
+ if ( ret = pExcutor->IsScriptOver() )
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+RUNPYTHON_API void CleanPyScript(DWORD dwScriptId)
|
|
|
+{
|
|
|
+ CScriptExecutor *pExcutor = NULL;
|
|
|
+ std::vector<CScriptExecutor*>::iterator it = g_vtScriptExcutor.begin();
|
|
|
+ for ( ; it != g_vtScriptExcutor.end(); it++ )
|
|
|
+ {
|
|
|
+ pExcutor = *it;
|
|
|
+ if ( pExcutor->GetScriptId() == dwScriptId )
|
|
|
+ {
|
|
|
+ // 先停止脚本;
|
|
|
+ pExcutor->StopScript();
|
|
|
+
|
|
|
+ // 再清除;
|
|
|
+ delete pExcutor;
|
|
|
+ pExcutor = NULL;
|
|
|
+ g_vtScriptExcutor.erase(it);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|