Page 6 of 7
Re: PrinterLib 1.10
Posted: Tue Apr 29, 2014 4:36 pm
by IdeasVacuum
SetPrinter_() sounds interesting though:
#PRINTER_CONTROL_PURGE: Delete all print jobs
in the printer.
Of interest:
FlushPrinter()
Another possibility would be to send printer-language instructions to the printer (PJL)
HP PJL
It seems HP have a solution for everything, including 'Personality Errors'......

Re: PrinterLib 1.10
Posted: Tue Apr 29, 2014 5:46 pm
by TI-994A
yrreti wrote:The code does work just before and when the printer just starts to become active (motors running). So I thought it worked. But once the printer starts printing, it doesn't.
Hello again yrreti, and thank you for the update. Nothing beats a QED confirmation.
IdeasVacuum wrote:SetPrinter_() sounds interesting though:
#PRINTER_CONTROL_PURGE: Delete all print jobs in the printer.
Hi IdeasVacuum. Tested
SetPrinter(...PRINTER_CONTROL_PURGE), and it yields the same results.
FlushPrinter() is not natively available in PureBasic, and I can't seem to find any information on its import declarations. But from the MSDN description, it appears to be a write function to unclog the printer's memory, and not to delete it.
HP's PJL seems promising, although proprietary and not system-based.

Re: PrinterLib 1.10
Posted: Sat May 14, 2016 10:07 pm
by akee
The help file (.chm) from the archive found at
http://www.purebasicpower.de looks empty. Does someone have a working copy?
Re: PrinterLib 1.10
Posted: Sun May 15, 2016 12:54 am
by IdeasVacuum
It's tiny, but not empty:
Printer_Lib.chm
Re: PrinterLib 1.10
Posted: Sun May 15, 2016 8:38 am
by Marc56us
After download a .chm file from internet you need to set up special security
Without that the file seem to be empty.
Right clic on it and select property and then clic unblock
Look solution here
http://stackoverflow.com/questions/1143 ... s-canceled

Re: PrinterLib 1.10
Posted: Sun May 15, 2016 10:11 am
by IdeasVacuum
Good tip about unblocking .chm files on Windows (7 and up). Note, that problem is usually only to do with the file being on a network drive.
Re: PrinterLib 1.10
Posted: Sun May 15, 2016 2:50 pm
by akee
Ahhh ok got it... Forgot to check Windows permissions. Guess if you copy to a FAT32 drive it would work too... Thanks for highlighting...
Re: PrinterLib 1.10
Posted: Wed Aug 24, 2016 1:06 am
by DeanH
Hi. I am using PrinterLib 1.10 with PureBasic 5.50 and have discovered the ipprint_PrintDlg function crashes at the GlobalSize_( statement. Windows 7. hGmem1 has a value from its previous GlobalAlloc but GlobalSize_( returns 0. If I recompile using PureBasic 5.31, it works fine. GlobalSize_ returns the size of the memory buffer.
Does anyone know of a solution?
The source code for this function is below.
Thanks.
Code: Select all
Procedure.l ipprint_PrintDlg(Window.i=0,PrinterName$="",Option1$="",Option2$="")
Protected hwnd,res,Buffersize,hGmem1,hGmem2,*DevBuffer,*DevNames,*PrinterParameters.DEVMODE,*PrinterNames.DEVNAMES
If IsWindow(Window)
hwnd=WindowID(Window)
Else
hwnd=0
EndIf
If PrinterName$=""
PrintLib_PN=ipprint_GetDefaultPrinter()
Else
PrintLib_PN=PrinterName$
EndIf
If PrintLib_PH<>0
ClosePrinter_(PrintLib_PH)
PrintLib_PH=0
EndIf
res=OpenPrinter_(PrintLib_PN,@PrintLib_PH,0)
If res
Buffersize=DocumentProperties_(0,PrintLib_PH,PrintLib_PN,0,0,0)
If Buffersize=<0
ProcedureReturn 0
EndIf
hGmem1 = GlobalAlloc_(#GMEM_MOVEABLE|#GMEM_ZEROINIT, Buffersize)
hGmem2 = GlobalAlloc_(#GMEM_MOVEABLE|#GMEM_ZEROINIT, 1024+SizeOf(DEVNAMES))
;Debug "GlobalSize_(hGmem1)="+Str(GlobalSize_(hGmem1))
;Debug "GlobalSize_(hGmem2)="+Str(GlobalSize_(hGmem2))
*DevBuffer=GlobalLock_(hGmem1);AllocateMemory(Buffersize)
*DevNames=GlobalLock_(hGmem2);AllocateMemory(1024+SizeOf(DEVNAMES))
GlobalUnlock_(hGmem1)
GlobalUnlock_(hGmem2)
DocumentProperties_(0,PrintLib_PH,@PrintLib_PN,*DevBuffer,0,#DM_OUT_BUFFER)
*PrinterParameters=*DevBuffer
*PrinterNames=*DevNames
ipprint_SetDEVMODE(Option1$,*PrinterParameters)
;PrintLibDLG.PRINTDLG
ipprint_SetPRINTDLG(Option2$,PrintLibDLG)
PrintLibDLG\lStructSize=SizeOf(PRINTDLG)
PrintLibDLG\hWndOwner=hwnd
PrintLibDLG\hDevMode=hGmem1
PrintLibDLG\hDevNames=hGmem2
PrintLibDLG\Flags|$40000
If PrintLibDLG\nCopies=0
PrintLibDLG\nCopies=1
EndIf
If PrintLibDLG\nFromPage=0
PrintLibDLG\nFromPage=1
EndIf
If PrintLibDLG\nToPage=0
PrintLibDLG\nToPage=1
EndIf
If PrintLibDLG\nMinPage=0
PrintLibDLG\nMinPage=1
EndIf
If PrintLibDLG\nMaxPage=0
PrintLibDLG\nMaxPage=1
EndIf
res=PrintDlg_(PrintLibDLG)
If res<>0
;Debug "PrintDlg_ success res="+Str(res)
If *PrinterNames\wDeviceOffset<>0
PrintLib_PN=PeekS(*PrinterNames + *PrinterNames\wDeviceOffset)
;PRNNAME$=PrintLib_PN
;Debug "Buffersize="+Str(Buffersize)
;Debug "SizeOf(DEVMODE)="+Str(SizeOf(DEVMODE))
;Debug "dmSize="+Str(*PrinterParameters\dmSize)
;Debug "dmDriverExtra="+Str(*PrinterParameters\dmDriverExtra)
;Debug "GlobalSize_(hGmem1)="+Str(GlobalSize_(hGmem1))
;Debug "GlobalSize_(hGmem2)="+Str(GlobalSize_(hGmem2))
;copy devmode structure to internal buffer
*PrintLibDEVMODESize=GlobalSize_(hGmem1) ;<=== CRASHES HERE
*PrintLibDEVMODE=AllocateMemory(*PrintLibDEVMODESize)
CopyMemory(*DevBuffer,*PrintLibDEVMODE,*PrintLibDEVMODESize)
; open the printer and return it´s DC
res=ipprint_OpenPrinter(PrintLib_PN,"",0)
EndIf
EndIf
GlobalFree_(hGmem1)
GlobalFree_(hGmem2)
EndIf
ProcedureReturn res
EndProcedure
__________________________________________________
Code tags added
24.08.2016
RSBasic
Re: PrinterLib 1.10
Posted: Wed Aug 24, 2016 1:14 am
by DeanH
Further to the above ... I suspect is it Unicode related. I tried recompiling using PB 5.31 in Unicode mode and it crashed at the same place. I will try to dig into that but if anyone has an easy solution, it would be greatly appreciated.
Re: PrinterLib 1.10
Posted: Sun Mar 26, 2017 1:50 pm
by charvista
Using PrintLib in PureBasic 5.60 (and some earlier versions) no longer works because PRINTDEV has no structure predefined.
Is there a newer version of PrintLib?
Or, can someone please create the structure of PRINTDEV, that we can see in C++ format at
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
Code: Select all
typedef struct _devicemode {
TCHAR dmDeviceName[CCHDEVICENAME];
WORD dmSpecVersion;
WORD dmDriverVersion;
WORD dmSize;
WORD dmDriverExtra;
DWORD dmFields;
union {
struct {
short dmOrientation;
short dmPaperSize;
short dmPaperLength;
short dmPaperWidth;
short dmScale;
short dmCopies;
short dmDefaultSource;
short dmPrintQuality;
};
struct {
POINTL dmPosition;
DWORD dmDisplayOrientation;
DWORD dmDisplayFixedOutput;
};
};
short dmColor;
short dmDuplex;
short dmYResolution;
short dmTTOption;
short dmCollate;
TCHAR dmFormName[CCHFORMNAME];
WORD dmLogPixels;
DWORD dmBitsPerPel;
DWORD dmPelsWidth;
DWORD dmPelsHeight;
union {
DWORD dmDisplayFlags;
DWORD dmNup;
};
DWORD dmDisplayFrequency;
#if (WINVER >= 0x0400)
DWORD dmICMMethod;
DWORD dmICMIntent;
DWORD dmMediaType;
DWORD dmDitherType;
DWORD dmReserved1;
DWORD dmReserved2;
#if (WINVER >= 0x0500) || (_WIN32_WINNT >= 0x0400)
DWORD dmPanningWidth;
DWORD dmPanningHeight;
#endif
#endif
} DEVMODE, *PDEVMODE, *LPDEVMODE;
Thanks!
Re: PrinterLib 1.10
Posted: Sun Mar 26, 2017 2:38 pm
by Thunder93
w/PB It's named DEVMODE
Code: Select all
Structure DEVMODE
dmDeviceName.c[32]
dmSpecVersion.w
dmDriverVersion.w
dmSize.w
dmDriverExtra.w
dmFields.l
StructureUnion
Printer.DEVMODE_PRINTER
Display.DEVMODE_DISPLAY
EndStructureUnion
dmColor.w
dmDuplex.w
dmYResolution.w
dmTTOption.w
dmCollate.w
dmFormName.c[32]
dmLogPixels.w
dmBitsPerPel.l
dmPelsWidth.l
dmPelsHeight.l
StructureUnion
dmDisplayFlags.l
dmNup.l
EndStructureUnion
dmDisplayFrequency.l
dmICMMethod.l
dmICMIntent.l
dmMediaType.l
dmDitherType.l
dmReserved1.l
dmReserved2.l
dmPanningWidth.l
dmPanningHeight.l
EndStructure
Structure DEVMODE_PRINTER
dmOrientation.w
dmPaperSize.w
dmPaperLength.w
dmPaperWidth.w
dmScale.w
dmCopies.w
dmDefaultSource.w
dmPrintQuality.w
EndStructure
Structure DEVMODE_DISPLAY
dmPosition.POINT
dmDisplayOrientation.l
dmDisplayFixedOutput.l
EndStructure
Re: PrinterLib 1.10
Posted: Sun Mar 26, 2017 3:24 pm
by charvista
Thank you very much Thunder93!
Now I'll try to implement it in my code...
Re: PrinterLib 1.10
Posted: Sun Mar 26, 2017 3:51 pm
by charvista
Thunder93 wrote:
w/PB It's named DEVMODE
It is strange. I implemented your Structure DEVMODE, the compiler then says:
Structure already declared: DEVMODE (in a resident file)
Without your structure, the compiler says:
Structure field not found: dmOrientation
What's missing here? Is DEVMODE included in PureBasic? Is the internal structure correct?
The code that gives the problem is here (under CASE "ORIENTATION"): (code is from PureLib, with the exception that the procedurenames are always beginning with a 'z' in my final codes)
Code: Select all
Procedure zPrintLibSetDEVMODE(Option$,*PrinterParameters.DEVMODE)
Protected Flags,cnt,i,part$,opt$,value
cnt=CountString(Option$,",")
For i=0 To cnt
part$=StringField(Option$,i+1,",")
opt$=StringField(part$,1,"=")
value=Val(StringField(part$,2,"="))
Select UCase(opt$)
Case "ORIENTATION"
*PrinterParameters\dmFields|#DM_ORIENTATION
*PrinterParameters\dmOrientation=value
Case "PAPERSIZE"
*PrinterParameters\dmFields|#DM_PAPERSIZE
*PrinterParameters\dmPapersize=value
Case "PAPERLENGTH"
*PrinterParameters\dmFields|#DM_PAPERLENGTH
*PrinterParameters\dmPaperlength=value
Case "PAPERWIDTH"
*PrinterParameters\dmFields|#DM_PAPERWIDTH
*PrinterParameters\dmPaperwidth=value
Case "SCALE"
*PrinterParameters\dmFields|#DM_SCALE
*PrinterParameters\dmScale=value
Case "COPIES"
*PrinterParameters\dmFields|#DM_COPIES
*PrinterParameters\dmCopies=value
Case "DEFAULTSOURCE"
*PrinterParameters\dmFields|#DM_DEFAULTSOURCE
*PrinterParameters\dmDefaultsource=value
Case "PRINTQUALITY"
*PrinterParameters\dmFields|#DM_PRINTQUALITY
*PrinterParameters\dmPrintquality=value
Case "COLOR"
*PrinterParameters\dmFields|#DM_COLOR
*PrinterParameters\dmColor=value
Case "DUPLEX"
*PrinterParameters\dmFields|#DM_DUPLEX
*PrinterParameters\dmDuplex=value
Case "YRESOLUTION"
*PrinterParameters\dmFields|#DM_YRESOLUTION
*PrinterParameters\dmYResolution=value
Case "TTOPTION"
*PrinterParameters\dmFields|#DM_TTOPTION
*PrinterParameters\dmTTOption=value
Case "COLLATE"
*PrinterParameters\dmFields|#DM_COLLATE
*PrinterParameters\dmCollate=value
EndSelect
Next
EndProcedure
Re: PrinterLib 1.10
Posted: Sun Mar 26, 2017 4:01 pm
by Thunder93
charvista wrote:Thunder93 wrote:
w/PB It's named DEVMODE
It is strange. I implemented your Structure DEVMODE, the compiler then says:
Structure already declared: DEVMODE (in a resident file)
That's what I was referring to.. It is already included w/PB.
What you looking for is...
DevMode.DEVMODE\
Printer\dmOrientation

Re: PrinterLib 1.10
Posted: Sun Mar 26, 2017 4:14 pm
by charvista
Thunder93 wrote:
DevMode.DEVMODE\Printer\dmOrientation
YES! That was it! Thanks a lot!!
Changed
*PrinterParameters\dmOrientation=value
To
*PrinterParameters\Printer\dmOrientation=value
and it is working (again).
Now I am wondering if that mistake was mine, or was it already in the original PureLib?....