Re: This does not work on XP Attn: Rod Damon
I made a few changes to my additions and the test program now works.
(On Windows 2000)
include dll.e
include machine.e
constant winspool = open_dll("winspool.drv")
constant
iEnumPrinters = define_c_func(winspool,"EnumPrintersA",{C_INT,C_INT,C_INT,
C_INT,C_INT,C_INT,C_INT},C_INT)
constant
PRINTER_ENUM_DEFAULT = 1
--Add this declaration
constant iGetDefaultPrinter=define_c_func(winspool,"GetDefaultPrinterA",
{C_POINTER,C_POINTER},C_LONG)
--with trace
-----------------------------------------------------------------------------
function peeksz(atom pStr) -- peek string zero
-- return from allocated memory a string terminated by sero
integer c,i
sequence str
str = {}
i = 1
c = peek(pStr)
while c do
str = str & c
c = peek(pStr+i)
i = i + 1
end while
return str
end function
-----------------------------------------------------------------------------
global function DefaultPrinterName()
-- return default printer name
atom pPInfo5, pNeeded, pReturned, ok, needed, pSize
sequence PrinterName
----Add This--
atom pBuffer
pBuffer=allocate(40)
pSize=allocate(4) --Added
poke4(pSize,40) --Added
if iGetDefaultPrinter>0 then --OS is Win2000 or XP
ok=c_func(iGetDefaultPrinter,{pBuffer,pSize})
if ok then
PrinterName=peeksz(pBuffer)
else
PrinterName=""
end if
free(pBuffer)
free(pSize) --Added
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
trace(1)
object temp
temp = DefaultPrinterName()
integer k
printf(1,"%s",{temp})
while 1 do
k = get_key()
if k != -1 then
exit
end if
end while
There was a change in the declaration for iGetDefaultPrinter and in calling the
function. I noticed that the function requires a pointer to the buffer size, not
the size itself. The necessary additions have been marked. For simplicity I have
hard coded the size of the name buffer as 40 bytes which should be sufficient.
Larry Miller
|
Not Categorized, Please Help
|
|