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(
  [in]          IStream        *stream,
  [in]          OPC_READ_FLAGS flags,
  [out, retval] IOpcPackage    **package


stream [in]

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.

flags [in]

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

package [out, retval]

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 codeDescription

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.


Minimum supported client

Windows 7 [desktop apps only]

Minimum supported server

Windows Server 2008 R2 [desktop apps only]





See also

Loading a Package
Getting Started with the Packaging API
Packaging API Programming Guide
Platform Update for Windows Vista
Packaging Errors
Packaging API Reference
Packaging API Samples



Community Additions