Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Declare Dll exception while using API commands to print
Message
 
 
To
23/03/2011 09:19:13
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
01504642
Message ID:
01504647
Views:
89
Have you tried to install a different printer driver for this printer?

See also Re: Error loading printer driver on W2K3 Thread #1185773 Message #1185875 for potential fix

>hello all,
>
>in one of our program, we use win32 api commands to send print jobs. it works fine but on one particular machine it always crashes with 'Delcare Dll call caused an execption' message while calling StartPage or TextOut functions. I have pasted code in here. This is not the actual code from our program but we basically do the same thing. for simplicity purposes i copied demo program from msdn site and tried it on that pc and noticed Declare DLL error happens while calling StartPage and TextOut functions. our program also crashes while calling these same functions.
>
>Its a win xp sp3 machine and default printer name i see in their 'print setup' is 'HP LasterJet 4250 PCL 6'
>they have PDF printer and microsoft xps document also installed as printers. if i make one of them as default then everything works fine but on above HP LaserJet printer Declare dll error happens. Other users are able to print to this same printer without any problems.
>
>Can anyone please guide me what could be wrong ? here is the code
>
>thanks very much in advance.
>
>
>hello all,
>
>in one of our program, we use win32 api commands to send print jobs. it works fine but on one particular machine it always crashes with 'Delcare Dll call caused an execption' message while calling StartPage or TextOut functions. I have pasted code in here. This is not the actual code from our program but we basically do the same thing. for simplicity purposes i copied demo program from msdn site and tried it on that pc and noticed Declare DLL error happens while calling StartPage and TextOut functions. our program also crashes while calling these same functions.
>
>Its a win xp sp3 machine and default printer name i see in their 'print setup' is 'HP LasterJet 4250 PCL 6'
>they have PDF printer and microsoft xps document also installed as printers. if i make one of them as default then everything works fine but on above HP LaserJet printer Declare dll error happens. Other users are able to print to this same printer without any problems.
>
>Can anyone please guide me what could be wrong ? here is the code.
>
>thanks very much in advance.
>
>
>
>DECLARE LONG CreateDC IN gdi32.DLL ;
>   STRING @cDriver, STRING @cDevice, STRING cOutput, ;
>   STRING cInitData
>
>DECLARE LONG DeleteDC IN gdi32.DLL ;
>   LONG nDC
>
>DECLARE INTEGER TextOut IN gdi32.DLL INTEGER hDC, INTEGER xStart, INTEGER yStart, ;
>   STRING @PrintString, INTEGER cbString
>
>DECLARE INTEGER StartDoc IN gdi32.DLL INTEGER hDC, STRING @DocInfo
>
>
>DECLARE INTEGER StartPage IN gdi32.DLL INTEGER hDC
>
>DECLARE INTEGER EndPage IN gdi32.DLL INTEGER hDC
>
>DECLARE INTEGER EndDoc IN gdi32.DLL INTEGER hDC
>
>DECLARE INTEGER GetLastError IN kernel32.DLL
>
>lcBuffer = SPACE(255)
>IF "5.0"$OS()
>   *!* If the OS is 5.0, the driver is either DISPLAY or WINSPOOL
>   lcDriver="WINSPOOL"
>ELSE
>
>   lcDriver=NULL
>ENDIF
>
>lcPrinter=GETPRINTER()
>hDC = CreateDC(lcDriver, lcPrinter, NULL, NULL)
>IF hDC = 0
>   MESSAGEBOX("Unable to create device context" + CHR(13) + ;
>      "Error Code : " + ALLTRIM(STR(GetLastError())),48)
>   RETURN
>ENDIF
>
>lcDocInfo = Long2Str(20) + REPLICATE(CHR(0), 16)
>
>retCode = StartDoc(hDC, @lcDocInfo)
>IF retCode <= 0
>   MESSAGEBOX("Error calling StartDoc" + CHR(13) + ;
>      " Error code : " + ALLTRIM(STR(GetLastError())),48)
>   RETURN
>ENDIF
>
>retCode = StartPage(hDC)
>IF retCode <= 0
>   MESSAGEBOX("Error calling StartPage" + CHR(13) + ;
>      " Error code : " + ALLTRIM(STR(GetLastError())),48)
>   RETURN
>ENDIF
>
>myString = "Using API functions for printing"
>myLength = LEN(myString)
>
>retCode = TextOut(hDC, 10, 10, @myString, myLength)
>IF retCode <= 0
>   MESSAGEBOX("Error calling TextOut" + CHR(13) + ;
>      " Error code : " + ALLTRIM(STR(GetLastError())),48)
>   RETURN
>ENDIF
>
>retCode = EndPage(hDC)
>IF retCode <= 0
>   MESSAGEBOX("Error calling EndPage" + CHR(13) + ;
>      " Error code : " + ALLTRIM(STR(GetLastError())),48)
>   RETURN
>ENDIF
>
>retCode = EndDoc(hDC)
>IF retCode <= 0
>   MESSAGEBOX("Error calling EndDoc" + CHR(13) + ;
>      " Error code : " + ALLTRIM(STR(GetLastError())),48)
>   RETURN
>ENDIF
>
>CLEAR DLLS
>
>FUNCTION Long2Str
>   PARAMETERS m.longval
>   PRIVATE i, m.retstr
>   m.retstr = ""
>   FOR i = 24 TO 0 STEP -8
>      m.retstr = CHR(INT(m.longval/(2^i))) + m.retstr
>      m.longval = MOD(m.longval, (2^i))
>   NEXT
>   RETURN m.retstr
>* End of Code
>
>
>
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform