|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| Help! |
|
![]() Adrian99420 Member since: 11/3/2009 From: Kuala Lumpur, Malaysia |
||||
|
|
||||
| Hi all, urgent help needed. I faced error of "stack around the variable "hexxal" was corrupted. Any suggestion? UCHAR ucMifareKey[6] = {0}; ULONG ulMifareKeyLen = 0; m_strAuthentKey = "FFFFFFFFFFFF"; CStringToUchar(m_strAuthentKey,ucMifareKey,&ulMifareKeyLen); void CContactlessDemoVCDlg::CStringToUchar(CString str, UCHAR *ucBuffer, ULONG *ulBufferLen) { int Length = 0; int DataLength = 0; char cstr[] =""; char strcstring[512] =""; byte hexval=0x00; int i = 0; Length = str.GetLength(); for (i = 0; i<Length; i++) strcstring[i] = str.GetAt(i); DataLength = Length / 2; for (i = 0; i<DataLength; i++) { cstr[0] = strcstring[2*i]; cstr[1] = strcstring[2*i+1]; sscanf( cstr, "%02x", &hexval ); ucBuffer[i]=hexval; } *ulBufferLen = DataLength; } |
||||
|
||||
![]() alvaro Member since: 3/7/2002 From: USA |
||||
|
|
||||
| sscanf with a format specifier of "%02x" will read in an int, but you gave it a pointer to a single byte. You can try making hexval an int. If what you are reading is in range, that should work fine. |
||||
|
||||
![]() Adrian99420 Member since: 11/3/2009 From: Kuala Lumpur, Malaysia |
||||
|
|
||||
| Hi alvaro, Thanks for the reply, but when i changed the hexval to int, here comes the error of "Stack around the variable 'cstr' was corrupted". Any advice? |
||||
|
||||
![]() _fastcall Member since: 2/4/2008 From: Salt Lake City, UT, United States |
||||
|
|
||||
| UCHAR ucMifareKey[6] = {0}; ULONG ulMifareKeyLen = 0; m_strAuthentKey = "FFFFFFFFFFFF"; CStringToUchar(m_strAuthentKey,ucMifareKey,&ulMifareKeyLen); void CContactlessDemoVCDlg::CStringToUchar( const CString& str, UCHAR *ucBuffer, ULONG *ulBufferLen) { int Length = 0; int DataLength = 0; char cstr[3] = {}; assert( str.GetLength() % 2 == 0 ); DataLength = for ( int i = 0; i<DataLength; i++) { cstr[0] = str[2*i]; cstr[1] = str[2*i+1]; sscanf( cstr, "%02x", &hexval ); ucBuffer[i]= static_cast<UCHAR>(hexval); } *ulBufferLen = DataLength; } |
||||
|
||||
![]() Adrian99420 Member since: 11/3/2009 From: Kuala Lumpur, Malaysia |
||||
|
|
||||
| Hi all, I got the things work. Thanks for the help. |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|