int LuaAsynUtil::AsynExecuteSqlite3DML( lua_State* pLuaState ) { TSTRACEAUTO(); LuaAsynUtil** ppAsynUtil = (LuaAsynUtil **)luaL_checkudata(pLuaState, 1, XMPTIPWND_ASYNCUTIL_CLASS); if (ppAsynUtil && *ppAsynUtil) { const char* pdbPath = lua_tostring(pLuaState, 2); const char* pSql = lua_tostring(pLuaState, 3); if (pdbPath != NULL && pSql != NULL && lua_isfunction(pLuaState, 6)) { int iOpenFlag = SQLITE_OPEN_READONLY; BOOL bQuery = TRUE; if (lua_isnumber(pLuaState, 4)) { iOpenFlag = (int)lua_tointeger(pLuaState, 4); } if(lua_isboolean(pLuaState, 5)) { bQuery = lua_toboolean(pLuaState,5); } ExecuteDMLData* pSqlite3 = new ExecuteDMLData(pLuaState,pdbPath,pSql,iOpenFlag,bQuery); if (pSqlite3) { _beginthreadex(NULL,0,Sqlite3Proc,pSqlite3,0,NULL); } } } return 0; }
void KillProcessData::Work() { TSTRACEAUTO(); int nErrCode = 0; HANDLE hProcess = ::OpenProcess(PROCESS_TERMINATE|SYNCHRONIZE, FALSE, m_dwPID); if (hProcess) { if (::TerminateProcess(hProcess, 4)) { DWORD dwWaitResult = ::WaitForSingleObject(hProcess, m_dwWaitTimeMS); if (WAIT_OBJECT_0 != dwWaitResult) { nErrCode = 3; TSERROR(_T("WaitForSingleObject kill process failed, dwWaitResult=%d, m_dwPID=%d, hProcess=0x%X, m_dwWaitTimeMS=%d, GetLastError() return 0x%X"), dwWaitResult, m_dwPID, hProcess, m_dwWaitTimeMS, GetLastError()); } } else { nErrCode = 2; TSERROR(_T("TerminateProcess failed, hProcess=0x%X, GetLastError() return 0x%X"), hProcess, GetLastError()); } ::CloseHandle(hProcess); } else { nErrCode = 1; TSERROR(_T("OpenProcess with PROCESS_TERMINATE flag failed, m_dwPID=%d, GetLastError() return 0x%X"), m_dwPID, GetLastError()); } g_wndMsg.PostMessage(WM_KILLPROCESS, nErrCode, (LPARAM)this); }
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow) { TSTRACEAUTO(); //std::wstring strProdName, strProdId, strProdVer; HRESULT hRes = ::CoInitialize(NULL); // If you are running on NT 4.0 or higher you can use the following call instead to // make the EXE free threaded. This means that calls come in on a random RPC thread. // HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); ATLASSERT(SUCCEEDED(hRes)); // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used ::DefWindowProc(NULL, 0, 0, 0L); AtlInitCommonControls(ICC_BAR_CLASSES); // add flags to support other controls hRes = _Module.Init(NULL, hInstance); ATLASSERT(SUCCEEDED(hRes)); int nRet = Run(lpstrCmdLine, nCmdShow); _Module.Term(); ::CoUninitialize(); return nRet; }
extern "C" __declspec(dllexport) void LoadLuaRunTime(char* szInstallDir) { TSTRACEAUTO(); HRESULT hr = ::CoInitialize(NULL); hr = _Module.Init(NULL, gInstance); CMessageLoop theLoop; _Module.AddMessageLoop(&theLoop); CLRTAgent lrtAgent; //lrtAgent.InitLua(szInstallDir); //g_hXappLuaToolDll = lrtAgent.GetXappLuaToolDllModuleHandle(); if (lrtAgent.InitLua(szInstallDir)) { TSDEBUG4CXX(_T(">>>>>theLoop.Run()")); theLoop.Run(); TSDEBUG4CXX(_T("<<<<<theLoop.Run()")); } _Module.RemoveMessageLoop(); _Module.Term(); ::CoUninitialize(); TerminateProcess(::GetCurrentProcess(), S_OK); return; }
void GetFileSizeWithUrlData::Work() { TSTRACEAUTO(); INT64 iFileSize = 0; BOOL bRet = gMiniTPWrapper.GetFileSizeWithUrl(m_strUrl.c_str(),m_iFileSize); WPARAM wParam = bRet?0:1; g_wndMsg.PostMessage(WM_GETFILESIZEWITHURL, wParam, (LPARAM)this); }
void ExecuteDMLData::Notify(int iErrCode) { TSTRACEAUTO(); lua_State* pLuaState = m_callInfo.GetLuaState(); lua_rawgeti(pLuaState, LUA_REGISTRYINDEX, m_callInfo.GetRefFn()); int iRetCount = 0; lua_pushinteger(pLuaState, iErrCode); ++iRetCount; if (SQLITE_OK == iErrCode) { lua_newtable(pLuaState); int i = 1; std::vector<std::map<std::string,std::string>>::const_iterator c_iter = m_vQuery.begin(); TSDEBUG(_T("count is %d."),m_vQuery.size()); for (;c_iter != m_vQuery.end();++c_iter) { std::map<std::string,std::string> map_Row = *c_iter; std::map<std::string,std::string>::const_iterator c_mapRow = map_Row.begin(); lua_newtable(pLuaState); for (;c_mapRow != map_Row.end();++c_mapRow) { std::string utf8key = c_mapRow->first; std::string utf8Value = c_mapRow->second; lua_pushstring(pLuaState, utf8key.c_str()); if (!utf8Value.empty()) lua_pushstring(pLuaState, utf8Value.c_str()); else lua_pushnil(pLuaState); lua_settable(pLuaState, -3); } lua_rawseti(m_callInfo.GetLuaState(), -2, i); i++; } TSDEBUG(_T("table pusher ok"),m_vQuery.size()); ++iRetCount; free(); } else { lua_pushnil(pLuaState); ++iRetCount; } XLLRT_LuaCall(pLuaState, iRetCount, 0, L"ExecuteDMLData Callback"); }
int LuaAsynUtil::AsynPostWndMsg(lua_State* pLuaState) { TSTRACEAUTO(); const char* pClassName = lua_tostring(pLuaState, 2); const char* pTitle = lua_tostring(pLuaState, 3); UINT uMsg = (UINT)lua_tonumber(pLuaState, 4); WPARAM wParam = (WPARAM)lua_tonumber(pLuaState, 5); LPARAM lParam = (LPARAM)lua_tonumber(pLuaState, 6); if (lua_isfunction(pLuaState, 7)) { CPostMsgData* pData = new CPostMsgData(pClassName, pTitle, uMsg,wParam,lParam,pLuaState, luaL_ref(pLuaState, LUA_REGISTRYINDEX)); _beginthreadex(NULL, 0, PostMsgProc, pData, 0, NULL); } return 0; }
int __stdcall LuaErrorHandle(lua_State* luaState,const wchar_t* pExtInfo, const wchar_t* luaErrorString,PXL_LRT_ERROR_STACK pStackInfo) { TSTRACEAUTO(); static bool s_bEnter = false; if (!s_bEnter) { s_bEnter = true; if(pExtInfo != NULL) { TSDEBUG4CXX(L"LuaErrorHandle: " << luaErrorString << L" @ " << pExtInfo); } else { TSDEBUG4CXX(L"LuaErrorHandle: " << luaErrorString); } s_bEnter = false; } return 0; }
void ExecuteDMLData::Work() { TSTRACEAUTO(); int nErrCode = -1; if (Init()) { nErrCode = m_pfn_sqlite3_open_v2(m_strDBPath.c_str(),&m_db,m_OpenFlag,NULL); if (SQLITE_OK == nErrCode) { nErrCode = execDML(m_strSQL.c_str(),m_bQuery); db_close(); } else { TSDEBUG(_T("open database failed,error code is %lu"),nErrCode); }; } g_wndMsg.PostMessage(WM_SQLITE3, nErrCode, (LPARAM)this); }
BOOL CRegisterLuaAPI::Init(LPCTSTR lpCmdLine, LPVOID lpHookObj) { TSTRACEAUTO(); XL_LRT_ENV_HANDLE hEnv = XLLRT_GetEnv(NULL); if (NULL == hEnv) { TSDEBUG4CXX(L"XLLRT_GetEnv error! hEnv == NULL"); return FALSE; } LuaAPIUtil::RegisterObj(hEnv); LuaAsynUtil::RegisterSelf(hEnv); LuaGraphicUtil::RegisterObj(hEnv); LuaNotifyIcon::RegisterSelf(hEnv); LuaListenPreFactory::RegisterObj(hEnv); LuaListenPre::RegisterClass(hEnv); XLLRT_ReleaseEnv(hEnv); return TRUE; }
int LuaAsynUtil::AsynWaitForSingleObject(lua_State* pLuaState) { TSTRACEAUTO(); HANDLE hProcess = (HANDLE)lua_touserdata(pLuaState, 2); DWORD dwTimeout; if (lua_isnil(pLuaState, 3)) { dwTimeout = INFINITE; } else { dwTimeout = (DWORD)lua_tonumber(pLuaState, 3); } TSDEBUG4CXX(L"[AsynWaitForSingleObject] dwTimeout = " << dwTimeout << L", hProcess = " << hProcess); if (lua_isfunction(pLuaState, 4)) { CWaitObjData* pData = new CWaitObjData(hProcess, dwTimeout, pLuaState, luaL_ref(pLuaState, LUA_REGISTRYINDEX)); _beginthreadex(NULL, 0, WaitObjProc, pData, 0, NULL); } return 0; }