borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Visual Basic versus VB.Net)Next Topic (Free VB.net EBook) New Topic New Poll Post Reply
AndreaVB Forum : VB.Net : FindnextPrinterChangeNotification interop problem
Poster Message
Merrion
Level: VB Guru

Registered: 15-04-2002
Posts: 37

icon FindnextPrinterChangeNotification interop problem

I have declared the PrinterNotifyInfo structure that it wants in as a class thus:


Imports System.Runtime.InteropServices


<StructLayout(LayoutKind.Explicit)> _
Public Class PrinterNotifyOptions
    <FieldOffset(0)> Public dwVersion As Integer
    <FieldOffset(4)> Public dwFlags As Integer
    <FieldOffset(8)> Public Count As Integer
    '\ --JOB_NOTIFY_OPTIONS_TYPE
    <FieldOffset(12)> Public wType As Int16
    <FieldOffset(14)> Public wReserved0 As Int16
    <FieldOffset(16)> Public dwReserved1 As Int32
    <FieldOffset(20)> Public dwReserved2 As Int32
    <FieldOffset(24)> Public FieldCount As Int32
    <FieldOffset(28)> Public pFields As IntPtr

#Region "Public Enumerated Types"
    Public Enum Printer_Notification_Types
        PRINTER_NOTIFY_TYPE = &H0
        JOB_NOTIFY_TYPE = &H1
    End Enum

    Public Enum Printer_Notify_Field_Indexes
        PRINTER_NOTIFY_FIELD_SERVER_NAME = &H0
        PRINTER_NOTIFY_FIELD_PRINTER_NAME = &H1
        PRINTER_NOTIFY_FIELD_SHARE_NAME = &H2
        PRINTER_NOTIFY_FIELD_PORT_NAME = &H3
        PRINTER_NOTIFY_FIELD_DRIVER_NAME = &H4
        PRINTER_NOTIFY_FIELD_COMMENT = &H5
        PRINTER_NOTIFY_FIELD_LOCATION = &H6
        PRINTER_NOTIFY_FIELD_DEVMODE = &H7
        PRINTER_NOTIFY_FIELD_SEPFILE = &H8
        PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR = &H9
        PRINTER_NOTIFY_FIELD_PARAMETERS = &HA
        PRINTER_NOTIFY_FIELD_DATATYPE = &HB
        PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR = &HC
        PRINTER_NOTIFY_FIELD_ATTRIBUTES = &HD
        PRINTER_NOTIFY_FIELD_PRIORITY = &HE
        PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY = &HF
        PRINTER_NOTIFY_FIELD_START_TIME = &H10
        PRINTER_NOTIFY_FIELD_UNTIL_TIME = &H11
        PRINTER_NOTIFY_FIELD_STATUS = &H12
        PRINTER_NOTIFY_FIELD_STATUS_STRING = &H13
        PRINTER_NOTIFY_FIELD_CJOBS = &H14
        PRINTER_NOTIFY_FIELD_AVERAGE_PPM = &H15
        PRINTER_NOTIFY_FIELD_TOTAL_PAGES = &H16
        PRINTER_NOTIFY_FIELD_PAGES_PRINTED = &H17
        PRINTER_NOTIFY_FIELD_TOTAL_BYTES = &H18
        PRINTER_NOTIFY_FIELD_BYTES_PRINTED = &H19
        PRINTER_NOTIFY_FIELD_OBJECT_GUID = &H1A
    End Enum

    Public Enum Job_Notify_Field_Indexes
        JOB_NOTIFY_FIELD_PRINTER_NAME = &H0
        JOB_NOTIFY_FIELD_MACHINE_NAME = &H1
        JOB_NOTIFY_FIELD_PORT_NAME = &H2
        JOB_NOTIFY_FIELD_USER_NAME = &H3
        JOB_NOTIFY_FIELD_NOTIFY_NAME = &H4
        JOB_NOTIFY_FIELD_DATATYPE = &H5
        JOB_NOTIFY_FIELD_PRINT_PROCESSOR = &H6
        JOB_NOTIFY_FIELD_PARAMETERS = &H7
        JOB_NOTIFY_FIELD_DRIVER_NAME = &H8
        JOB_NOTIFY_FIELD_DEVMODE = &H9
        JOB_NOTIFY_FIELD_STATUS = &HA
        JOB_NOTIFY_FIELD_STATUS_STRING = &HB
        JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR = &HC
        JOB_NOTIFY_FIELD_DOCUMENT = &HD
        JOB_NOTIFY_FIELD_PRIORITY = &HE
        JOB_NOTIFY_FIELD_POSITION = &HF
        JOB_NOTIFY_FIELD_SUBMITTED = &H10
        JOB_NOTIFY_FIELD_START_TIME = &H11
        JOB_NOTIFY_FIELD_UNTIL_TIME = &H12
        JOB_NOTIFY_FIELD_TIME = &H13
        JOB_NOTIFY_FIELD_TOTAL_PAGES = &H14
        JOB_NOTIFY_FIELD_PAGES_PRINTED = &H15
        JOB_NOTIFY_FIELD_TOTAL_BYTES = &H16
        JOB_NOTIFY_FIELD_BYTES_PRINTED = &H17
    End Enum

#End Region

    Public Sub New()


        '\ As it stands, version is always 2
        dwVersion = 2
        '\ We must have at least one notification - status makes sense to test with...
        'NotifyJobStatus = True
        FieldCount = 1
        Dim pfld1 As Short = Job_Notify_Field_Indexes.JOB_NOTIFY_FIELD_STATUS

        '\ Use pointer to array per your suggestion...
        pFields = Marshal.AllocHGlobal(2)
        Marshal.WriteInt16(pFields, 0, pfld1)

    End Sub

End Class


And when I pass it to FindFirstPrinterChangeNotification it goes OK but when a print job occurs and the wait object triggers I have to call FindNextPrinterChangeNotification to get the info that has changed which I have declared thus:-

<DllImport("winspool.drv", EntryPoint:="FindNextPrinterChangeNotification", _
    SetLastError:=True, CharSet:=CharSet.Ansi, _
    ExactSpelling:=True, _
    CallingConvention:=CallingConvention.StdCall)> _
    Public Shared Function FindNextPrinterChangeNotification _
                            (<InAttribute()> ByVal hChangeObject As IntPtr, _
                             <OutAttribute()> ByRef pdwChange As IntPtr, _
                             <InAttribute()> ByVal pPrinterNotifyOptions As PrinterNotifyOptions, _
                             <OutAttribute()> ByRef lppPrinterNotifyInfo As IntPtr _
                                 ) As Boolean

    End Function


Now when this is called the variable pdwChange is filled with the correct value to indicate what has changed but lppPrinterNotifyInfo is never non-zero.

Any thoughts at all?

Thanks in advance,
Duncan

____________________________
--8<------------------------------
Free components and source code - see http://www.merrioncomputing.com/Download/index.htm for details

27-11-2002 at 01:29 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : VB.Net : FindnextPrinterChangeNotification interop problem
Previous Topic (Visual Basic versus VB.Net)Next Topic (Free VB.net EBook) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder