/////////////////////////////////////////////////////////////////////////////// // // (c) Digi International Inc. 2002. All Rights Reserved // // Digi provides this document "as is," without warranty of any kind, // either expressed or implied, including, but not limited to, the implied // warranties of fitness or merchantability for a particular purpose. Digi // may make improvements and/or changes in this document or in the product(s) // and/or the program(s) described in this document at any time. // // This document could include technical inaccuracies or typographical errors. // Changes are periodically made to the information herein; these changes may // be incorporated in new editions of the publication. // // Digi International Inc. // 11001 Bren Road East // Minnetonka, MN 55343, USA // Tel: +1 (952) 912-3444 // Fax: +1 (952) 912-4952 // http://www.digi.com/ // /////////////////////////////////////////////////////////////////////////////// // HexDumpData.cpp : implementation file // #include "stdafx.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif //--------------------------------------------------------------------------- // // HexDumpData // // Description: // // Utitily function for dumping data in a human readable hex format to // a CListBox // // Parameters: // // ListBoxCtrl - CListBox object to which data is dumped // Data - Pointer to contiguous byte array of data // Length - Number of bytes Data points to // // Return Value: // // Remarks: // // This function assumes that Data is a valid pointer to at least // Length number of bytes. // //--------------------------------------------------------------------------- void HexDumpData(CListBox &ListBoxCtrl, BYTE const * const Data, DWORD const Length) { CString HexString; CString CharString; for (DWORD i = 0; i < Length; i++) { BYTE Datum = Data[i]; CString FormatString; FormatString.Format(_T("%.2x "), Datum); HexString += FormatString; FormatString.Format(_T("%c"), isprint(Datum) ? Datum : _T('.')); CharString += FormatString; DWORD NextIndex = (i + 1); if ((NextIndex % 8 == 0) || (NextIndex == Length)) { CString DumpString; DumpString.Format(_T("%-26.26s%s"), (LPCTSTR)HexString, (LPCTSTR)CharString); ListBoxCtrl.AddString((LPCTSTR)DumpString); HexString.Empty(); CharString.Empty(); } } }