Application crashes on trying to call ListBox.AddString("Text") in Visual Studio [Client/Server]

-2

I am trying to create a MFC Application (Client/Server) in Visual Studio and have a Listbox on the main dialog box to display a text when the connection is accepted. In my Sockets class I have the following code:

   void CServerSock::OnAccept(int nErrorCode)
{

    CString text="Some Text";

    ((CServerDlg*)pDlg)->msgMaker(text);

    CSocket::OnAccept(nErrorCode);
}

In my Dialog class, I have the msgMaker function defined as follows:

void CServerDlg::msgMaker(CString cList)
{   

    CString randomtext;
    randomtext= cList;
    dispCntrl.AddString(randomtext);
}

The program compiles without error, but when the actual call for the onAccept function is made, it sends the text perfectly and msgMaker function receives it as well, but the application crashes and gives me the following error:

Exception Thrown:
Exception thrown at 0x5FCE5084 (mfc140ud.dll) in Server.exe: 0xC0000005: 
Access violation reading location 0x000001B0.

I understand the problem is with the following line, but it seems to be working fine if called elsewhere:

dispCntrl.AddString(randomtext);
c++
visual-studio
exception
visual-c++
mfc
asked on Stack Overflow Jun 30, 2018 by Marty Harisson • edited Jun 30, 2018 by Anselmo G PP

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0