Please try this ,simple and it has bug.
-
Hi,All The following code giving me an error while running in Release Mode. I tested this code under Windows2000 professional,VC++6.0. CMyDlg::OnButton() { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } can any one tell me what is wrong with this code. My observations: 1.If i commented CString strTemp---It is not giving any error 2.If this code running under Debug Mode--it is not giving any error 3.If this code running under Release Mode with TRy CATCH--it is not giving any error TRY { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } CATCH(CExPetion,expGen) { char szError[100]; exGen->GetErrorMessage(szError,100); exGen->Delete(); } END_CATCH I am happiest man,If some one explain me step by step with this observations, why it is giving error in some conditions and not in another conditoions. Thank in Advance:rose: anju
-
Hi,All The following code giving me an error while running in Release Mode. I tested this code under Windows2000 professional,VC++6.0. CMyDlg::OnButton() { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } can any one tell me what is wrong with this code. My observations: 1.If i commented CString strTemp---It is not giving any error 2.If this code running under Debug Mode--it is not giving any error 3.If this code running under Release Mode with TRy CATCH--it is not giving any error TRY { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } CATCH(CExPetion,expGen) { char szError[100]; exGen->GetErrorMessage(szError,100); exGen->Delete(); } END_CATCH I am happiest man,If some one explain me step by step with this observations, why it is giving error in some conditions and not in another conditoions. Thank in Advance:rose: anju
-
Hi,All The following code giving me an error while running in Release Mode. I tested this code under Windows2000 professional,VC++6.0. CMyDlg::OnButton() { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } can any one tell me what is wrong with this code. My observations: 1.If i commented CString strTemp---It is not giving any error 2.If this code running under Debug Mode--it is not giving any error 3.If this code running under Release Mode with TRy CATCH--it is not giving any error TRY { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } CATCH(CExPetion,expGen) { char szError[100]; exGen->GetErrorMessage(szError,100); exGen->Delete(); } END_CATCH I am happiest man,If some one explain me step by step with this observations, why it is giving error in some conditions and not in another conditoions. Thank in Advance:rose: anju
Instead of
sscanf(szVal,"%X",&byByteCmd);
why not useatol()
? What I think your code is doing is that you are reading an int value (%X) into a BYTE variable and overwriting the next location(s) in memory you could try using %c
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
-
Hi,All The following code giving me an error while running in Release Mode. I tested this code under Windows2000 professional,VC++6.0. CMyDlg::OnButton() { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } can any one tell me what is wrong with this code. My observations: 1.If i commented CString strTemp---It is not giving any error 2.If this code running under Debug Mode--it is not giving any error 3.If this code running under Release Mode with TRy CATCH--it is not giving any error TRY { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } CATCH(CExPetion,expGen) { char szError[100]; exGen->GetErrorMessage(szError,100); exGen->Delete(); } END_CATCH I am happiest man,If some one explain me step by step with this observations, why it is giving error in some conditions and not in another conditoions. Thank in Advance:rose: anju
BYTE byByteCmd; .... sscanf(szVal,"%X",&byByteCmd); And types %X and %x require int or int alike (DWORD) argument, you are using byte. 1 byte vs 4 bytes... Due to debug mode padding you don't get an error.
-
Hi,All The following code giving me an error while running in Release Mode. I tested this code under Windows2000 professional,VC++6.0. CMyDlg::OnButton() { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } can any one tell me what is wrong with this code. My observations: 1.If i commented CString strTemp---It is not giving any error 2.If this code running under Debug Mode--it is not giving any error 3.If this code running under Release Mode with TRy CATCH--it is not giving any error TRY { BYTE byByteCmd; CString strTemp; char szVal[10]; szVal[0]='\0'; sprintf(szVal,"%d",1); sscanf(szVal,"%X",&byByteCmd); } CATCH(CExPetion,expGen) { char szError[100]; exGen->GetErrorMessage(szError,100); exGen->Delete(); } END_CATCH I am happiest man,If some one explain me step by step with this observations, why it is giving error in some conditions and not in another conditoions. Thank in Advance:rose: anju