Question How to set the printer form NOT print document

dlw@pickpro.com

New member
Joined
May 13, 2008
Messages
3
Location
St. Louis area
Programming Experience
10+
Been trying to set a printers form (page size).
Got to the winspool.drv library, SetForm API... without luck.

I'm looking to set the default form (IE: Letter, legal, "Us Std Fanfold" etc)
I do not want to add/remove the form from the printer. Just assign an existing form, not knowing the dimentions etc.

I've written code to itterate through the available forms, however the list consistantly comes up empty. The initial call to the Enumerate Forms API is supposed to return the number of forms and the "bytes needed". These are both zero.

I suspect my API definition may be at fault, or perhaps the way I'm passing my structure pointers to the API. Most doc I've red refer to pForm as type "Any" - this is as close as i could find.

(NOTE: the only reason i itterate through the forms is to have the metrics pre-defined, avoiding hard-coding. If there is a better way, i'm all ears)


Public Declare Function APIEnumForms Lib "winspool.drv" Alias "EnumFormsA" ( _
ByVal hPrinter As Long, _
ByVal Level As Long, _
<System.Runtime.InteropServices.MarshalAsAttribute( _
System.Runtime.InteropServices.UnmanagedType.AsAny)> _
ByVal pForm As Object, _
ByVal cbBuf As Long, _
ByVal pcbNeeded As Long, _
ByVal pcReturned As Long) As Long

--- then the actual call:

If Me.OpenPrinter(True) = False Then ' True = Admin permissions
OnInfo("Could not open printer '{0}'", Me.PrinterName)
Exit Sub
End If
ReDim aFI1(0) ' array of type FORM_INFO_1
RetVal = WINAPI.APIEnumForms(m_PrinterHndl, 1, 0&, 0&, BytesNeeded, NumForms)
' at this point, BytesNeeded & NumForms are both Zero
ReDim Temp(BytesNeeded)
ReDim aFI1(BytesNeeded / Len(FI1))
' Second call actually enumerates the supported forms.
RetVal = WINAPI.APIEnumForms(m_PrinterHndl, 1, 0&, BytesNeeded, BytesNeeded, NumForms)
Call WINAPI.APICopyMemory(aFI1(0).Flags, Temp(0), BytesNeeded)

I have other API calls in the application to enumerate the print jobs for all queues - not having ANY luck on assigning the Form.
 

Latest posts

Back
Top