I have got a problem with my implementation of the PXCComLib6.IStream interface (see below). I want it to read/write to the file.
Code: Select all
public class PrinterStream : PXCComLib6.IStream
{
private System.IO.Stream stream;
public PrinterStream( System.IO.Stream stream )
{
this.stream = stream;
}
public void Clone( out IStream ppstm )
{
ppstm = null;
}
public void Commit( uint grfCommitFlags )
{
}
public void LockRegion( _ULARGE_INTEGER libOffset, _ULARGE_INTEGER cb, uint dwLockType )
{
}
public void RemoteCopyTo( IStream pstm, _ULARGE_INTEGER cb, out _ULARGE_INTEGER pcbRead, out _ULARGE_INTEGER pcbWritten )
{
pcbRead = new _ULARGE_INTEGER() { QuadPart = 0 };
pcbWritten = new _ULARGE_INTEGER() { QuadPart = 0 };
}
public void RemoteRead( out byte pv, uint cb, out uint pcbRead )
{
int byteRead = this.stream.ReadByte();
if ( byteRead != -1 )
{
pv = (byte)byteRead;
pcbRead = cb;
}
else
{
pv = new byte();
pcbRead = 0;
}
}
public void RemoteSeek( _LARGE_INTEGER dlibMove, uint dwOrigin, out _ULARGE_INTEGER plibNewPosition )
{
long seek = this.stream.Seek( dlibMove.QuadPart, (System.IO.SeekOrigin)dwOrigin );
plibNewPosition = new _ULARGE_INTEGER() { QuadPart = (ulong)seek };
}
public void RemoteWrite( ref byte pv, uint cb, out uint pcbWritten )
{
this.stream.WriteByte( pv );
pcbWritten = cb;
}
public void Revert()
{
}
public void SetSize( _ULARGE_INTEGER libNewSize )
{
}
public void Stat( out tagSTATSTG pstatstg, uint grfStatFlag )
{
pstatstg = new tagSTATSTG()
{
cbSize = new _ULARGE_INTEGER() { QuadPart = 1 }
};
}
public void UnlockRegion( _ULARGE_INTEGER libOffset, _ULARGE_INTEGER cb, uint dwLockType )
{
}
}
Code: Select all
FileStream fStream = null;
try
{
fStream = new FileStream( name, FileMode.Create );
PrinterStream pStream = new PrinterStream( fStream );
this.PDFPrinter.StorePrinterOptions( pStream );
return true;
}
catch ( Exception ex )
{
return false;
}
finally
{
if ( fStream != null )
fStream.Close();
}
Best regards,
Igor Paszewski