6

I am updating our "Printer Monitoring" application. Previously this application runs successfully on Windows 2000 server. Now we shifted to Windows 7 server. On windows 7 our "Print monitor" application crashes. When I debug it, I found that our SetJob function throws the following exception:

The parameter is incorrect.

Does anyone know anything about this?

Function call:

SetJob(
    mhPrinter,
    midJob,
    0,
    IntPtr.Zero,
    PrintJobControlCommands.JOB_CONTROL_PAUSE) 'Here exception is thrown

Spooler API which we use :

<DllImport("winspool.drv", EntryPoint:="SetJob", _

SetLastError:=True, CharSet:=CharSet.Ansi, _

ExactSpelling:=False, _

CallingConvention:=CallingConvention.StdCall)> _

Public Function SetJob _

(<InAttribute()> ByVal hPrinter As IntPtr, _

<InAttribute()> ByVal dwJobId As Int32, _

<InAttribute()> ByVal Level As Int32, _

<InAttribute()> ByVal lpJob As IntPtr, _

<InAttribute(), MarshalAs(UnmanagedType.U4)> ByVal dwCommand As PrintJobControlCommands _

) As Boolean
BartoszKP
  • 34,786
  • 15
  • 102
  • 130
Ashutosh
  • 71
  • 1
  • 5
  • That API call has not changed on Windows7. That exception generally means that you either have an invalid JobId, or that the JobId is not associated with that Printer handle. From windows Vista onwards MS introduced Client Side Rendering (CSR) to improve printing efficiency, this can have the appearance of jobs running through the spooler multiple times, maybe there is some other bug in your code somewhere else causing a mismatch. – BBoy Jun 30 '11 at 22:33
  • 1
    When you say "Windows 7 Server" can we assume you mean "Windows Server 2008 R2"? I'm assuming based on the tag. – Tory Netherton May 10 '12 at 18:54
  • 1
    Do you get any entries in the event log that provide event ids? – Tory Netherton May 10 '12 at 19:00

1 Answers1

0

Please have a loop here, how the function has to be build and how the parsmeters are called:

http://www.pinvoke.net/default.aspx/winspool.setjob

It is a bit different then you implemented it. Hope it will help.

etalon11
  • 895
  • 2
  • 13
  • 36