Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 797
  • Last Modified:

Passing values to a dialog

Hi,

I have a small app that connects to a server via the CAsyncSocket class, such class called CConnSocket.

I have a buddylist CDialog that opens when the application runs, class called CBuddyChatDlg.

then upon double clicking a item from a CListBox which is in my CBuddyChatDlg, a new dialog opens called CChatWindowDlg,

now before any of this starts to happen it is initiated by clicking a button on CBuddyChatDlg which connects to a specific server which sends back a reply of LOGIN-OK, then my client sends a request for a buddylist update, which the server replys with, but when my client (CConnSocket) tries to pass the data to the CListBox in my dialog (CBuddyChatDlg) class it crashes.

code from CConnSocket:
      if (command == "BUDDYLIST")
      {
            //((CBuddyChatDlg*)m_pWnd) -> doUpdateBuddyList(token);
            // function in CBuddyChatDlg to update buddy list

            char seps[]   = " ";
            
            ((CBuddyChatDlg*)m_pWnd) -> doTest();
            //  it does this ok!!!!, displays a AfxMessageBox("Display this") from CBuddyChatDlg

            ((CBuddyChatDlg*)m_pWnd) -> m_ctlBuddyList.ResetContent();
            // program stops on this, does not get any further.

            token = strtok( NULL, seps );
            //takes the first nickname only

            while( token != NULL )
            {
                  ((CBuddyChatDlg*)m_pWnd) -> m_ctlBuddyList.AddString(token);
                  token = strtok( NULL, seps ); //takes the first nickname only
            }
      }

in CConnSocket for the dialog to work i have:

void CConnSocket::SetParent(CDialog *pWnd)
{
      //set pointer
      m_pWnd = pWnd;
}

private:
      CDialog *m_pWnd;

and included the header for CBuddyChatDlg,

Error output when CConnSocket does ((CBuddyChatDlg*)m_pWnd) -> m_ctlBuddyList.ResetContent();

Call Stack:
CListBox::ResetContent() line 675 + 13 bytes
CConnSocket::OnReceive(int 0) line 123
CAsyncSocket::DoCallBack(unsigned int 1872, long 1) line 529
CSocket::ProcessAuxQueue() line 822
CSocketWnd::OnSocketNotify(unsigned int 1872, long 1) line 1126
CWnd::OnWndMsg(unsigned int 883, unsigned int 1872, long 1, long * 0x0012e748) line 1815 + 17 bytes
CWnd::WindowProc(unsigned int 883, unsigned int 1872, long 1) line 1585 + 30 bytes
AfxCallWndProc(CWnd * 0x00a81150 {CSocketWnd hWnd=0x004006ca}, HWND__ * 0x004006ca, unsigned int 883, unsigned int 1872, long 1) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x004006ca, unsigned int 883, unsigned int 1872, long 1) line 368
USER32! 77d43a68()
USER32! 77d43b37()
USER32! 77d43d91()
USER32! 77d43df7()
USER32! 77d4d9aa()
USER32! 77d662f4()


Context:
CListBox::ResetContent()
-      this      0xcccccd64 {CListBox hWnd=???}
-      CWnd      {CWnd hWnd=???}
+      CCmdTarget      {CCmdTarget}
+      classCWnd      {"CWnd"}
      m_hWnd      CXX0030: Error: expression cannot be evaluated
+      wndTop      {CWnd hWnd=0x00000000}
+      wndBottom      {CWnd hWnd=0x00000001}
+      wndTopMost      {CWnd hWnd=0xffffffff}
+      wndNoTopMost      {CWnd hWnd=0xfffffffe}
      m_hWndOwner      CXX0030: Error: expression cannot be evaluated
      m_nFlags      CXX0030: Error: expression cannot be evaluated
      m_pfnSuper      CXX0030: Error: expression cannot be evaluated
      m_nMsgDragList      49289
      m_nModalResult      CXX0030: Error: expression cannot be evaluated
      m_pDropTarget      CXX0030: Error: expression cannot be evaluated
      m_pCtrlCont      CXX0030: Error: expression cannot be evaluated
      m_pCtrlSite      CXX0030: Error: expression cannot be evaluated
+      _messageEntries      0x005b97b0 struct AFX_MSGMAP_ENTRY const * const CWnd::_messageEntries
+      messageMap      {...}
+      classCListBox      {"CListBox"}


Context:
CConnSocket::OnReceive()
-      m_pWnd      0xcccccccc {CDialog hWnd=???}
+      CWnd      {CWnd hWnd=???}
+      classCDialog      {"CDialog"}
      m_nIDHelp      CXX0030: Error: expression cannot be evaluated
      m_lpszTemplateName      CXX0030: Error: expression cannot be evaluated
      m_hDialogTemplate      CXX0030: Error: expression cannot be evaluated
      m_lpDialogTemplate      CXX0030: Error: expression cannot be evaluated
      m_lpDialogInit      CXX0030: Error: expression cannot be evaluated
      m_pParentWnd      CXX0030: Error: expression cannot be evaluated
      m_hWndTop      CXX0030: Error: expression cannot be evaluated
      m_pOccDialogInfo      CXX0030: Error: expression cannot be evaluated
+      _messageEntries      0x005b8dd8 struct AFX_MSGMAP_ENTRY const * const CDialog::_messageEntries
+      messageMap      {...}
+      seps      0x0012e58c " "
-      this      0x0012fed8 {CConnSocket}
+      CAsyncSocket      {CAsyncSocket}
-      m_pWnd      0xcccccccc {CDialog hWnd=???}
+      CWnd      {CWnd hWnd=???}
+      classCDialog      {"CDialog"}
      m_nIDHelp      CXX0030: Error: expression cannot be evaluated
      m_lpszTemplateName      CXX0030: Error: expression cannot be evaluated
      m_hDialogTemplate      CXX0030: Error: expression cannot be evaluated
      m_lpDialogTemplate      CXX0017: Error: symbol "" not found
      m_lpDialogInit      CXX0030: Error: expression cannot be evaluated
      m_pParentWnd      CXX0030: Error: expression cannot be evaluated
      m_hWndTop      CXX0030: Error: expression cannot be evaluated
      m_pOccDialogInfo      CXX0017: Error: symbol "" not found
+      _messageEntries      0x005b8dd8 struct AFX_MSGMAP_ENTRY const * const CDialog::_messageEntries
+      messageMap      {...}
+      m_pParent      0xcccccccc {CDialog hWnd=???}
-      token      0x00a76f09 "BUDDYLIST"
            66 'B'


Can anyone help me with this problem please, have also just tried adding SetParent to CBuddyChatDlg too but that has not worked either so have taken it back out again.

many thanks.
0
firefox2003
Asked:
firefox2003
  • 13
  • 13
1 Solution
 
Roshan DavisCommented:
code from CConnSocket:
    if (command == "BUDDYLIST")
     {
         if ( ::IsWindow(m_pWnd->m_hWnd) )           <----------------------- ADD THIS LINE
        {
                     char seps[]   = " ";
         
                     ((CBuddyChatDlg*)m_pWnd) -> doTest();
                    //  it does this ok!!!!, displays a AfxMessageBox("Display this") from CBuddyChatDlg

                    ((CBuddyChatDlg*)m_pWnd) -> m_ctlBuddyList.ResetContent();
                    // program stops on this, does not get any further.

                     token = strtok( NULL, seps );
                   //takes the first nickname only

                     while( token != NULL )
                  {
                           ((CBuddyChatDlg*)m_pWnd) -> m_ctlBuddyList.AddString(token);
                            token = strtok( NULL, seps ); //takes the first nickname only
                  }
           }
    }

Rosh :)
0
 
firefox2003Author Commented:
Hi,

Just tried that, and it crashes on : if ( ::IsWindow(m_pWnd->m_hWnd) )


+      command      {"BUDDYLIST"}
-      m_pWnd      0xcccccccc {CDialog hWnd=???}
+      CWnd      {CWnd hWnd=???}
+      classCDialog      {"CDialog"}
      m_nIDHelp      CXX0030: Error: expression cannot be evaluated
      m_lpszTemplateName      CXX0030: Error: expression cannot be evaluated
      m_hDialogTemplate      CXX0030: Error: expression cannot be evaluated
      m_lpDialogTemplate      CXX0017: Error: symbol "" not found
      m_lpDialogInit      CXX0030: Error: expression cannot be evaluated
      m_pParentWnd      CXX0030: Error: expression cannot be evaluated
      m_hWndTop      CXX0030: Error: expression cannot be evaluated
      m_pOccDialogInfo      CXX0017: Error: symbol "" not found
+      _messageEntries      0x005b8dd8 struct AFX_MSGMAP_ENTRY const * const CDialog::_messageEntries
+      messageMap      {...}
+      this      0x0012fedc {CConnSocket}
0
 
Roshan DavisCommented:
Initialize the pointer "m_pWnd " with null in constructor

and change that if condition like

 if ( m_pWnd && ::IsWindow(m_pWnd->m_hWnd) )           <----------------------- ADD THIS LINE


Good Luck
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
firefox2003Author Commented:
sorry having a blonde day,

how do i initalize the pointer?

CDialog *m_pWnd;

?
0
 
Roshan DavisCommented:
In your Dialog's constructor, put

m_pWnd = NULL;


eg:


CYourDialog::CYourDialog()
{
       m_pWnd = NULL;

}


Rosh :)
0
 
firefox2003Author Commented:
Rosh,

Now it does not crash but not it also does not do my function, it stops at ( m_pWnd && ::IsWindow(m_pWnd->m_hWnd) )  

:o/
0
 
firefox2003Author Commented:
also CConnSocket is not a dialog, but CBuddyChatDlg is, and im calling a function from CBuddyChatDlg from CConnSocket, if this makes it a problem?
0
 
Roshan DavisCommented:
Ohh yes,

The Function "SetParent" (that you mentioned in the above code) is not calling...!!!

Call this funtion b4 the socket connection

Good luck
0
 
firefox2003Author Commented:
Ok,

But how can i get the SetParent function set?

As the socket connection is set in CBuddyChatDlg, so i take it SetParent needs to be set in CConnSocket?

How would i do this successfully?

Sorry for all the hassle i have uped the points for you if this works.

=)
0
 
Roshan DavisCommented:
Code will look like this


CConnSocket oSocket;

oSocket.SetParent(&m_dlg);

Call the socket processing functions after this ....

Rosh :)

0
 
firefox2003Author Commented:
well now my app wont compile at all,

sigh, its not moaning about your last code snippit, its now complaining about:

CConnSocket m_sConnectSocket; in CBuddyChatDlg, when its perfectly ok and has been working fine, why all of a sudden does it not know what it is ?

(note, the header is still there)

e:\working directory\buddychat\buddychatdlg.h(60) : error C2146: syntax error : missing ';' before identifier 'm_sConnectSocket'
e:\working directory\buddychat\buddychatdlg.h(60) : error C2501: 'CConnSocket' : missing storage-class or type specifiers
e:\working directory\buddychat\buddychatdlg.h(60) : error C2501: 'm_sConnectSocket' : missing storage-class or type specifiers

Also I take it I need to specify m_dlg as CBuddyChatDlg m_dlg; in my header of CConnSocket, yes ?

which also after including the header for CBuddyChatDlg i get this:

e:\working directory\buddychat\connsocket.h(48) : error C2146: syntax error : missing ';' before identifier 'm_dlg'
e:\working directory\buddychat\connsocket.h(48) : error C2501: 'CBuddyChatDlg' : missing storage-class or type specifiers
e:\working directory\buddychat\connsocket.h(48) : error C2501: 'm_dlg' : missing storage-class or type specifiers

why why why
0
 
Roshan DavisCommented:
>>  need to specify m_dlg as CBuddyChatDlg m_dlg; in my header of CConnSocket, yes ?
No. You already have the m_pWnd right...? So thatz not needed.

Rosh :)
0
 
firefox2003Author Commented:
Ok taken that out but still getting this:

Compiling...
BuddyChat.cpp
BuddyChatDlg.cpp
e:\working directory\buddychat\buddychatdlg.h(59) : error C2146: syntax error : missing ';' before identifier 'm_sConnectSocket'
e:\working directory\buddychat\buddychatdlg.h(59) : error C2501: 'CConnSocket' : missing storage-class or type specifiers
e:\working directory\buddychat\buddychatdlg.h(59) : error C2501: 'm_sConnectSocket' : missing storage-class or type specifiers
E:\Working Directory\BuddyChat\BuddyChatDlg.cpp(204) : error C2065: 'm_sConnectSocket' : undeclared identifier

but i have not touched that class and now its having a fit about it, is there something stupidly wrong in my header?

#include "ConnSocket.h"

...

private:
      CConnSocket m_sConnectSocket;

...
0
 
Roshan DavisCommented:
Check for any semi colon missing
Also check is there any additional bracket ( "}" ) happened accidently.
Rosh :)
0
 
firefox2003Author Commented:
Rosh,

I have looked and looked and looked, i can see nothing wrong.

Could you please visit

http://212.158.208.253/code.rar

and have a look at it please.

tks

tomski
0
 
Roshan DavisCommented:
Remove the line

include "BuddyChatDlg.h"      // Added by ClassView

from the file ConnSocket.h

Rosh :)
0
 
firefox2003Author Commented:
damn bloody classview, cheers, why does that happen?

also             CConnSocket oSocket;

            oSocket.SetParent(&m_dlg);

goes in CConnSocket but... m_dlg not definded

:)

ill up the point again...
0
 
Roshan DavisCommented:
That include files got deadlock, refering each other

Add SetParent in the line 203 of BuddyChatDlg.cpp like

"
m_sConnectSocket.SetParent(this);
int iSent = m_sConnectSocket.Create(); // 0 if executed unsuccessfully
"

Here is one chat program, you can try that also...
http://www.codeguru.com/network/netmsg-fxx.html
Good luck
0
 
firefox2003Author Commented:
thats worked like a dream, will also have a look at that other application.

many many thanks for all your help.

tom
0
 
Roshan DavisCommented:
:0)
Rosh
0
 
firefox2003Author Commented:
Urm just one last thing, how would I go about calling a function from CConnSocket from my CChatWindowDlg  like when i click a button called send msg?

??
0
 
Roshan DavisCommented:
Add a Function in CChatWindowDlg  eg

CChatWindowDlg::SetSockConnection(CConnSocket *pConn)
{
      m_pConnSock = pConn;
}

and in your header, add

CConnSocket *m_pConnSock;


After the line "CChatWindowDlg* dlg = new CChatWindowDlg;"

Add

dlg->SetSockConnection(&m_sConnectSocket);

Good luck
0
 
firefox2003Author Commented:
Oh sorry one last last last thing:

      { ASSERT(::IsWindow(m_hWnd)); return (int)::SendMessage(m_hWnd, LB_ADDSTRING, 0, (LPARAM)lpszItem); }

error when i try to set a CListBox to have some contents

this is the CConnSocket passing my CChatWindowDlg a CString.

;o)
0
 
Roshan DavisCommented:
Good Morning,
Sorry I was not here,
Where this line added?

Rosh :)
0
 
firefox2003Author Commented:
right well when this is done:

code from CConnSocket that forwards the CString to my CChatWindowDlg is:

     if (command == "MSG")
     {
          CString msg = "connsocket on receive if command == msg .. ";
          AfxMessageBox(msg + strRecvd);

          ((CChatWindowDlg*)m_pWnd) -> doProcessMsg(strRecvd); // receive a message

     }

and the code in my CChatWindowDlg is:

void CChatWindowDlg::doProcessMsg(CString strRecvd)
{
     AfxMessageBox(strRecvd);

     char *token = strRecvd.GetBuffer(1024);

     char seps[] = " ";

     token = strtok( NULL, seps ); //takes off msg
     CString buddy = token; // leaving nick
          AfxMessageBox(buddy);

     token = strtok( NULL, "" ); //takes off nick          
      CString msg = "    ";
     msg += token; // for the first non loop
           AfxMessageBox(msg);

     //add the message to the received box
      m_sRecvd.AddString("hello"); // CRASH HERE ***************
     //m_sRecvd.AddString(buddy); // the buddy
     //m_sRecvd.SetTopIndex(m_sRecvd.AddString(msg)); //the message
0
 
Roshan DavisCommented:
That dialog creation should come before this "doProcessMsg", I think that dialog handle is not valid, please check with IsWindow function.

I'm going out for lunch, I will check that today itself.

Rosh :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 13
  • 13
Tackle projects and never again get stuck behind a technical roadblock.
Join Now