PythonHelper.h 926 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef __PYTHON_HELPER__
  2. #define __PYTHON_HELPER__
  3. #pragma once
  4. #define THREAD_SIZE 100
  5. // 工作参数,用于工作者线程;
  6. typedef struct __WORK_PARAMTER__
  7. {
  8. HANDLE hThread; // 事件句柄;
  9. HANDLE hEvent; // 线程事件;
  10. BOOL bStatus; // 线程状态;
  11. TCHAR szScriptPath[MAX_PATH]; // 脚本路径;
  12. TCHAR szLogPath[MAX_PATH]; // 日志路径;
  13. // 重定向标准输出和标准错误;
  14. HANDLE hStdOutRead;
  15. HANDLE hStdOutWrite;
  16. HANDLE hStdErroWrite;
  17. }WorkParamter, *pWorkParamter;
  18. class CPythonHelper
  19. {
  20. public:
  21. CPythonHelper(void);
  22. ~CPythonHelper(void);
  23. public:
  24. // 添加脚本;
  25. // strScript: 脚本路径;
  26. // strLogPath: 日志路径;
  27. // nRunType: 运行方式, 0=嵌入C++ 1=子进程运行;
  28. bool AddPythonScript(std::string strScript, std::string strLogPath, int nRunType = 0);
  29. // 停止脚本运行;
  30. void StopScript();
  31. protected:
  32. // 工作者线程函数;
  33. static DWORD WINAPI _WorkerThread(LPVOID lpParam);
  34. };
  35. #endif //__PYTHON_HELPER__