1. This does not work on XP
- Posted by Rod Damon <roddamon at bellsouth.net> Jan 07, 2006
- 548 views
- Last edited Jan 08, 2006
The following routine works just fine on WIN98 but bombs on my XP. WHY? I can program Euphoria just fine, but not API. Can someone with API programming knowlege help me. This is part of my windows printing package that I posted awhile back. Now I know why there have been some complaints on the forum. Any help would be appreciated. Thanks in advance.
-- print.ew -- --originally by Jacques Deschenes, api_wrap.zip
include machine.e include dll.e
** added from win_misc.ew function peeksz(atom pStr) peek string zero return from allocated memory a string terminated by zero 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
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
global function DefaultPrinterName()
return default printer name atom pPInfo5, pNeeded, pReturned, ok, needed sequence PrinterName 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
Rod Damon }}}
2. Re: This does not work on XP
- Posted by Brian Broker <brian_broker at yahoo.com> Jan 08, 2006
- 525 views
Rod Damon wrote: > > The following routine works just fine on WIN98 but bombs on my XP. WHY? > I can program Euphoria just fine, but not API. > Can someone with API programming knowlege help me. > This is part of my windows printing package that I posted awhile back. > Now I know why there have been some complaints on the forum. > > Any help would be appreciated. Thanks in advance. > > }}} <eucode> > -- print.ew -- > --originally by Jacques Deschenes, api_wrap.zip > > include machine.e > include dll.e > > -- ** added from win_misc.ew > function peeksz(atom pStr) -- peek string zero > -- return from allocated memory a string terminated by zero > 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 > > 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 > > global function DefaultPrinterName() > -- return default printer name > atom pPInfo5, pNeeded, pReturned, ok, needed > sequence PrinterName > > 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 > > Rod Damon For a guy like me, it's easier to debug when you give as many details as you can. Do I need api_wrap.zip? I get: winspool has not been declared iEnumPrinters = define_c_func(winspool,"EnumPrintersA",{C_INT,C_INT,C_INT, ^ All I can say is that you need to declare 'winspool'.... -- Brian
3. Re: This does not work on XP
- Posted by Rod Damon <roddamon at bellsouth.net> Jan 08, 2006
- 542 views
Thank you for answering. This is needed. constant winspool = open_dll("winspool.drv") Rod Damon
4. Re: This does not work on XP
- Posted by Brian Broker <brian_broker at yahoo.com> Jan 08, 2006
- 540 views
Rod Damon wrote: > > Thank you for answering. > > This is needed. > > constant winspool = open_dll("winspool.drv") > > > Rod Damon No problem... but I still can't repro a problem with just declarations. Can you provide a failing demo? Thanks, -- Brian
5. Re: This does not work on XP
- Posted by Brian Broker <brian_broker at yahoo.com> Jan 08, 2006
- 556 views
Brian Broker wrote: > > Rod Damon wrote: > > > > Thank you for answering. > > > > This is needed. > > > > constant winspool = open_dll("winspool.drv") > > > > > > Rod Damon > > No problem... but I still can't repro a problem with just declarations. Can > you provide a failing demo? > > Thanks, > -- Brian Nevermind... it might have been best to just tell me to grab your stuff from the archives. I can verify that nothing works. I'll see what I can do to help. -- Brian
6. Re: This does not work on XP
- Posted by "Wolf" <wolfritz at king.igs.net> Jan 08, 2006
- 539 views
Tried to use this in XP years ago, and failed. Can't remember exact details, but according to the 'fuzzy' API docs, PRINTER_ENUM_DEFAULT probably only works on 9x's, ... not NT/XP. Ended up wrapping simplest PrintDlg() instead.
7. Re: This does not work on XP
- Posted by Rod Damon <roddamon at bellsouth.net> Jan 08, 2006
- 522 views
- Last edited Jan 09, 2006
Yea! that's were I found the problem to be also. What I need at work is a simple print button at work, so the user only prints to the default printer for his/her work station. The user of the work stations do not always know what the default printer is. PrintDlg() gives a list of available printers to choose from. I need to control the work station to only the default printer. Any help from the API programers out there would be greatly appreciated. Rod Wolf wrote: > > Tried to use this in XP years ago, and failed. Can't remember exact details, > but according to the 'fuzzy' API docs, PRINTER_ENUM_DEFAULT probably only > works on 9x's, ... not NT/XP. > Ended up wrapping simplest PrintDlg() instead. > >
8. Re: This does not work on XP
- Posted by Al Getz <Xaxo at aol.com> Jan 09, 2006
- 523 views
Rod Damon wrote: > > Yea! that's were I found the problem to be also. > > What I need at work is a simple print button at work, so the user only prints > to the default printer for his/her work station. The user of the work stations > do not always know what the default printer is. > PrintDlg() gives a list of available printers to choose from. > I need to control the work station to only the default printer. > > Any help from the API programers out there would be greatly appreciated. > > Rod > > Wolf wrote: > > > > Tried to use this in XP years ago, and failed. Can't remember exact details, > > but according to the 'fuzzy' API docs, PRINTER_ENUM_DEFAULT probably only > > works on 9x's, ... not NT/XP. > > Ended up wrapping simplest PrintDlg() instead. > > > > Hi there, Just a guess but did you try something other than level=5 ? Somewhere in the doc's it says 5 isnt allowed for NT so maybe also not with XP. Just a guess though, this may not help either. Take care, Al And, good luck with your Euphoria programming! My bumper sticker: "I brake for LED's"
9. Re: This does not work on XP
- Posted by Rod Damon <roddamon at bellsouth.net> Jan 09, 2006
- 516 views
Al Getz wrote: > > Hi there, > > Just a guess but did you try something other than level=5 ? > Somewhere in the doc's it says 5 isnt allowed for NT so maybe > also not with XP. Just a guess though, this may not help either. > > > Al > > > My bumper sticker: "I brake for LED's" Sorry guys, I guess I have not given enough info on what I get when I run the function under WIN98 and what I get under XP. When I get to work tomorrow, I will get the results from WIN98 and then I will get the results at home from XP and let you know what they are. Thanks for trying to help. Rod
10. Re: This does not work on XP
- Posted by Larry Miller <larrymiller at sasktel.net> Jan 09, 2006
- 544 views
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.
--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
Larry Miller
11. Re: This does not work on XP
- Posted by Rod Damon <roddamon at bellsouth.net> Jan 09, 2006
- 554 views
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