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