Hey all,
I have prepared a GUI for chatting application using winsock2 concept. Connection with server is created using GUI. However, I am facing a little issue. Once the server send some thing, it is received in buffer at client. I am putting the data from buffer to output window (which is a EDIT BOX on GUI) of client using SetDlgItemText(). However, as the compiler reach SetDlgItemText() an error is flashed:
DEBUG ASSERTION FAILED!
FILE: winocc.cpp
Line 138
|
By debugging I came to know that error appears when SetDlgItemText() is called. I went to winocc.cpp at line 138 as well. There also the same function was pointed out.
Part of file winocc.cpp around line 138 is also shown below:
1 2 3 4 5 6 7 8 9 10
|
void CWnd::SetDlgItemText(int nID, LPCTSTR lpszString)
{
ASSERT(::IsWindow(m_hWnd));
if (m_pCtrlCont == NULL)
::SetDlgItemText(m_hWnd, nID, lpszString);
else
m_pCtrlCont->SetDlgItemText(nID, lpszString);
}
|
PART OF MY CODE IS GIVEN BELOW:
I have created GUI using MFC application wizard.
below is the code for OK button on GUI:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
void CGUI_chatDlg::OnOK()
{
// TODO: Add extra validation here
unsigned int connect, disconnect;
connect=IsDlgButtonChecked(IDC_RADIO1); //to connect to server
disconnect=IsDlgButtonChecked(IDC_RADIO2);
if(connect==1)
{
client_program(); //Function where whole code to connect to server using winsock2 concepts.
}
// CDialog::OnOK();
}
|
Now code for client_program() is written below the above code:
Not listing the full code.
1 2 3 4 5 6 7 8 9 10
|
void client_program()
{
// all the code here
//connection to server
sd=connect(cd,(sockaddr*)&client,client_length);
_beginthread(Readthread,0,(void*)cd); //Thread to read data from server.
}
|
Then read thread is defined below it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
void Readthread(void *parameter)
{
CGUI_chatDlg c;
char buff[512];
unsigned int cd=(unsigned int)parameter;
while(1)
{
if(recv(cd,buff,sizeof(buff),0)!=SOCKET_ERROR) /*recv returns a positive value*/
{
//cout<<endl<<"From Server:"<<buff<<flush;
c.SetDlgItemText(IDC_EDIT2,buff); // PROBLEM IS INVOKED HERE.
memset(buff,0,512);
//cout<<"\n\n"<<flush;
}
}
}
|
PROBLEM IS INVOKED at the place pointed in comment in Readthread.
Please help me guys. I am out of my mind with this error.
Regards,
Abhishek