1

I'm trying to call the GetJob() method documented here. I think I'm having problems with the syntax of the routine right now, both calling and defining. I've finally got something to compile which is the following.

[DllImport(
    "winspool.drv",
    EntryPoint = "GetJob",
    SetLastError = true,
    CharSet = CharSet.Ansi,
    ExactSpelling = true,
    CallingConvention = CallingConvention.StdCall)]
private static extern bool GetJob
    ([InAttribute()] IntPtr hPrinter,
    [InAttribute()] Int32 JobId,
    [InAttribute()] Int32 Level,
    [OutAttribute()] out byte[] pJob,
    [InAttribute()] Int32 cbBuf,
    [OutAttribute()] out Int32 pcbNeeded);

    ...
    ...
    ...
    ...

const int BUFFER_SIZE = 250;
int pcbNeeed = 0;

unsafe
{
    byte[] byteBuffer = new byte[BUFFER_SIZE];

    bResult = GetJob(m_PrinterHandle, jobID, 1, out byteBuffer, BUFFER_SIZE, out pcbNeeed);

}

According to the documentation here, it seems I should be able to use a byte[] without any special marshaling code because it is "blittable". In anycase, I get a runtime exception that says:

Unable to find an entry point named 'GetJob' in DLL 'winspool.drv'. at NQBB.Printer.PrintQueueMonitor.PrinterWatcher.GetJob(IntPtr hPrinter, Int32 JobId, Int32 Level, Byte[]& pJob, Int32 cbBuf, Int32& pcbNeeded)

I think I just have some syntax wrong here. Can anyone see the problem?

i_am_jorf
  • 53,608
  • 15
  • 131
  • 222
Ultratrunks
  • 2,464
  • 5
  • 28
  • 48
  • 2
    Note this section in the documentation: "GetJobW (Unicode) and GetJobA (ANSI)". Your use of `ExactSpelling = true` tells dllimport not to append the A. P.S., you'll find people are more willing to help if you don't insult them. – Raymond Chen Sep 12 '11 at 19:55
  • 1
    Please stop using the term M$ it's really not funny or clever. – David Heffernan Sep 12 '11 at 20:09

2 Answers2

2

Stop using ExactSpelling and then you will link to GetJobA or GetJobW as appropriate.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
1

Try setting EntryPoint to "GetJobA". GetJob is not actually in the winspool export list...

Brad
  • 529
  • 4
  • 8
  • Wow, that really ticks me off how much time I spent banging my head trying to figure out what I did wrong. >:-< But thank you. – Ultratrunks Sep 12 '11 at 20:12