Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8203613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:37:05+00:00 2026-06-07T07:37:05+00:00

We have some print server software written in C# (which P/Invokes functions from winspool.drv).

  • 0

We have some print server software written in C# (which P/Invokes functions from winspool.drv). Some of the “printers” are actually virtual printers that print to a directory. The code to install such a printer is:

public override void AddLocalDirectoryPrinter(string printerName, string directory)
{
    IntPtr hPrinter = IntPtr.Zero;

    try
    {
        PRINTER_DEFAULTS pd;
        PRINTER_INFO_2 pi2;

        pd.datatype = null;
        pd.pDevMode = IntPtr.Zero;
        // Access = PRINTER_ALL_ACCESS
        // http://msdn.microsoft.com/en-us/library/cc244650%28v=prot.10%29.aspx
        pd.desiredAccess = PRINTER_ALL_ACCESS;

        // Attributes = PUBLISHED | DO_COMPLETE_FIRST | SHARED
        // http://msdn.microsoft.com/en-us/library/aa394363%28v=vs.85%29.aspx
        pi2.attributes = 0x2208;
        pi2.averagePpm = 0;
        pi2.jobs = 0;
        pi2.defaultPriority = 0;
        pi2.comment = "Auto-Generated by [name of program]";
        pi2.datatype = "RAW";
        pi2.pDevMode = IntPtr.Zero;
        pi2.driverName = "Generic / Text Only";
        pi2.location = string.Empty;
        pi2.parameters = string.Empty;
        pi2.portName = directory;
        pi2.printerName = printerName.ToUpperInvariant();
        pi2.printProcessor = "WinPrint";
        pi2.priority = 0;
        pi2.pSecurityDescriptor = IntPtr.Zero;
        pi2.sepFile = string.Empty;
        pi2.serverName = string.Empty;
        pi2.shareName = printerName.ToUpperInvariant();
        pi2.startTime = 0;
        pi2.status = 0;
        pi2.untilTime = 0;

        hPrinter = AddPrinter(null, 2, ref pi2);

        if (hPrinter == IntPtr.Zero)
        {
            throw new Win32Exception(Marshal.GetLastWin32Error());
        }
    }
    catch (Exception ex)
    {
        throw new PrintingException("Failed to add printer", ex);
    }
    finally
    {
        if (hPrinter != IntPtr.Zero)
        {
            ClosePrinter(hPrinter);
        }
    }
}

On 32-bit Windows XP, the above code runs without error. But on 64-bit Windows 7, the call to AddPrinter fails with Windows error 1796 (“The specified port is unknown”).

Why does it work on one version of Windows but not another?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T07:37:07+00:00Added an answer on June 7, 2026 at 7:37 am

    It turns out that I just needed to build a 64-bit version of dirport.dll.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some folders in my server where i have several scripts which use
How to print both to Log.e/d/etc. and to System.out/err/etc.? I have some code that
I need to sort then print the result increasing and decreasing. I have some
I'm using XPreformatted to print some preformated text and I have an issue with
i have a list of posts. i want print some words of post content
So I have been doing some research into getting my UTF8 to print correctly.
So far I have managed to write some code that should print the source
I have written some Python scripts in Eclipse where at some point I have
At some point I must have moved files from one location to another using
Ok so coming in from a completely different field of software development, I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.