CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 34
  1. #16
    Join Date
    Dec 2001
    Location
    Bremen, Germany
    Posts
    314
    I do not know if anyone already pointed out the article "Surviving the release version" by Joseph M. Newcomer:

    http://www.codeproject.com/debug/survivereleasever.asp

    I think this one is very advisable.

    Oliver.

  2. #17
    Join Date
    Feb 2003
    Location
    Tokyo, Japan
    Posts
    93
    Thank you for the tip Oliver, I have read that article few times today, and I identify the problems in my code, which are the initialization of the variables, and I since I am fairly a new programmer I am going mad trying to find the way to initializate the variables

    at present the problem I have is that one of the member variables of one of the classes is a struct
    Code:
    struct USERDET
    {
      BOOL newUser;
      char userName[25];
      char passWord[25];
    
      USERDET()//initialisation as Mr Masur suggested
      {
        newUser = FALSE;
        memset(userName, 0, sizeof(userName));
        memset(passWord, 0, sizeof(passWord));
      }
    };
    that struct is initialized on the struct definition but do I need to initialized also in the class constructor? if so, how do I do it??

    at the moment without initializing the struct on the class constructor when I try to access the values of the struct these values are set and I cant modify them such as by
    Code:
    strcpy(m_userDet.userName,userDlg.m_userName);
    		strcpy(m_userDet.passWord,userDlg.m_passWord);
    		
    nothing gets copied accross no even like fallow
    
    strcpy(m_userDet.userName,"hello");
    
    this should copy hello into the m_userDet.userName but it doesn't copy anything
    Any ideas why it doesn't work

    Thanks
    Favourite Quotes

    "In the first place, God made idiots. That was for practice. Then he made developers."

    "Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done."

  3. #18
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    Originally posted by Oliver Twesten
    I do not know if anyone already pointed out the article "Surviving the release version" by Joseph M. Newcomer:

    http://www.codeproject.com/debug/survivereleasever.asp

    I think this one is very advisable.
    Yes, the FAQ mentioned also links to it - as a last resort. That article is indeed very good and comprehensive - the FAQ covers the most frequent causes for release build problems, and points to that detailed article in the case everything else fails.

  4. #19
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by andreshs1
    When the dialog doModal return I copy the values that it got from the CEdit boxes...
    Well...one thing I noticed is that your given example should not even compile. With the following line
    Code:
    CUserDlg userDlg = new CUserDlg();
    you create the dialog on the heap (using a pointer)...later on, however, you are accessing the dialog as it was created on the stack...
    Code:
    rtnDlg = userDlg.DoModal();
    if (rtnDlg == IDOK)
    {
      strcpy(m_userDet.userName,userDlg.m_userName);
      strcpy(m_userDet.passWord,userDlg.m_passWord);
    		
      //stablish connection to server
      if (!cConnect->GetConnected(m_userDet))
      {
      }
    ]


    Other than that...could you post your project here (without debug and release directory)?

  5. #20
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    Originally posted by andreshs1
    that struct is initialized on the struct definition but do I need to initialized also in the class constructor? if so, how do I do it??
    I don't understand what you mean by "initialized on the struct definition", but the code suggested by Andreas uses the struct's ctor for initialization. Which other class constructor are you referring to?

    Originally posted by andreshs1
    at the moment without initializing the struct on the class constructor when I try to access the values of the struct these values are set and I cant modify them such as by
    Code:
    strcpy(m_userDet.userName,userDlg.m_userName);
    		strcpy(m_userDet.passWord,userDlg.m_passWord);
    		
    nothing gets copied accross no even like fallow
    
    strcpy(m_userDet.userName,"hello");
    
    this should copy hello into the m_userDet.userName but it doesn't copy anything
    Any ideas why it doesn't work
    Note that those problems have nothing to do with the struct members being initialized or not - the strcpy you showed should definitely copy the strings to the struct members, regardless of the previous content. So the problem must be something else - are you sure you are looking at the same instance of the struct in both cases? And since the struct instance seems to be a member of a class - are you sure you a looking at the same instance of that class?

  6. #21
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by andreshs1
    Code:
    struct USERDET
    {
      BOOL newUser;
      char userName[25];
      char passWord[25];
    
      USERDET()//initialisation as Mr Masur suggested
      {
        newUser = FALSE;
        memset(userName, 0, sizeof(userName));
        memset(passWord, 0, sizeof(passWord));
      }
    };
    that struct is initialized on the struct definition but do I need to initialized also in the class constructor? if so, how do I do it??
    No, you don't...the constructor will be automatically called while constructing the enclosed class (in your case the dialog).


    Originally posted by andreshs1
    strcpy(m_userDet.userName,"hello");

    this should copy hello into the m_userDet.userName but it doesn't copy anything
    What? That is basically impossible. The above line will definitely copy the word 'hello' into 'userName'. Somehow I get the impression that you are copying to a local (-> different) structure than the one enclosed by the dialog class...

  7. #22
    Join Date
    Feb 2003
    Location
    Tokyo, Japan
    Posts
    93
    ok, I am posting the application, I have left break points where the problem is detected, hope you manage to understand, thanks in advance for all your help

    once the application is launched, go the the menu and click connect

    Thanks
    Attached Files Attached Files
    Favourite Quotes

    "In the first place, God made idiots. That was for practice. Then he made developers."

    "Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done."

  8. #23
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    Oops, a VC++ .net project... Sorry, I won't be able to participate in the debugging party then...

  9. #24
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Well...I do not have any development IDE installed at the moment, and I just saw that you are using .NET. Thus, I simply looked over the code...
    • Run your application within the debugger and step into the constructor of 'CTCPChatClientDlg' and take a look what the value of 'm_userDet.passWord' and 'm_userDet.userName' is after doing the 'strcpy()'.
    • The following does not make sense to me and should not make it through the compiler...
      Code:
      CUserDlg userDlg = new CUserDlg();//here were I create the instance of the dlg
      'new' returns a pointer...hence
      Code:
      CUserDlg *userDlg = new CUserDlg();//here were I create the instance of the dlg
      would be correct...
    • Run your application within the debugger and step into the function 'OnConnectMenu()' and take a look what the value of 'm_userDet.passWord' and 'm_userDet.userName' is after doing the 'strcpy()'.

  10. #25
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by gstercken
    Oops, a VC++ .net project... Sorry, I won't be able to participate in the debugging party then...
    What...you need a physical debugger to debug code??

  11. #26
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    Originally posted by Andreas Masur
    What...you need a physical debugger to debug code??
    Well, we're all getting older...

  12. #27
    Join Date
    Feb 2003
    Location
    Tokyo, Japan
    Posts
    93

    Exclamation

    ok, lets see

    on the constructor the values are ok, but I tried to to a test such as
    Code:
    CTCPChatClientDlg::CTCPChatClientDlg(CWnd* pParent /*=NULL*/)
    	: CDialog(CTCPChatClientDlg::IDD, pParent)
    {
    	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    	//structure definition
    	m_socket = 0;
    	m_userList.status = 0;
    	m_userList.UserId= 0;
    	m_dlgCounter = 0;
    	m_userDet.newUser = 0;
    	strcpy(m_userDet.passWord,"test");//the values here are not modified, why???? 
    //the new value should be "test"!!!!!
    	strcpy(m_userDet.userName,"test");
    		
    }

    Thank you, Mr Masur and Mr gstercken
    Favourite Quotes

    "In the first place, God made idiots. That was for practice. Then he made developers."

    "Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done."

  13. #28
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    OK, OK, just a little doubt... You are debugging the release version, right? Remember (from the FAQ) that the current line you see in the debugger doesn't always exactly correspond to the actual line being executed (due to optimizations)? Try stepping a few lines further and see if the values change.

  14. #29
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by gstercken
    OK, OK, just a little doubt... You are debugging the release version, right? Remember (from the FAQ) that the current line you see in the debugger doesn't always exactly correspond to the actual line being executed (due to optimizations)? Try stepping a few lines further and see if the values change.
    Is he still? That would of course explain some things...

  15. #30
    Join Date
    Feb 2003
    Location
    Tokyo, Japan
    Posts
    93
    I am very very sorry guys, you are right, I didn't remember that sometime the line I see is not updated and I wasn't continueing with the debbuging.

    Sorry and Thanks!!

    another problem I now have is that I use a variable which stores the value of the created socket, but I can only use it once because the second time the values is gone, any ideas why??

    Code:
    
    	ioctlsocket(m_socket,FIONREAD,&size);//here the value of socket it is fine
    
    	while(size > 0)
    	{
    		rtn = recv(m_socket,buff,strlen(buff),0);//the value of socket disappears, 
                                                       //and doesn't receive anything
    		if(rtn == SOCKET_ERROR)
    		{
    			AfxMessageBox("****"+m_socket);
    		}
    		str += buff;
    		size = size - rtn;
    	}
    	strcpy(buff,str);
    	ptrPacket = (PACKET*)buff;
    Any suggestion?


    Thanks
    Favourite Quotes

    "In the first place, God made idiots. That was for practice. Then he made developers."

    "Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done."

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured