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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Losing scope?

Status
Not open for further replies.

HyperEngineer

Programmer
May 8, 2002
190
US
Here's my problem. I have a button called Send. The OnSend functions works fine from within a procedure. But when I click on it, I get an error. Here is the code in the function.

Code:
void CTelnetDlg::OnGetData() 
{
	// TODO: Add your control notification handler code here
	int iRet, iCount = 0;
	char* cMsg;
	
	// Disable cancel button
	GetDlgItem(IDCANCEL)->EnableWindow(false);
	// Disable the Get Data button
	GetDlgItem(IDC_GET_DATA)->EnableWindow(false);
	SetDlgItemText(IDC_GET_DATA, "WORKING");
	// Clear received text
	m_cReceivedText = "";
	// Update the member variables just in case user changed them
	UpdateData(true);
	
	// Initialize the sockets
	CSocketDx m_SocketDx((void*) this);
	
	// Start the read / write processes
	m_hSocket = m_SocketDx.TelnetConnect(m_cErrorStatus);
	UpdateData(false);
	
	// Start the Rx & Tx threads
	CSocketRx m_SocketRx(m_hSocket, m_hThread[0], (void*) this);
	CSocketTx m_SocketTx(m_hSocket, m_hThread[1], (void*) this);
	
	SetEvent(m_hStartSessionEvent);
	
	iRet = WaitForSingleObject(m_hLoggedInEvent, 5000);
	switch (iRet)
	{
	case WAIT_OBJECT_0:
		// We have successfully logged in
		MessageBox("Logged in", "Telnet", MB_OK);
		break;
	default:
		// We either timed out or have an error
		// Either way were outta here
		// Close threads
		TerminateThread(m_hThread[0], 0);
		TerminateThread(m_hThread[1], 0);
		// Enable and recaption Get Data button
		SetDlgItemText(IDC_GET_DATA, "Get Data");
		GetDlgItem(IDC_GET_DATA)->EnableWindow(true);
		// Enable cancel button
		GetDlgItem(IDCANCEL)->EnableWindow(true);
		// Leave this pop-stand
		MessageBox("Did not log in", "Telnet", MB_OK);
		return;
	}
	
	// Now lets get some data
	// First get the async errors
	SetDlgItemText(IDC_SEND_COMMAND,"clnkstat a");
	OnSend();
	
	// Retrieve data from member variable
	TimeDelay(3);

	m_cReceivedText = g_cReceivedText;
	UpdateData(false);

	cMsg = (char*) malloc(64);
	sprintf(cMsg, "Data retrieved");
	MessageBox(cMsg, "Telnet Session",MB_OK);
	free(cMsg);

	// Enable and change caption for Get Ready button
	GetDlgItem(IDC_GET_DATA)->EnableWindow(true);
	SetDlgItemText(IDC_GET_DATA, "READY");
	
	// Enable cancel button
	GetDlgItem(IDCANCEL)->EnableWindow(true);

}

Here is the code in the OnSend function:
Code:
void CTelnetDlg::OnSend() 
{
  // TODO: Add your control notification handler code here
  UpdateData(true);
  SetEvent(m_hSendRequestEvent);
}

The error I get is:

The instruction at "0x5f4771b5" referenced memory at "0xcccccdac". The memory could not be "read".
Click on OK to terminate the program

The classes and variable should all still be there. The OnSend button is clicked after the OnGetData is clicked so that the classes are instantiated. Did someone lose scope here?

thanks,

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

Part and Inventory Search

Sponsor

Back
Top