This interface is implemented on a byte array object that is backed by some physical storage, such as a disk file, global memory, or a database. It is used by a Component Object Model (COM) compound file storage object to give its root storage access to the physical device, while isolating the root storage from the details of accessing the physical storage.
At a Glance
Header file: | Objbase.h |
Windows CE versions: | 2.0 and later |
When to Implement
Most applications will not implement the ILockBytes interface because COM provides implementations for one of the most common situations:
File-based implementation—If you call StgCreateDocfile function to create a compound file storage object, it contains an implementation of ILockBytes that is associated with a byte array stored in a physical disk file. The compound file storage object calls the ILockBytes methods—you do not call them directly in this implementation.
There are situations in which it would be useful for an application to provide its own ILockBytes implementation. For example, a database application could implement ILockBytes to create a byte array object backed by the storage of its relational tables. However, it is strongly recommended that you use the COM-provided implementations. For a discussion of the advantages of using the COM implementations rather than creating your own, see the StgCreateDocfileOnILockBytes API function, which creates a compound file storage object on top of a caller-provided byte array object.
When to Use
The ILockBytes methods are called by the COM implementations of IStorage and IStream on the compound file object. Unless you are implementing IStorage and IStream, you would not need to call ILockBytes methods directly. If you write your own ILockBytes implementation, you can use the StgCreateDocfileOnILockBytes function to create a compound file storage object backed by your implementation of ILockBytes.
Method | Description |
ILockBytes::Flush | Ensures that any internal buffers maintained by the byte array object are written out to the backing storage. |
ILockBytes::LockRegion | Restricts access to a specified range of bytes in the array. |
ILockBytes::ReadAt | Reads a specified number of bytes starting at a specified offset from the beginning of the array. |
ILockBytes::SetSize | Changes the size of the byte array. |
ILockBytes::Stat | Retrieves a STATSTG structure for this byte array object. |
ILockBytes::UnlockRegion | Removes the access restriction on a range of bytes previously restricted with ILockBytes::LocRegion. |
ILockBytes::WriteAt | Writes a specified number of bytes to a specified location in the array. |