Page 1 of 1

Problem with storing printer options

Posted: Mon Jun 13, 2016 11:58 am
by igor_p
Hi,

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 )
    {
    }
}
Everytime I call StorePrinterOptions, the file created seems to be incomplete. Please, look at attachment.
printingoptions.zip
(175 Bytes) Downloaded 87 times
Below is my code which initializes Stream and calls StorePrinterOptions:

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();
}
I didn't find any documentation or sample implementation of the IStream interface. Can you, please, help me with finding what am I doing wrong? Some code samples would be also appreciated.

Best regards,
Igor Paszewski

Re: Problem with storing printer options

Posted: Thu Jul 07, 2016 1:57 pm
by Ivan - Tracker Software
There is no PXCComLib6.IStream. The Method for saving/restoring a printer's options requires standard windows IStream interface: https://msdn.microsoft.com/en-us/librar ... s.85).aspx

So, you have to implement an IStream interface which encapsulates working with your storage, for example file or C# Stream object. As an example of such an implementation you can take a look at http://hl7connect.blogspot.ca/2010/04/c ... tream.html

HTH