Click here to Skip to main content
Click here to Skip to main content
Go to top

Non-MFC ByteArray Class for ATL

, 30 Apr 2001
Rate this:
Please Sign up or sign in to vote.
Non-MFC ByteArray Class for an ATL Component
<!-- Download Links --> <!-- Main HTML starts here -->

Introduction

When writing ATL components, I have found that one of the hardest things for Windows programmers to overcome is the dependency on the MFC library. For dates, strings and byte arrays, MFC simplifies the programmer's job by handling memory allocations and type conversions within its class encapsulation. However, with that simplification comes the price of having to distribute the MFC DLL's with your component.

This article focuses on the issues surrounding the use of byte arrays in an ATL component. If you don’t include MFC support in your ATL component, you obviously won’t have the CByteArray available to use.  I, therefore, wrote CCOMByteArray to provide the functionality of MFC's CByteArray, but without the MFC dependency.  Please note that I do not currently include exception handling for the memory allocation functions.  I am currently trapping any memory allocation errors with the ATLASSERT macro, but these will compile away in Release mode.  This functionality along with performance improvements will be added to a future version.

The current version of the CCOMByteArray includes the following functionality.  Please note, if there are any functions in the CCOMByteArray class that you download that are not listed in the text below, they are considered to be undocumented and, therefore, possibly untested as well:

Constructors

  • CCOMByteArray() - Constructs an empty byte array.
  • CCOMByteArray(BYTE*, UINT) - Constructs a CCOMByteArray object from a pointer to a BYTE array.
  • CCOMByteArray(BSTR&) - Constructs a CCOMByteArray object from a Binary String (i.e., BSTR)
  • CCOMString(BSTR) - Constructs a CCOMByteArray object from a BSTR.

Attributes

  • GetSize() const - Returns the size of the byte array.
  • GetUpperBound() const - Returns the upper boundary (i.e., the size minus one) of the byte array.
  • SetSize(UINT, UINT) - Set the size of the array along with the grow by factor.

Cleanup

  • RemoveAll() - Removes all elements from the array.
  • FreeExtra() - Free any extra allocated memory that is not currently used by the array.

Accessors

  • GetAt(UINT) const - Returns the byte located at the specified location.
  • ElementAt(UINT) - Returns a reference to the byte located at the specified location.
  • SetAt(BYTE, UINT) - Sets the element to the specified byte value at the specified location.

Accessors

  • GetAt(UINT) const - Returns the byte located at the specified location.
  • Operator[](UINT) - Same functionality as GetAt(UINT) (See above).
  • ElementAt(UINT) - Returns a reference to the byte located at the specified location.
  • SetAt(BYTE, UINT) - Sets the element to the specified byte value at the specified location.

Direct Access

  • GetData() const - Returns a pointer to the array contained in CCOMByteArray.

Growing the Array

  • Append(BYTE) - Adds the specified byte to the existing array.
  • Append(const CCOMByteArray&apm;) - Adds the specified CCOMByteArray to the existing array.
  • Append(BYTE*, UINT) - Adds the array specified by the BYTE* to the existing array.
  • Append(BSTR&) - Adds the specified Binary String to the existing array.
  • Operator+=(CCOMByteArray&) - Same functionality as Append(CCOMByteArray&) (See above).
  • Operator+=(BYTE&) - Same functionality as Append(BYTE&) (See above).
  • Operator+=(BSTR&) - Same functionality as Append(BSTR&) (See above).

Move Elements Around

  • InsertAt(UINT, BYTE, UINT) - Inserts the specified byte at the specified location for the specified count.
  • InsertAt(UINT, CCOMByteArray&) - Inserts the specified CCOMByteArray starting at the specified location.
  • RemoveAt(UINT, UINT) - Removes the element at the specified location for the specified count.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Paul E. Bible
Software Developer (Senior)
United States United States
Eat, Sleep, Code, Bike. That about sums it up!!

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 1 May 2001
Article Copyright 2001 by Paul E. Bible
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid