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??
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."
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.
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)?
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?
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...
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
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."
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()'.
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.
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...
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."
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.