IOpcFactory::ReadPackageFromStream method

Deserializes package data from a stream and creates a package object to represent the package being read. While a Packaging API object obtained from the package object, or the package object itself, is still in use, the stream may be used to access package data.


HRESULT ReadPackageFromStream(
  IStream        *stream,
  IOpcPackage    **package



A pointer to the IStream interface of the stream.

The stream must be readable, seekable, have size, and must contain package data. Additionally, if the stream is not clonable, it will be buffered and read sequentially, incurring overhead.


The value that specifies the read settings for caching package components and validating them against OPC conformance requirements.


A pointer to the IOpcPackage interface of the package object that represents the package being read through the stream.

Return Value

The method returns an HRESULT. Possible values include, but are not limited to, those in the following table.

Return code Description
The method succeeded.
The value passed in the flags parameter is not a valid OPC_READ_FLAGS enumeration value.
This method is not implemented for this version of Windows.
At least one of the stream and package parameters is NULL.
IStream interface error
An HRESULT error code from the IStream interface.
Package Consumption error
An HRESULT error code from the Package Consumption Error Group.
Part URI error
An HRESULT error code from the Part URI Error Group.


Do not use a stream to serialize package data when the same stream is being used to deserialize a package, because the attempt may result in undefined behavior.

The Packaging APIs can interact with packages that map a ZIP archive as specified in the OPC, and that are based on either Zip32 (ZIP 2.0) or Zip64 (ZIP 4.5) encoding.

For information about how to use this method to load a package, see the Loading a Package programming task.

Support on Previous Versions of Windows

This method is not supported on versions of Windows prior to Windows 7. For more information, see Getting Started with the Packaging API, and Platform Update for Windows Vista.

Thread Safety

Packaging objects are not thread-safe.

For more information, see the Getting Started with the Packaging API.


Windows version Windows 7 [desktop apps only] Windows Server 2008 R2 [desktop apps only]
Target Platform Windows
Header msopc.h

See Also

Getting Started with the Packaging API


Loading a Package



Packaging API Programming Guide

Packaging API Reference

Packaging API Samples

Packaging Errors

Platform Update for Windows Vista