page faults trying to get printer settings from two printers 
Author Message
 page faults trying to get printer settings from two printers

I've been playing around with getting printer settings with VB5, but I keep
getting Page faults after I try to get the settings from one printer and
then another printer. Everything works fine on the first printer, its only
when I try to get the settings of a different printer after the first
printer. I do not get the page faults if I try to get the settings for the
same printer twice though.  I have been using the example for MSKB article
Q190218 except I added a list box the would list all my printers. I would
then be able to get the settings for the printer that I have choosen in the
list box.

My 'GetPrinterSettings' procedure is exactly as layed out in the MSKB
article, including the close printer command at the end.

if you can fill me in on as to why I am getting the page faults, I would
greatly appreciate it.

Thanks,

Clay

*************************************************************************
*** on command1_click, I get the settings for the printer that I  ***
*** have selected in the list box
***

Private Sub Command1_Click()
Dim index As Integer
    index = Me.Combo1.ListIndex
    If GetPrinterSettings(Printers(index).DeviceName, Printers(index).hdc) =
False Then
        List1.AddItem "No Settings Retrieved!"
        MsgBox "Unable to retrieve Printer settings.", , "Failure"
    End If
End Sub

**************************************************************************

***************************************************************
*** on form_load i fill the list box with a list of printers ***

Private Sub Form_Load()
Dim iCount As Integer
    For iCount = 0 To Printers.Count - 1
        Me.Combo1.AddItem Printers(iCount).DeviceName
    Next iCount
    Me.Combo1.Text = Me.Combo1.List(0)
End Sub

*******************************************************

**********************************************************************
*** here are the page faults that I recieve,
***
*** after trying to receive the settings two a second printer  ***

VB5 caused an invalid page fault in
module OLEAUT32.DLL at 0177:7feb1c47.

VB5 caused an invalid page fault in
module OLEAUT32.DLL at 0177:7feb181c.

**************************************************

**********************************************************************
*** get printer settings as stated in MSKB article Q190218 ***

Private Function GetPrinterSettings(szPrinterName As String, hdc As Long) As
Boolean
Dim hPrinter As Long
Dim nSize As Long
Dim pDevMode As DEVMODE
Dim aDevMode() As Byte
Dim TempStr As String
    If OpenPrinter(szPrinterName, hPrinter, NULLPTR) Then
        nSize = DocumentProperties(NULLPTR, hPrinter, szPrinterName,
NULLPTR, NULLPTR, 0)
        ReDim aDevMode(1 To nSize)
        nSize = DocumentProperties(NULLPTR, hPrinter, szPrinterName,
aDevMode(1), NULLPTR, DM_OUT_BUFFER)
        Call CopyMemory(pDevMode, aDevMode(1), Len(pDevMode))
        List1.Clear ' empty the ListBox
        List1.AddItem "Printer Name: " & ByteToString(pDevMode.dmDeviceName)
        If pDevMode.dmOrientation = DMORIENT_PORTRAIT Then
            TempStr = "PORTRAIT"
        ElseIf pDevMode.dmOrientation = DMORIENT_LANDSCAPE Then
            TempStr = "LANDSCAPE"
        Else
            TempStr = "UNDEFINED"
        End If
        List1.AddItem "Orientation: " & TempStr
        Select Case pDevMode.dmPrintQuality
            Case DMRES_DRAFT
                TempStr = "DRAFT"
            Case DMRES_HIGH
                TempStr = "HIGH"
            Case DMRES_LOW
                TempStr = "LOW"
            Case DMRES_MEDIUM
                TempStr = "MEDIUM"
            Case Else ' positive value
                TempStr = CStr(pDevMode.dmPrintQuality) & " dpi"
        End Select
        List1.AddItem "Print Quality: " & TempStr
        Select Case pDevMode.dmTTOption
            Case DMTT_BITMAP ' default for dot-matrix printers
                TempStr = "TrueType fonts as graphics"
            Case DMTT_DOWNLOAD ' default for HP printers that use PCL
                TempStr = "Downloads TrueType fonts as soft fonts"
            Case DMTT_SUBDEV ' default for postscript printers
                TempStr = "Substitute device fonts for TrueType fonts"
            Case Else
                TempStr = "UNDEFINED"
        End Select
        List1.AddItem "TrueType Option: " & TempStr ' Windows NT drivers
often return COLOR from Monochrome printers
        If pDevMode.dmColor = DMCOLOR_MONOCHROME Then
            TempStr = "MONOCHROME"
        ElseIf pDevMode.dmColor = DMCOLOR_COLOR Then
            TempStr = "COLOR"
        Else
            TempStr = "UNDEFINED"
        End If
        List1.AddItem "Color or Monochrome: " & TempStr
        If pDevMode.dmScale = 0 Then
            TempStr = "NONE"
        Else
            TempStr = CStr(pDevMode.dmScale)
        End If
        List1.AddItem "Scale Factor: " & TempStr
        List1.AddItem "Y Resolution: " & pDevMode.dmYResolution & " dpi"
        List1.AddItem "Copies: " & CStr(pDevMode.dmCopies) ' Add any other
items of interest ...
        Call ClosePrinter(hPrinter)
        GetPrinterSettings = True
    Else
        GetPrinterSettings = False
    End If
End Function

****************************************************************************
****



Sat, 16 Jun 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Getting the printer settings without initialising the printer?

2. Getting two columns on printer object

3. Changing Printers (was Re: Getz code error/setting printer info)

4. Problem setting the active printer of Word 97 without changing the Windows default printer

5. A HOW-TO: Setting Printer fonts: WAS Printer fonts

6. Printer Dialog sets System Wide Printer settings....

7. Printer Dialog sets System Wide Printer settings....

8. Changing the printer capture and setting printer driver

9. Q: Forcing Printer Paper bins / Getting List Per Printer

10. Printer Object - Getting the available printer information

11. Getting default printer name from Printers Collection

12. Getting Raw Printer Data To The Printer

 

 
Powered by phpBB® Forum Software