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.
Printable View
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.
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
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??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));
}
};
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
Any ideas why it doesn't workCode: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
Thanks
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.Quote:
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.
Well...one thing I noticed is that your given example should not even compile. With the following lineQuote:
Originally posted by andreshs1
When the dialog doModal return I copy the values that it got from the CEdit boxes...
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:CUserDlg userDlg = new CUserDlg();
:confused: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)?
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?Quote:
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??
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?Quote:
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
Any ideas why it doesn't workCode: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
No, you don't...the constructor will be automatically called while constructing the enclosed class (in your case the dialog).Quote:
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??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));
}
};
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...Quote:
Originally posted by andreshs1
strcpy(m_userDet.userName,"hello");
this should copy hello into the m_userDet.userName but it doesn't copy anything
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
Oops, a VC++ .net project... Sorry, I won't be able to participate in the debugging party then... :( ;)
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...
'new' returns a pointer...henceCode:CUserDlg userDlg = new CUserDlg();//here were I create the instance of the dlg
would be correct... :confused:Code:CUserDlg *userDlg = new CUserDlg();//here were I create the instance of the dlg
- 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()'.
What...you need a physical debugger to debug code?? :D :D :DQuote:
Originally posted by gstercken
Oops, a VC++ .net project... Sorry, I won't be able to participate in the debugging party then... :( ;)
Well, we're all getting older... :DQuote:
Originally posted by Andreas Masur
What...you need a physical debugger to debug code?? :D :D :D
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
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... :cool:Quote:
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.
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??
Any suggestion?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;
Thanks