Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with UpdateData

Status
Not open for further replies.

HyperEngineer

Programmer
May 8, 2002
190
US

I have the following code in a class:

Code:
bool CTelnetDlg::ErrorMessage(CString cError)
{
	m_cErrorStatus = cError;
	UpdateData(false);
	return 0;
}

When I call this code from within the class it works fine. But if I call it from another class the UpdateData(false); gives me an error.

Code from within the class that is in the OnInitDialog() function:
Code:
	CString cErrMsg;
	if (WSAStartup(MAKEWORD(2,2), &wd))
	{
		cErrMsg = "WSAStartup failed";
		ErrorMessage(cErrMsg);
	}
	else
	{
		cErrMsg = "WSAStartup successful";
		ErrorMessage(cErrMsg);
	}
Code from another class:
Code:
CSocketDx::CSocketDx(char *strIP,int nPort)
{
  unsigned long ip;
  CTelnetDlg ErrorMessage;
  CString cErrMsg;

  if((*strIP <= '9') && (*strIP >= '0'))
  {
    if((ip = inet_addr(strIP)) == INADDR_NONE)
    {
      cErrMsg = "DX invalid host IP given";
      ErrorMessage.ErrorMessage(cErrMsg);
    }
    else
    {
      cErrMsg = "DX valid host IP given";
      ErrorMessage.ErrorMessage(cErrMsg);
    }
  }
  else
  {
    hostent* ent = gethostbyname(strIP);
    if(!ent)
    {
       ErrorMessage.ErrorMessage("DX Host IP error");
    }
    else
    {
       ErrorMessage.ErrorMessage("DX Host IP valid");
    }
    ip = *(unsigned long*)(ent->h_addr);
  }
  
  m_sockaddr_in.sin_family = AF_INET;
  m_sockaddr_in.sin_port = htons(nPort);
  m_sockaddr_in.sin_addr = *(in_addr*)&ip;
}

The error code is:

Code:
   Debug assertion failed!
   Program: \telnet\debug\telnet.exe
   File: wincore.cpp
   Line: 3095

   ...

When I debug it I can see the CString coming in. It looks OK no matter where it is called from. But the UpdateData() function is not happy. Why?


HyperEngineer
If it ain't broke, it probably needs improvement.
 
I have a question: What are you updating? If there some control on you Telenet dialog you are trying to read from? And are looking to update the dialog itself because that would be UpdateData(True)?

I would Change:
Code:
void CTelnetDlg::SetErrorMessage(CString cError)
{
    m_cErrorStatus = cError;
    //Or use a SetDlgText(...)
}
 

I have a label on the main dialog box.

The m_cErrorStatus is a CString connected to a label control on the main dialog box. The CString passed to the ErrorMessage function is placed into m_cErrorStatus. The UpdateData(false) places the contents of m_cErrorStatus into the label control.

This will not work. The statement
Code:
  CTelnetDlg ErrorMessage;
in the constructor of CTelnetDx does not execute a DoModal() function, there for it's not really there. I can't figure out a way to access the main dialog box. Hence, my most recent post asking how do I get the handle (HWND) of the main dialog box.


HyperEngineer
If it ain't broke, it probably needs improvement.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top