Re: Print Preview - Pete Lomax
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Oct 08, 2003
- 380 views
On Tue, 07 Oct 2003 12:38:34 -0400, "Louis Puster" <Louis at cwshop.com> wrote: >I tried your program in Windows 2000 SP4, latest patches. > >Crashed until I used the "needed+1" change. Now PrinterName is being = set to zero characters even though OK is true and I _do_ have a default = printer defined. Does that help? > Yes it does, thanks. I've now found out the printer_info_5 structure is only available on win9x, so I've replaced it with a printer_info_2 structure. Can you check if the following is any better on windows 2000 please. Thanks, Pete include win32lib.ew constant=20 iwinspool =3D open_dll("winspool.drv"), iEnumPrinters =3D define_c_func(iwinspool,"EnumPrintersA", {C_INT,C_INT,C_INT,C_INT,C_INT,C_INT,C_INT},C_INT), PRINTER_ENUM_DEFAULT =3D 1 global function peeksz(atom pStr) -- peek string zero -- return from allocated memory a string terminated by zero integer c,i sequence str str =3D {} i =3D 1 c=3D1 c =3D peek(pStr) while c !=3D 0 do str =3D str & c c =3D peek(pStr+i) i =3D i + 1 end while return str end function function getDefaultPrinterName() -- return default printer name atom pPInfo2, pNeeded, pReturned, ok, needed sequence PrinterName pNeeded =3D allocate(4) mem_set(pNeeded,0,4) pReturned =3D allocate(4) mem_set(pReturned,0,4) -- first try to know how many bytes needed for pPInfo2 ok =3D c_func(iEnumPrinters,{PRINTER_ENUM_DEFAULT, NULL,2, 0,0, pNeeded,pReturned}) needed =3D peek4u(pNeeded) pPInfo2 =3D allocate(needed+1) mem_set(pPInfo2,0,needed+1) ok =3D c_func(iEnumPrinters,{PRINTER_ENUM_DEFAULT, NULL,2, pPInfo2,needed, pNeeded,pReturned}) free(pNeeded) free(pReturned) PrinterName=3D{} if ok then PrinterName =3D peeksz(peek4u(pPInfo2+4)) end if free(pPInfo2) return PrinterName end function puts(1,getDefaultPrinterName()) puts(1,"\nPress Enter to exit\n") if getc(0) then end if