Hello,

welcome to my blog of various technical solutions, experiences and tutorials.

Please feel free to use the Archive menu to go through my articles.

Tuesday, January 24, 2012

1. Building and using XPSDrvSmpl under Windows XP

Microsoft Windows Driver Developer Kit (DDK/WDK) comes with a sample of XPS print driver. This post will tell you what to do to build it and use it under WinXP.

(XPS print path isn't supported in standard Windows XP, you need to have either SP3 with .Net3.0, MS XPS Essentials Pack or this MS hotfix installed in order to use it. We will assume that you have this done)

Having WDK downloaded (for free) and installed, you should find this sample at [WDK root]\[WDK version]\src\print\XPSDrvSmpl folder (e.g. c:\WinDDK\7600.16385.1\src\print\XPSDrvSmpl). Further you should see some records in your Start menu under Programs/Windows Driver Kits. This folder and its content is important, as it provides building environments for various MS operating systems (XPSDrvSmpl must be built using at least Vista build environment, as it is not supported in XP and trying to build the sample using XP build environment will result in lot of errors and no output libraries).

So let's start:
  1. Go to Start - Programs - Windows Driver Kits - WDK [version number] - Build environments and choose Windows Vistaand Windows Server 2008 - x86 checked environment (the checked environment should provide more information at output when errors occur; it's something like Debug/Release configuration in MSVC). A console should start.
  2. If you have copied the XPS sample to a custom directory, use cd command to go there (e.g. cd c:\projects\xpsdrvsmpl). From now on I will call this directory a sample root.
  3. Type build -cZ and hit Enter. After few moments the build should end successfully (without any error and warning) telling you the count of files compiled and libraries and executables built. Now your new dll output files are located in [sample root]\install\x86 directory.
  4. We can now proceed to new XPS printer installation.
    Go to Start - Control Panel - Add new printer. Then choose Local printer and Create new port. Select Local Port in combo box. The dialog asking for a port name will appear. For our XPS driver to print to specified file without asking a user for a location, write in full path for this output file. This file need not to exist at the moment (something like c:\mydriveroutput.xps for example).
  5. Now when you see the list of vendors and devices, click the "From disk" button. Then select [sample root]\install\xdsmpl.inf and click Next. This will load the printer installing instructions.
  6. As you go on, the wizard can ask you for some files it cannot find. But this should be no big trouble if you have SP3 or XPS Extension Pack installed.
    If the wizard asks you for xdsmpl.gpd, click Browse and find this file in [sample root]\install\x86.
    If it asks for xdwmark.dll, navigate to [sample root]\install\x86 as well.
    For msxpsinc.gpd go to c:\windows\Driver cache\i386.
    The xpssvcs.dll file should be found in c:\windows\system32.
  7. And that's it. The printer driver should now be installed and ready to use. Now go to any of your favourite application and under File - Print menu choose XPSDrv Sample Driver. The output XPS file is the one you provided aas the port name at the beginning of printer installation (e.g. c:\mydriveroutput.xps)

6 comments:

  1. I am trying to install the printer, it copies all the files, but at the end, I get "Unable to Install Printer. Operation could not be completed". Do you have any ideea how can I pass this?
    Thanks

    ReplyDelete
    Replies
    1. Hi Andrei, sorry for my late response. The error looks quite general and it's been more than half a year since I was dealing with XPS, thus I'm afraid I will not be of much help here :/
      At least make sure you use the right compiler for your OS (x86 for Win32 and x64 for Win64) and also that you provide all necessary files for the installer (according to INF file).
      I wish you good luck with this. Should you find the solution, feel free to share your knowledge ;)

      Delete
    2. hi, I guess i am way too late to the party, but I am trying out this same method of building sample XPS driver to be able to run on XP. I am stuck at the same error as pointed by you viz. "Unable to Install Printer. Operation could not be completed". Did you find any solution to that? I am guessing my issue is cuz I am using WDK10 (2017 people, I know its too late to try this) and VS2015 for compilation. I guess I should instead use some wdk version which is compatible to windows XP?? Let me know if you can still read this and can guide me to anything relevant. :)
      Thanks!

      Delete
    3. Hi, Nirvantosh and thanks for your question, here's what comes to my mind.
      Please check the Build Environment mentioned in step 1 - if I am not mistaken (can't verify it at the moment) there should be an extra one just for XP, so try to use that.
      If it is not there (could have been removed by Microsoft in WDK 10), try to download an older WDK (6 or 7).
      Hope my answer helps you. Have a nice day! :-)

      Delete
    4. Hi kibitzer,

      Indeed that was the issue, wdk 10 wont build drivers to run on XP. I installed wdk 7.1 on a separate machine and build the driver and it worked perfectly fine. Thanks a lot. Your blog helped a lot.

      P.S. - I found the steps need a little correction for anyone who is trying this still (at least in my case it did). While building the driver with wdk 7.1, after choosing the build environment, do not do 'build -cZ', that will not build the driver as the sample contained by this wdk does not have 'dirs' file which helps build utility to scan and compile directories and sub-directories.
      On reading wdk 7.1 manual's 'building driver' section, I came to know about three files viz sources, makefile and dirs which are necessary for build utility to build driver; although it states dirs as optional, my driver built only after making this dirs file; you can use the same manual to see how to make dirs file which is easy as shit using the available utility makedirs)
      - once you use makedirs utility to create dirs file (sources and makefile is already present in each dir available), afterwards go ahead with 'build -cZ'
      - once driver is built, follow blog instructions further

      Hope if someone still going to do this and using wdk 7.1, it will help him/her. :)

      Thanks again.:)

      Delete
  2. Very useful article. I have been looking for a way to suppress the save as dialog that pops up when printing to xps printers. Your article gave me a solution in one line. Thank you! Keep up the good work..

    ReplyDelete