Home > Back-end >  Used in the thread of the ActiveX socket, switch input method crashing
Used in the thread of the ActiveX socket, switch input method crashing

Time:10-11

Basic program structure: first established the socket in the ActiveX (block), a new thread after the connection is successful, the thread with recv (blocking mode) to receive data from the other (do - while mode, circulation has been waiting for death, after the test, the thread of the pure cycle will not result in the death of input switch card dead, once a socket is involved in will stuck), socket and thread processing are standard winapi way, not MFC,
Problem: waiting for recv when receiving data, IE the page in a input box casually focal switch input method, will be stuck (sogou, Microsoft, such as QQ input method will be jammed), online information is new thread + socket mode switch, there is no message loop to deal with input caused sendmessage jammed, so need to destroy the IME window, but the solution also have never thought, comment,

CodePudding user response:

Infinite loop with a little delay,
Message processing or application

CodePudding user response:

Infinite loop plus time delay is Sleep? This tried or jammed, as for message processing to add in where? The thread function in the body? Still?
Thank you,

CodePudding user response:

Not have a solution? Kill the ime window is good
Void __fastcall TDBThread: : FreeIMEWindow ()
{
//if GetCurrentThreadId=the main thread IDthen exit;//if it is the main thread, it should have a message loop, can not handle
HWND h=FindWindow (" the IME ", "Default IME");
DWORD pid;
HWND dh.

While (IsWindow (h))
{
If (GetWindowThreadProcessId (h, & amp; Pid)==GetCurrentThreadId ())
{
Dh=h;
}
The else
Dh=NULL;
H=FindWindowEx (0, h, "the IME", "Default IME");
If (dh)
The DestroyWindow (dh);
}
}

CodePudding user response:

Have, in accordance with the above scheme tried but seems not, debugging, and add a messagebox line of code
If (GetWindowThreadProcessId (h, & amp; Pid)==GetCurrentThreadId ())
{
MessageBox (0, cstrings (" found!" ), cstrings (" 0 "), 0);
Dh=h;
}
But doesn't show this messagebox, also is to show that no and thread corresponding to the IME window, this is very strange ~

In addition, make sure my process, because I am a novice, so also please the great god to see if the process has a problem:
1, creating the socket links in the main thread, thread (m_ThreadHandle=CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) RecvData, this, 0, & amp; M_ThreadID);
2, RecvData function call the above method in the destruction of the thread their own IME Windows
Void RecvData (XXXX)
{
FreeIMEWindows ();//the above treatment methods

//infinite loop to wait for the other party to send data, using recv blocking mode
}

Hope the great god directions, the problem didn't solve for a long time, depressed ~

CodePudding user response:

Where did you add to sleep?

CodePudding user response:

reference 5 floor lhylhy reply:
add sleep where have you been?


I'm not too sure, sleep play a role of so is added to the recv process, the structure is

Void RecvData (XXXX)
{
FreeIMEWindows ();//the above treatment methods

//other preparatory work, variables and memory allocation etc.

Do
{
Ret=recv (... );
//processing data

sleep(1000);
} while (ret & gt; 0);

But apparently still won't do

CodePudding user response:

I suggest, use of sleep time should use the sleep (1)
In addition you what is the thread priority? Can will stuck because thread priority is high (such as real time)?

CodePudding user response:

refer to 7th floor lhylhy response:
I suggest, use of sleep time should use the sleep (1)
In addition you what is the thread priority? Can will stuck because thread priority is high (such as real time)?

Thank you for your help, many times I wrote sleep (1), and sets the thread priority to minimum
SetThreadPriority (m_ThreadHandle THREAD_PRIORITY_LOWEST);
Still won't do ~ ~
Now there are a few points I'm not quite understand
1, the new thread according to online data interpretation would have an IME window set up, but not to be found in FreeIMEWindows traversal
If (GetWindowThreadProcessId (h, & amp; Pid)==GetCurrentThreadId ())
{
MessageBox (0, cstrings (" found!" ), cstrings (" 0 "), 0);//never popup tooltip
Dh=h;
}
So why I create threads have not corresponding to the ime window
2, increase sleep in infinite loop recv blocking mode (1) is used? Because most of the time are both stuck in recv it, sleep feel this sentence is rarely, if ever,

Show just a little hope, thank you,

CodePudding user response:

refer to the eighth floor kylinqilin2011 response:
Quote: refer to 7th floor lhylhy response:

I suggest, use of sleep time should use the sleep (1)
In addition you what is the thread priority? Can will stuck because thread priority is high (such as real time)?

Thank you for your help, many times I wrote sleep (1), and sets the thread priority to minimum
SetThreadPriority (m_ThreadHandle THREAD_PRIORITY_LOWEST);
Still won't do ~ ~
Now there are a few points I'm not quite understand
1, the new thread according to online data interpretation would have an IME window set up, but not to be found in FreeIMEWindows traversal
If (GetWindowThreadProcessId (h, & amp; Pid)==GetCurrentThreadId ())
{
MessageBox (0, cstrings (" found!" ), cstrings (" 0 "), 0);//never popup tooltip
Dh=h;
}
So why I create threads have not corresponding to the ime window
2, increase sleep in infinite loop recv blocking mode (1) is used? Because most of the time are both stuck in recv it, sleep feel this sentence is rarely, if ever,

Show just a little hope, thank you,

Thread is not automatically have the ime window, the process may be,

CodePudding user response:

If the thread didn't go to online calls to kill the thread of the IME window scheme is no??????? So what to do?

CodePudding user response:

Did some debugging again today, in the main thread and the child thread calls FreeIMEWindows (threadId), the function source code later given, debugging steps as follows:
1, the main thread invokes the way as follows:
M_ThreadHandle=CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) RecvData, this, 0, & amp; M_ThreadID);
.
FreeIMEWindows (m_ThreadID);//parameter is the last child CreateThread above thread ID of the

2, the child thread invokes the way as follows:
RecvData (... )
{
.
FreeIMEWindows (p - & gt; M_ThreadID);//parameter is passed by the main thread of the child thread ID, have validation represents the ID of the correct
.
}

Result: 1 the way to find the window handle of the associated with the child thread, but cannot be destroyed, because authority "; 2 the way completely can't find the child thread related window handle,

FreeIMEWindows (threadId) is defined as:
Int FreeIMEWindows (DWORD threadId)
{
Int ret=1;
Int count=0;//testing to find how many total IME window

Char I [255];
Itoa (threadId, I 10);
Cstrings MessageBox (cstrings (I), (" threadId "), 0).//verification passed the thread ID of the value of the
Itoa (GetCurrentThreadId (), I, 10);
Cstrings MessageBox (cstrings (I), (" GetCurrentThreadId "), 0).//value of the current thread ID authentication

//the above verify whether the main thread calls or child thread calls, ID is accurate, the function called when the thread type, 2 times to print out the results of the uniform

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related