Solved

Passing values to a dialog

Posted on 2003-11-16
26
770 Views
Last Modified: 2013-11-20
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
Comment
Question by:firefox2003
  • 13
  • 13
26 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9761539
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
 

Author Comment

by:firefox2003
ID: 9762544
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
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9762557
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
 

Author Comment

by:firefox2003
ID: 9762577
sorry having a blonde day,

how do i initalize the pointer?

CDialog *m_pWnd;

?
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9762600
In your Dialog's constructor, put

m_pWnd = NULL;


eg:


CYourDialog::CYourDialog()
{
       m_pWnd = NULL;

}


Rosh :)
0
 

Author Comment

by:firefox2003
ID: 9762652
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
 

Author Comment

by:firefox2003
ID: 9762662
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
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9762678
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
 

Author Comment

by:firefox2003
ID: 9762715
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
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9762781
Code will look like this


CConnSocket oSocket;

oSocket.SetParent(&m_dlg);

Call the socket processing functions after this ....

Rosh :)

0
 

Author Comment

by:firefox2003
ID: 9762922
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
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9762962
>>  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
 

Author Comment

by:firefox2003
ID: 9763367
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9763615
Check for any semi colon missing
Also check is there any additional bracket ( "}" ) happened accidently.
Rosh :)
0
 

Author Comment

by:firefox2003
ID: 9763747
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
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9763792
Remove the line

include "BuddyChatDlg.h"      // Added by ClassView

from the file ConnSocket.h

Rosh :)
0
 

Author Comment

by:firefox2003
ID: 9763820
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
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 70 total points
ID: 9763878
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
 

Author Comment

by:firefox2003
ID: 9763914
thats worked like a dream, will also have a look at that other application.

many many thanks for all your help.

tom
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9763944
:0)
Rosh
0
 

Author Comment

by:firefox2003
ID: 9764062
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
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9764115
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
 

Author Comment

by:firefox2003
ID: 9764521
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
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9768769
Good Morning,
Sorry I was not here,
Where this line added?

Rosh :)
0
 

Author Comment

by:firefox2003
ID: 9769523
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
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9769544
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 87
sameEnds challenge 3 107
substring method in java 1 79
MaxSpan challenge 9 67
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now