Tony Edgecombe

RawPrint on Nuget

28 Jan 2015

As part of my work on the next version of Print Distributor I am planning to pull out several parts as open source projects. The first is a .Net assembly that allows you to send raw print files directly to a printer bypassing the printer driver.

The package is on Nuget and the source is on GitHub.

Raw printing in Windows 8

10 Sep 2012

With the introduction of V4 drivers in Windows 8 and Server 2012 Microsoft has taken another step down the road of making everything print related based on XPS. One of the issues this created in several of my programs is raw printing stopped working for printers using V4 drivers.

It appears (although I haven't tested this thoroughly) that if you try and send a document directly to the printer using the established methods Windows treats it as an XPS document. If it is then everything is fine, if not then it drops into a black hole.

Fortunately there is a new data type you can specify "XPS_PASS" which will bypass the driver and send your output directly to the printer, more details on this on MSDN.

To be able to print to both V4 and earlier printers you will need to test for the driver version, this code will flag whether you have a version 4 driver or not.

bool IsV4Driver(wchar_t* printerName)
    HANDLE handle;
    PRINTER_DEFAULTS defaults;

    defaults.DesiredAccess = PRINTER_ACCESS_USE;
    defaults.pDatatype = L"RAW";
    defaults.pDevMode = NULL;

    if (::OpenPrinter(printerName, &handle, &defaults) == 0)
        return false;

    DWORD version = GetVersion(handle);


    return version == 4;

DWORD GetVersion(HANDLE handle)
    DWORD needed;

    ::GetPrinterDriver(handle, NULL, 2, NULL, 0, &needed);
    if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER)
        return -1;

    std::vector<char> buffer(needed);
    if (::GetPrinterDriver(handle, NULL, 2, (LPBYTE) &buffer[0], needed, &needed) == 0)
        return -1;

    return ((DRIVER_INFO_2*) &buffer[0])->cVersion;

Folder Agent

11 May 2012

This week I released my latest project, Folder Agent. It is a Windows application that monitors a folder or directory for new and modified files. It then lets you run actions against that modified file such as copying, moving, emailing or deleting the file. You can also run an external program or script against the file.

There is a template system that lets you build paths and properties dynamically, so you could move files to a folder structure based on the date for instance.

I've been thinking about writing something along these lines for a long time, in fact I first registered the domain in 2005 but was never really satisified with my first few attempts. This time I started by focussing on the core functionality rather than the user interface and the whole thing has come together quickly, in fact from start to finish was only three months.

Deinterleave XPS files

28 Jan 2012

XPS files have a nice feature called interleaving.

When a printer receives an XPS file it needs to receive any resources such as fonts or images before those resources are used on a page. The way this is handled is items are split into parts, so the first part of the page is spooled then it may be followed by a font then more of the page followed by an image and so on.

This is effective for the creator and consumer software but it does make the files difficult to navigate manually.

To work around this I wrote a small utility to deinterleave an XPS file.

Xcode Linking

24 Dec 2010

I've just started a cross platform project in Xcode and one of the problems I came across is it doesn't seem possible to link to different libraries depending on whether you are building the Debug or Release configuration.

I did find an old message on the Apple developer forums that indicates you can do this with dependent projects, the trouble with this is when you clean your target all the dependent projects will clean as well.

In the end I did find a method that works for my project. The trick is to add a "Library Search Path" with the BUILD_STYLE environment variable:


The $(BUILD_STYLE) macro gets expanded to Debug or Release depending on which configuration I am using, I just need to make sure the libraries are created in the appropriate folders.

I can then add the libraries using the setting "Other linker flags" with the -l option:

-l mylibraryname

Not as nice as the Visual Studio solution but it does seem to work.