Re: This does not work on XP

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

Larry Miller wrote:
> 
> According to MSDN docs the PRINTER_ENUM_DEFAULT option should not be used with
> Win2000 or XP and the GetDefaultPrinter() function should be used instead.
> Unfortunately
> this function is not available on Win98. The following code has not been
> tested
> but it should work. The new function will use GetDefaultPrinter() if
> available,
> else it will use the previous code. There may be better ways to do this.
> 
> If the program need not work with Win98 the code could be very much
> simplified.
> 
> }}}
<eucode>
> --Add this declaration
> constant iGetDefaultPrinter=define_c_func(winspool,"GetDefaultPrinterA",
> 		{C_POINTER,C_LONG})
> 
> global function DefaultPrinterName()
> -- return default printer name
> atom pPInfo5, pNeeded, pReturned, ok, needed
> sequence PrinterName
> 
> ----Add This--
> atom pBuffer
>  pBuffer=allocate(40)
>  if iGetDefaultPrinter>0 then	--OS is Win2000 or XP
>  	ok=c_func(iGetDefaultPrinter,{pBuffer,40})
>  	if ok then
>  		PrinterName=peeksz(pBuffer)
>  	else
>  		PrinterName=""
>  	end if
>  	free(pBuffer)
>         return PrinterName
>  end if
> ----End Additions
> 	
>  pNeeded = allocate(4)    mem_set(pNeeded,0,4)
>  pReturned = allocate(4)  mem_set(pReturned,0,4)
>  -- first try to know how many bytes needed for pPInfo5
>  ok =
>  c_func(iEnumPrinters,{PRINTER_ENUM_DEFAULT,NULL,5,0,0,pNeeded,pReturned})
>  needed = peek4u(pNeeded)
>  pPInfo5 = allocate(needed)    mem_set(pPInfo5,0,needed)
>  ok = c_func(iEnumPrinters,{PRINTER_ENUM_DEFAULT,NULL,5,pPInfo5,needed,
>                             pNeeded,pReturned})
>  free(pNeeded)
>  free(pReturned)
>  if not ok then
>     free(pPInfo5)
>     return {}
>  else
>     PrinterName  = peeksz(peek4u(pPInfo5))
>     free(pPInfo5)
>     return PrinterName
>  end if
> end function 
> </eucode>
{{{

> 
> Larry Miller

GREAT!!!

I'll try this tommorow and let you know if it works.

Again, Thank you Euphorians for your help.

By the way, I've been a Epophoria programer since 1998. I don't like the
constant complaining about what the language won't do, try improvements
by what Larry Miller has just done.

Rod

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

Search



Quick Links

User menu

Not signed in.

Misc Menu