Problem with storing printer options

PDF-XChange Drivers API (only) V4/V5
This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-XChange Printer Drivers SDK (only) - VERSION 4 & 5 - Please use the PDF-Tools SDK Forum for Library DLL assistance.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

igor_p
User
Posts: 24
Joined: Wed Oct 02, 2013 7:18 am

Problem with storing printer options

Post 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
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
You do not have the required permissions to view the files attached to this post.
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3550
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada

Re: Problem with storing printer options

Post 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
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.