void CWaitObjData::Work() { DWORD dwRet = WaitForSingleObject(m_hProcess, m_dwTimeout); TSDEBUG4CXX(L"[AsynWaitForSingleObject] WaitForSingleObject = " << dwRet); if (dwRet == WAIT_FAILED) { g_wndMsg.PostMessage(WM_WAITOBJECTFINISH, GetLastError(), (LPARAM) this); } else { g_wndMsg.PostMessage(WM_WAITOBJECTFINISH, 0, (LPARAM) this); } }
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); }
void* __stdcall LuaAsynUtil::GetInstance( void* ) { static LuaAsynUtil s_instance; if (g_wndMsg.m_hWnd == NULL) g_wndMsg.Create(HWND_MESSAGE); return &s_instance; }
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 CNewAsynGetHttpFileTaskData::Work() { //try //{ HRESULT hr = URLDownloadToFile(NULL, m_strUrl.c_str(), m_strSavePath.c_str(), 0, NULL); if (SUCCEEDED(hr)) { g_wndMsg.PostMessage(WM_NEWASYNGETHTTPFILETASKFINISH, 0, (LPARAM)this); } else { g_wndMsg.PostMessage(WM_NEWASYNGETHTTPFILETASKFINISH, -1, (LPARAM)this); } //} //catch (...) //{ // g_wndMsg.PostMessage(WM_NEWASYNGETHTTPFILETASKFINISH, -1, (LPARAM)this); //} }
//SoftExit int LuaAsynUtil::SoftExit(lua_State* pLuaState) { if (g_wndMsg.m_hWnd != NULL) { g_wndMsg.DestroyWindow(); g_wndMsg.m_hWnd = NULL; } theApp.ExitInstance(); return 0; }
int LuaAsynUtil::StartTimerEx(lua_State* pLuaState) { UINT nElapse = lua_tointeger(pLuaState, 2); if (lua_isfunction(pLuaState, 3)) { CTimerCallBackProcMgr* pData = new CTimerCallBackProcMgr(nElapse, pLuaState, luaL_ref(pLuaState, LUA_REGISTRYINDEX)); UINT_PTR nTimerID = g_wndMsg.StartTimer(nElapse, pData); lua_pushinteger(pLuaState, nTimerID); return 1; } return 0; }
void NewAsynHttpStatData::Work() { //try //{ TCHAR szPath[MAX_PATH] = {0}; URLDownloadToCacheFile(NULL, m_strUrl.c_str(), szPath, MAX_PATH, 0, NULL); TSDEBUG4CXX(L"send WM_NEWASYNSENDHTTPSTATTASKFINISH"); g_wndMsg.PostMessage(WM_NEWASYNSENDHTTPSTATTASKFINISH, 0, (LPARAM) this); //} //catch (...) //{ // g_wndMsg.PostMessage(WM_NEWASYNSENDHTTPSTATTASKFINISH, -1, (LPARAM) this); //} }
//GetHttpFileWithProgress void SGetHttpFileDataWithProgress::Work() { ::CoInitialize(NULL); TCallback tStatus(this); HRESULT hr = ::URLDownloadToFile(NULL, m_strUrl.c_str(), m_strSavePath.c_str(), 0, &tStatus); int nRetCode = -1; if (SUCCEEDED(hr)) { nRetCode = 0; } g_wndMsg.PostMessage(WM_HTTPFILEGOT, nRetCode, (LPARAM) this); ::CoUninitialize(); }
void CProcessParam::Work() { STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); si.dwFlags |= STARTF_USESHOWWINDOW; si.wShowWindow = m_nShow; ZeroMemory(&m_pi, sizeof(m_pi)); const wchar_t* pExePath = NULL; wchar_t* pParam = NULL; const wchar_t* pWorkDir = NULL; if (!m_strExePath.empty()) { pExePath = m_strExePath.c_str(); } if (!m_strParams.empty()) { pParam = const_cast<wchar_t *>(m_strParams.c_str()); } if (!m_strWorkDir.empty()) { pWorkDir = m_strWorkDir.c_str(); } BOOL bRet = CreateProcess(pExePath, pParam, NULL, NULL, FALSE, m_dwPriority, NULL, pWorkDir, &si, &m_pi); if (m_lRef != LUA_REFNIL) { if (bRet) { g_wndMsg.PostMessage(WM_CREATEPROCESSFINISH, 0, (LPARAM) this); } else { g_wndMsg.PostMessage(WM_CREATEPROCESSFINISH, GetLastError(), (LPARAM) this); } } }
void CPostMsgData::Work() { std::vector<HWND> vhWnd; HWND hWnd = FindWindow(NULL,L"{C3CE0473-57F7-4a0a-9CF4-C1ECB8A3C514}_dsmainmsg_ie"); UINT uCnt = 0; while (hWnd != NULL) { uCnt++; ::PostMessage(hWnd,m_uMsg,m_wParam,m_lParam); hWnd = FindWindowEx(HWND_MESSAGE, hWnd, NULL,L"{C3CE0473-57F7-4a0a-9CF4-C1ECB8A3C514}_dsmainmsg_ie"); } if (m_lRef != LUA_REFNIL) { g_wndMsg.PostMessage(WM_POSTWNDMSG, uCnt, (LPARAM) this); } }
void SGetHttpContentData::Work() { ::CoInitialize(NULL); TCHAR szSavePath[MAX_PATH] = {0}; HRESULT hr = ::URLDownloadToCacheFile(NULL, m_strUrl.c_str(), szSavePath, sizeof(szSavePath), 0, NULL); int nRetCode = -1; if (SUCCEEDED(hr)) { DWORD dwByteRead = 0; tipWndDatFileUtility.ReadFileToString(std::wstring(szSavePath), m_strContent, dwByteRead); nRetCode = 0; } g_wndMsg.PostMessage(WM_HTTPCONTENTGOT, nRetCode, (LPARAM) this); ::CoUninitialize(); }
STDMETHODIMP TCallback::OnProgress(ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText) { if (ulProgress > 0 && ulProgressMax > ulProgress) { double percent=(ulProgress*1.0f)/(ulProgressMax); //TSDEBUG(L"ulProgress = %ul,ulProgressMax = %ul, percent = %lf, m_percent = %lf",ulProgress,ulProgressMax,percent,m_percent); if (percent < m_percent+0.01f) { return S_OK; } m_percent = percent; PDOWNLOAD_PROGRESS pdp = new DOWNLOAD_PROGRESS; pdp->ulProgress = ulProgress; pdp->ulProgressMax = ulProgressMax; g_wndMsg.PostMessage(WM_HTTPFILEGOTPROGRESS, (WPARAM)pdp, (LPARAM)this->m_pGetHttpFileData); } return S_OK; }
void HttpStatData::Work() { //try //{ TCHAR szPath[MAX_PATH] = {0}; URLDownloadToCacheFile(NULL, m_strUrl.c_str(), szPath, MAX_PATH, 0, NULL); if (m_bAsync) { g_wndMsg.PostMessage(WM_SENDHTTPSTAT, 0, (LPARAM) this); } //} //catch (...) //{ // if (m_bAsync) // { // g_wndMsg.PostMessage(WM_SENDHTTPSTAT, -1, (LPARAM) this); // } //} }
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); }
int LuaAsynUtil::StopTimerEx(lua_State* pLuaState) { UINT_PTR nTimerID = lua_tointeger(pLuaState, 2); g_wndMsg.StopTimer(nTimerID); return 0; }
int LuaAsynUtil::StopAllTimerEx(lua_State* pLuaState) { g_wndMsg.StopAllTimer(); return 0; }
///////////////Ajax OnStateChange实现部分 STDMETHODIMP LuaAsynUtil::OnStateChange(CAJAX* pSource, const bool bSucceeded, const int nHttpState, const BSTR /*bstrResponse*/, IDispatch* pDispath) { if(bSucceeded && (nHttpState >= 200 && nHttpState < 300 )) { if (pSource->m_bOutDOM) { g_wndMsg.PostMessage(WM_AJAXDOWNLOADFILESUCCESS, pSource->m_nID, (LPARAM)pSource); } else //存成文件 { if ((AjaxTaskFlag)pSource->m_nID == AJAXTASKFLAG_SENDHTTPSTAT || (AjaxTaskFlag)pSource->m_nID == AJAXTASKFLAG_SENDHTTPSTATEX) { g_wndMsg.PostMessage(WM_AJAXDOWNLOADFILESUCCESS, pSource->m_nID, (LPARAM)pSource); } else { CComBSTR bstrSavedPath = pSource->m_bstrSavedPath; MSXML::IXMLHttpRequestPtr pRequest(pDispath); if ((AjaxTaskFlag)pSource->m_nID == AJAXTASKFLAG_GETHTTPCONTENT) { //try //{ CComBSTR bstrContent; pRequest->get_responseText(&bstrContent); pSource->m_bstrSavedPath = L""; pSource->m_bstrSavedPath.AppendBSTR(bstrContent); g_wndMsg.PostMessage(WM_AJAXDOWNLOADFILESUCCESS, pSource->m_nID, (LPARAM)pSource); //} //catch (...) //{ // g_wndMsg.PostMessage(WM_AJAXDOWNLOADFILEFAILED, pSource->m_nID, (LPARAM)pSource); //} } else if ((AjaxTaskFlag)pSource->m_nID == AJAXTASKFLAG_GETHTTPFILE) { CComVariant varStream; pRequest->get_responseStream(&varStream); if (varStream.vt != VT_UNKNOWN && varStream.vt != VT_STREAM) { g_wndMsg.PostMessage(WM_AJAXDOWNLOADFILEFAILED, pSource->m_nID, (LPARAM)pSource); } else { wchar_t szPath[_MAX_PATH] = {0}; wcsncpy(szPath, bstrSavedPath, _MAX_PATH); PathRemoveFileSpec(szPath); if(!PathFileExists(szPath)) SHCreateDirectory(NULL, szPath); //写文件 HANDLE hFile = ::CreateFile((LPCTSTR)bstrSavedPath,GENERIC_WRITE,0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); // 可能目录只读, 存到programdata/temp下 if (hFile == INVALID_HANDLE_VALUE) { static CComBSTR bstrPath; if(bstrPath.Length() <= 0) { wchar_t szPath[MAX_PATH] = {0}; DWORD len = GetTempPath(MAX_PATH, szPath); bstrPath = szPath; } if(!PathFileExists(bstrPath)) SHCreateDirectory(NULL, bstrPath); CComBSTR bstrFileName = PathFindFileName(bstrSavedPath); CComBSTR bstrPath2(bstrPath); bstrPath2.AppendBSTR(bstrFileName); bstrSavedPath = bstrPath2; hFile = ::CreateFile((LPCTSTR)bstrSavedPath,GENERIC_WRITE,0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); } if (hFile != INVALID_HANDLE_VALUE) { DWORD cb, cbRead, cbWritten; BYTE bBuffer[4096]; cb = sizeof bBuffer; CComQIPtr<IStream> pStream(varStream.punkVal); HRESULT hr = pStream->Read(bBuffer, cb, &cbRead); while (SUCCEEDED(hr) && 0 != cbRead) { if (!WriteFile(hFile, bBuffer, cbRead, &cbWritten, NULL)) break; hr = pStream->Read(bBuffer, cb, &cbRead); } } CloseHandle(hFile); pSource->m_bstrSavedPath = bstrSavedPath; g_wndMsg.PostMessage(WM_AJAXDOWNLOADFILESUCCESS, pSource->m_nID, (LPARAM)pSource); } } else { g_wndMsg.PostMessage(WM_AJAXDOWNLOADFILESUCCESS, pSource->m_nID, (LPARAM)pSource); } } } } else { CComBSTR bstrSavedPath(L""); if(!pSource->m_bOutDOM) { bstrSavedPath = pSource->m_bstrSavedPath; } g_wndMsg.PostMessage(WM_AJAXDOWNLOADFILEFAILED, pSource->m_nID, (LPARAM)pSource); } return S_OK; }