As Sebastian has said, the easiest way is to set the compression to B44 in the output header.
Although if all your wanting to do is playback a sequence of dpxs then why not use an application such as djv_view?
Files:
The B44 gubbins - ./openexr-1.6.1/IlmImf/ImfB44Compressor.cpp
Writing out a scanline image - ./openexr-1.6.1/IlmImf/ImfOutputFile.cpp
Example compression tests - ./openexr-1.6.1/IlmImfTest/testCompression.cpp
create an output file and set the header on it.
create a frame buffer, and dump your pixel data into it. At this point none of the pixel data is compressed.
set the frame buffer onto your output file and call writepixels/tiles
The write method goes off and retrieves the compression you wanted from the header, it then takes pixel data for the range you specified in your write call from the frame buffer and copies it into a number of tile/line buffers.
As each line buffer is created, a compressor object is created for it.
Once a line buffer is full, if compression has been set, then a pointer to the compressor object is retrieved and the line buffer contents is compressed.
The compressed linebuffer is then written out to disk.