Re: Print Preview - Pete Lomax
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Oct 07, 2003
- 381 views
On Tue, 7 Oct 2003 19:10:41 +1000, Tony Steward <tsteward at dodo.com.au> wrote: > > >Hello Pete, >I downloaded you files but when I click on the tutorial icon & some >others I get the following error: > >C:\EUPHORIA\include\machine.e:102 in function allocate()=20 >type_check failure, n is 0=20 > n =3D 0 > >... called from C:\tony\pp\pprg.ew:307 in function Fa() =20 > Fb =3D 0 > I think that's because the default printer name on your system is blank, which I didn't expect. Can you run the following code snippet, if it fails make the +1 change as shown on line 38 and re-try, thanks. If it works OK I'll put a new version up. Regards, 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 pPInfo5, 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 pPInfo5 ok =3D c_func(iEnumPrinters,{PRINTER_ENUM_DEFAULT, NULL,5,0,0,pNeeded,pReturned}) needed =3D peek4u(pNeeded) pPInfo5 =3D allocate(needed) -- pPInfo5 =3D allocate(needed+1) -- Tony Steward 7/10/03 mem_set(pPInfo5,0,needed) ok =3D c_func(iEnumPrinters,{PRINTER_ENUM_DEFAULT,NULL,5,pPInfo5,needed, pNeeded,pReturned}) free(pNeeded) free(pReturned) PrinterName=3D{} if ok then PrinterName =3D peeksz(peek4u(pPInfo5)) end if free(pPInfo5) return PrinterName end function puts(1,getDefaultPrinterName()) puts(1,"\nPress Enter to exit\n") if getc(0) then end if