fix: Prevent crash when closing window during background data processing
This commit is contained in:
@@ -1644,9 +1644,11 @@ VOID CALLBACK CMy2015RemoteDlg::NotifyProc(CONTEXT_OBJECT* ContextObject)
|
||||
|
||||
AUTO_TICK(50);
|
||||
|
||||
if (ContextObject->v1) {
|
||||
if (ContextObject->hWnd) {
|
||||
DialogBase* Dlg = (DialogBase*)ContextObject->hDlg;
|
||||
Dlg->MarkReceiving(true);
|
||||
Dlg->OnReceiveComplete();
|
||||
Dlg->MarkReceiving(false);
|
||||
} else {
|
||||
HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
if (hEvent == NULL) {
|
||||
@@ -1663,25 +1665,25 @@ VOID CALLBACK CMy2015RemoteDlg::NotifyProc(CONTEXT_OBJECT* ContextObject)
|
||||
}
|
||||
}
|
||||
|
||||
// 对话框句柄及对话框类型
|
||||
// 对话框指针及对话框句柄
|
||||
struct dlgInfo
|
||||
{
|
||||
HANDLE hDlg;
|
||||
int v1;
|
||||
dlgInfo(HANDLE h, int type) : hDlg(h), v1(type) { }
|
||||
HANDLE hDlg; // 对话框指针
|
||||
HWND hWnd; // 窗口句柄
|
||||
dlgInfo(HANDLE h, HWND type) : hDlg(h), hWnd(type) { }
|
||||
};
|
||||
|
||||
VOID CALLBACK CMy2015RemoteDlg::OfflineProc(CONTEXT_OBJECT* ContextObject)
|
||||
{
|
||||
if (!g_2015RemoteDlg)
|
||||
return;
|
||||
dlgInfo* dlg = ContextObject->v1 > 0 ? new dlgInfo(ContextObject->hDlg, ContextObject->v1) : NULL;
|
||||
dlgInfo* dlg = ContextObject->hWnd ? new dlgInfo(ContextObject->hDlg, ContextObject->hWnd) : NULL;
|
||||
|
||||
SOCKET nSocket = ContextObject->sClientSocket;
|
||||
|
||||
g_2015RemoteDlg->PostMessage(WM_USEROFFLINEMSG, (WPARAM)dlg, (LPARAM)nSocket);
|
||||
|
||||
ContextObject->v1 = 0;
|
||||
ContextObject->hWnd = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -1968,9 +1970,8 @@ LRESULT CMy2015RemoteDlg::OnUserOfflineMsg(WPARAM wParam, LPARAM lParam)
|
||||
dlgInfo *p = (dlgInfo *)wParam;
|
||||
if (p)
|
||||
{
|
||||
if (p->v1) {
|
||||
CDialogBase* Dlg = (CDialogBase*)p->hDlg;
|
||||
::PostMessageA(Dlg->GetSafeHwnd(), WM_CLOSE, 0, 0);
|
||||
if (::IsWindow(p->hWnd)) {
|
||||
::PostMessageA(p->hWnd, WM_CLOSE, 0, 0);
|
||||
}
|
||||
delete p;
|
||||
p = NULL;
|
||||
|
||||
@@ -154,7 +154,7 @@ public:
|
||||
Dlg->Create(id, GetDesktopWindow());
|
||||
Dlg->ShowWindow(Show);
|
||||
|
||||
ContextObject->v1 = id;
|
||||
ContextObject->hWnd = Dlg->GetSafeHwnd();
|
||||
ContextObject->hDlg = Dlg;
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -115,6 +115,11 @@ void CAudioDlg::OnReceiveComplete(void)
|
||||
void CAudioDlg::OnClose()
|
||||
{
|
||||
CancelIO();
|
||||
// <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (IsProcessing()) {
|
||||
ShowWindow(SW_HIDE);
|
||||
return;
|
||||
}
|
||||
|
||||
m_bIsWorking = FALSE;
|
||||
WaitForSingleObject(m_hWorkThread, INFINITE);
|
||||
|
||||
@@ -111,6 +111,11 @@ void CChat::OnButtonEnd()
|
||||
void CChat::OnClose()
|
||||
{
|
||||
CancelIO();
|
||||
// <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (IsProcessing()) {
|
||||
ShowWindow(SW_HIDE);
|
||||
return;
|
||||
}
|
||||
|
||||
CDialogBase::OnClose();
|
||||
}
|
||||
|
||||
@@ -61,7 +61,11 @@ VOID DecryptDlg::OnReceiveComplete() {
|
||||
|
||||
void DecryptDlg::OnClose() {
|
||||
CancelIO();
|
||||
|
||||
// <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (IsProcessing()) {
|
||||
ShowWindow(SW_HIDE);
|
||||
return;
|
||||
}
|
||||
CDialogBase::OnClose();
|
||||
}
|
||||
|
||||
|
||||
@@ -883,10 +883,13 @@ void CFileManagerDlg::FixedRemoteDriveList()
|
||||
|
||||
void CFileManagerDlg::OnClose()
|
||||
{
|
||||
// TODO: Add your message handler code here and/or call default
|
||||
CoUninitialize();
|
||||
|
||||
CancelIO();
|
||||
// <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (IsProcessing()) {
|
||||
ShowWindow(SW_HIDE);
|
||||
return;
|
||||
}
|
||||
CoUninitialize();
|
||||
|
||||
DialogBase::OnClose();
|
||||
}
|
||||
|
||||
@@ -95,6 +95,11 @@ END_MESSAGE_MAP()
|
||||
void CHideScreenSpyDlg::OnClose()
|
||||
{
|
||||
CancelIO();
|
||||
// 等待数据处理完毕
|
||||
if (IsProcessing()) {
|
||||
ShowWindow(SW_HIDE);
|
||||
return;
|
||||
}
|
||||
|
||||
CDialogBase::OnClose();
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ typedef struct CONTEXT_OBJECT
|
||||
CBuffer InCompressedBuffer; // <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CBuffer InDeCompressedBuffer; // <20><>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CBuffer OutCompressedBuffer;
|
||||
int v1;
|
||||
HWND hWnd;
|
||||
HANDLE hDlg;
|
||||
void *olps; // OVERLAPPEDPLUS
|
||||
int CompressMethod; // ѹ<><D1B9><EFBFBD>㷨
|
||||
@@ -236,7 +236,7 @@ typedef struct CONTEXT_OBJECT
|
||||
VOID InitMember(SOCKET s)
|
||||
{
|
||||
memset(szBuffer, 0, sizeof(char) * PACKET_LENGTH);
|
||||
v1 = 0;
|
||||
hWnd = NULL;
|
||||
hDlg = NULL;
|
||||
sClientSocket = s;
|
||||
PeerName = ::GetPeerName(sClientSocket);
|
||||
@@ -497,9 +497,10 @@ public:
|
||||
IOCPServer* m_iocpServer;
|
||||
CString m_IPAddress;
|
||||
bool m_bIsClosed;
|
||||
bool m_bIsProcessing;
|
||||
HICON m_hIcon;
|
||||
CDialogBase(UINT nIDTemplate, CWnd* pParent, IOCPServer* pIOCPServer, CONTEXT_OBJECT* pContext, int nIcon) :
|
||||
m_bIsClosed(false),
|
||||
m_bIsClosed(false), m_bIsProcessing(false),
|
||||
m_ContextObject(pContext),
|
||||
m_iocpServer(pIOCPServer),
|
||||
CDialog(nIDTemplate, pParent) {
|
||||
@@ -516,8 +517,17 @@ public:
|
||||
|
||||
public:
|
||||
virtual void OnReceiveComplete(void) = 0;
|
||||
// <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void MarkReceiving(bool recv = true) {
|
||||
m_bIsProcessing = recv;
|
||||
}
|
||||
bool IsProcessing() const {
|
||||
return m_bIsProcessing;
|
||||
}
|
||||
void OnClose() {
|
||||
m_bIsClosed = TRUE;
|
||||
m_bIsClosed = true;
|
||||
while (m_bIsProcessing)
|
||||
Sleep(200);
|
||||
if(m_hIcon) DestroyIcon(m_hIcon);
|
||||
m_hIcon = NULL;
|
||||
CDialog::OnClose();
|
||||
@@ -529,6 +539,7 @@ public:
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
// ȡ<><C8A1> SOCKET <20><>ȡ<EFBFBD><C8A1><EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD>ε<EFBFBD><CEB5><EFBFBD>
|
||||
void CancelIO(){
|
||||
m_bIsClosed = TRUE;
|
||||
|
||||
|
||||
@@ -196,6 +196,11 @@ BOOL CKeyBoardDlg::PreTranslateMessage(MSG* pMsg)
|
||||
void CKeyBoardDlg::OnClose()
|
||||
{
|
||||
CancelIO();
|
||||
// <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (IsProcessing()) {
|
||||
ShowWindow(SW_HIDE);
|
||||
return;
|
||||
}
|
||||
|
||||
DialogBase::OnClose();
|
||||
}
|
||||
|
||||
@@ -103,6 +103,11 @@ BOOL CRegisterDlg::OnInitDialog()
|
||||
void CRegisterDlg::OnClose()
|
||||
{
|
||||
CancelIO();
|
||||
// <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (IsProcessing()) {
|
||||
ShowWindow(SW_HIDE);
|
||||
return;
|
||||
}
|
||||
|
||||
DialogBase::OnClose();
|
||||
}
|
||||
|
||||
@@ -179,6 +179,11 @@ BOOL CScreenSpyDlg::OnInitDialog()
|
||||
VOID CScreenSpyDlg::OnClose()
|
||||
{
|
||||
CancelIO();
|
||||
// 等待数据处理完毕
|
||||
if (IsProcessing()) {
|
||||
ShowWindow(SW_HIDE);
|
||||
return;
|
||||
}
|
||||
|
||||
DialogBase::OnClose();
|
||||
}
|
||||
|
||||
@@ -118,6 +118,12 @@ int CServicesDlg::ShowServicesList(void)
|
||||
void CServicesDlg::OnClose()
|
||||
{
|
||||
CancelIO();
|
||||
// <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (IsProcessing()) {
|
||||
ShowWindow(SW_HIDE);
|
||||
return;
|
||||
}
|
||||
|
||||
DeleteAllItems();
|
||||
|
||||
DialogBase::OnClose();
|
||||
|
||||
@@ -143,6 +143,11 @@ VOID CShellDlg::AddKeyBoardData(void)
|
||||
void CShellDlg::OnClose()
|
||||
{
|
||||
CancelIO();
|
||||
// <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (IsProcessing()) {
|
||||
ShowWindow(SW_HIDE);
|
||||
return;
|
||||
}
|
||||
|
||||
DialogBase::OnClose();
|
||||
}
|
||||
|
||||
@@ -161,6 +161,12 @@ void CSystemDlg::ShowProcessList(void)
|
||||
void CSystemDlg::OnClose()
|
||||
{
|
||||
CancelIO();
|
||||
// <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (IsProcessing()) {
|
||||
ShowWindow(SW_HIDE);
|
||||
return;
|
||||
}
|
||||
|
||||
DeleteAllItems();
|
||||
DialogBase::OnClose();
|
||||
}
|
||||
|
||||
@@ -93,6 +93,11 @@ BOOL CTalkDlg::PreTranslateMessage(MSG* pMsg)
|
||||
void CTalkDlg::OnClose()
|
||||
{
|
||||
CancelIO();
|
||||
// <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (IsProcessing()) {
|
||||
ShowWindow(SW_HIDE);
|
||||
return;
|
||||
}
|
||||
|
||||
DialogBase::OnClose();
|
||||
}
|
||||
|
||||
@@ -219,14 +219,18 @@ BOOL CVideoDlg::OnInitDialog()
|
||||
|
||||
void CVideoDlg::OnClose()
|
||||
{
|
||||
CancelIO();
|
||||
// <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (IsProcessing()) {
|
||||
ShowWindow(SW_HIDE);
|
||||
return;
|
||||
}
|
||||
if (!m_aviFile.IsEmpty())
|
||||
{
|
||||
SaveAvi();
|
||||
m_aviFile.Empty();
|
||||
}
|
||||
|
||||
CancelIO();
|
||||
|
||||
DialogBase::OnClose();
|
||||
}
|
||||
|
||||
|
||||
@@ -492,11 +492,12 @@ void CFileManagerDlg::fixNetHood(BYTE* pbuffer, int buffersize)
|
||||
|
||||
void CFileManagerDlg::OnClose()
|
||||
{
|
||||
if (m_bIsClosed) return;
|
||||
|
||||
CancelIO();
|
||||
|
||||
DestroyIcon(m_hIcon);
|
||||
// <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (IsProcessing()) {
|
||||
ShowWindow(SW_HIDE);
|
||||
return;
|
||||
}
|
||||
|
||||
DestroyCursor(m_hCursor);
|
||||
|
||||
|
||||
@@ -198,10 +198,6 @@ CString CMachineDlg::__MakePriority(DWORD dwPriClass)
|
||||
return strRet;
|
||||
}
|
||||
|
||||
void CMachineDlg::OnReceive()
|
||||
{
|
||||
}
|
||||
|
||||
void CMachineDlg::OnReceiveComplete()
|
||||
{
|
||||
if (m_bIsClosed) return;
|
||||
@@ -320,6 +316,11 @@ void CMachineDlg::OnRclickList(NMHDR* pNMHDR, LRESULT* pResult)
|
||||
void CMachineDlg::OnClose()
|
||||
{
|
||||
CancelIO();
|
||||
// <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (IsProcessing()) {
|
||||
ShowWindow(SW_HIDE);
|
||||
return;
|
||||
}
|
||||
DeleteList();
|
||||
if (m_wndStatusBar.GetSafeHwnd())
|
||||
m_wndStatusBar.DestroyWindow();
|
||||
|
||||
@@ -21,7 +21,6 @@ public:
|
||||
CTabCtrl m_tab;
|
||||
|
||||
void OnReceiveComplete();
|
||||
void OnReceive();
|
||||
static int CALLBACK CompareFunction(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user