Click to See Complete Forum and Search --> : MFC Bug or My Bug


is99zsq
January 4th, 2005, 08:25 PM
I've written a very simple MFC Dialog Program
A dialog contain a OK Button and a edit control
then i write the following code

UINT TestThread(LPVOID lpParam)
{
CSocket s;
s.Create(0,SOCK_DGRAM);
while (1) {
//...
Sleep(1000);
}
}

void CTestDialog::OnOK()
{
AfxSocketInit(NULL);
AfxBeginThread(TestThread,0);
}

when the thread start, all things seems well, but when i want to shift another input method in the edit box, the mainthread is hang~

What's the problem in my code .
Any advice will be appreciate

amarcode
January 4th, 2005, 09:05 PM
Call the AfxInitSocket() function only once in your CWinApp::InitInstance.

amarcode
January 4th, 2005, 09:13 PM
Also specify the lpszSockAddress (third parameter in Create function) as a pointer to a string containing the network address of the connected socket.

is99zsq
January 4th, 2005, 10:28 PM
thanks amarcode, but i've try your way before, and the error still~

when i Replace all the CSocket Function with SOCKET function , the whole scenario work very well.

but it really a problem that confused me for 2 days . :(

i think the core thing is:
when i use a MFC Class with MessageQueue in a Thread, Something happen but i do not know.

any new advice?

Andreas Masur
January 5th, 2005, 04:05 AM
[ Moved thread ]