Re: Can't be solved: Error code 473 - Unable to allocate memory

new topic     » goto parent     » topic index » view thread      » older message » newer message

Pete Lomax wrote:
> 
> CChris wrote:
> > 
> > I'll have to stop everything related with printing on such failures so as to
> > proceed smoothly even though no printer will be available (for configuration
> > at least).
> 
> I think it would be better to debug the code rather than bury the problem
> deeper? smile
> One thing you could reasonably do is move all such code as:
> }}}
<eucode>
> integer pinit
>         pinit = 0
> procedure initPrinter()
>     vPrinterName = getDefaultPrinterName()
>     setPrinterPointers(0)
>     pinit = 1
> end procedure
> </eucode>
{{{

> and sprinkle a few
> }}}
<eucode>
>     if not pinit then initPrinter() end if
> </eucode>
{{{

> around the top of several printer-related routines. Then make error messages
> much more agressive, at least half the problem is they are silent now.

Simply changing
setPrinterPointer(0)

to
if length(vPrinterName) then
    setPrinterPointer(0)
end if


> I would also deliberately mangle vPrinterName as well as pretend that some
> other
> c_func calls had failed and make sure that when I did try to print I got
> useful
> error messages.
> 

Currently they all pop the printer dialog if printerDC is null or vPrinterName
is "". Nothing happens if no printer is available. I'll sprinkle a few warnErr()
I guess.

> According to msdn, this is wrong:
> }}}
<eucode>
>     rc = w32Func(xGetDefaultPrinter,{pBuffer,pNeeded})
>     if rc=0 then
>        rc=1 -- buffer holds the ASCIZ string
>     elsif rc=ERROR_FILE_NOT_FOUND then
> </eucode>
{{{

> and should instead be:
> }}}
<eucode>
>     rc = w32Func(xGetDefaultPrinter,{pBuffer,pNeeded})
>     if rc=0 then
>        rc = w32Func(xGetLastError,{})
>        if rc=ERROR_INSUFFICIENT_BUFFER then
>            -- as-is
>        elsif rc=ERROR_FILE_NOT_FOUND then
>            -- ???
>        else ?9/0  -- ????
>        end if
>     end if
> </eucode>
{{{

> 

Darn... looks like my doc file is wrong,  should have looked there. By miracle
it does work...
However, I don't want to crash because something is wrong with printer, because
user may simply not have or need one at as application is launched.
It's good to check for a buffer too small error and try again, otherwise just
consider there's no printer.
This is exactly the situation Nemo reported.
And if you are bent on printing something still, Windows will see to it that
your app crashes, won't it?

> Also, while we're here, this seems wrong:
> }}}
<eucode>
> atom pname -- points to printer name
> pname = 0
> ...
> 	pname = w32acquire_mem(0,vPrinterName)        -- [OK]
> ...
> global procedure newPrinter(sequence s,integer flag)
>     pname = s                                         -- [not OK]
> </eucode>
{{{

> Clearly, that has simply never been tested, not even once sad
> 

Oops... Indeed I didn't try uninstalling my printer for testing that, and I
don't like the idea either. But something has to be done about it.

CChris

> Regards,
> Pete

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu