Jump to content

Printing using Martin's UDF & DLL; _PrintSetPrinter()


MikahS
 Share

Go to solution Solved by BrewManNH,

Recommended Posts

I am just starting to use this UDF and I'm not sure if it's my sheer ignorance with this UDF or something that's missing, but I'm getting an error with _PrintSetPrinter(), which will not even bring up the dialog box to select the printer. Here's my code (tested):

#include <printMGv2.au3>
#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

Local $hwnd, $hButton, $msg, $hp, $mmssgg

$hwnd = GUICreate("Example")
$hButton = GUICtrlCreateButton("click me to print", 20, 20)
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Print")
GUISetState()

$hp = _PrintDLLStart($mmssgg) ; open the print dll

While 1
WEnd

Func Print()
    Local $selected
    If $hp = 0 Then ; if we couldn't open the dll
        MsgBox(0, "", "Error from dllstart = " & $mmssgg & @CRLF) ; tell us
        Return ; get out
    EndIf
    $selected = _PrintSetPrinter($hp) ; set the printer
    MsgBox(0, "", $selected)
    _PrintDLLClose($hp) ; close the dll
EndFunc   ;==>Print

Func Quit()
    Exit
EndFunc   ;==>Quit
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

  • Moderators

It works just fine for me. You're declaring variable $mmssgg, and you use it in your _PrintDLLStart function, but you never define it. You need to point it to the dll.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

$mmssgg = "C:\Windows\System32\printMG.dll"

 

Doesn't work, am I just stupid or what? hah

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Also, this is from Martin's example.

#include 'printMGv2.au3'
Global $hp
Local $mmssgg,$marginx,$marginy
$hp = _PrintDllStart($mmssgg);this must always be called first
if $hp = 0 then
    consolewrite("Error from dllstart = " & $mmssgg & @CRLF)
    Exit
endif
MsgBox(0,'version of dll',_PrintVersion($hp,1))
;MsgBox(0,'result from set printer = ',_PrintGetPrinter($hp));choose the printer if you don't want the default printer
;Exit
;$newselect = _PrintSelectPrinter($hp,"\\MOSAIC1\EPSON Stylus Photo 895")
$newselect = _PrintSetPrinter($hp)
MsgBox(0,'result from set printer = ',_PrintGetPrinter($hp));choose the printer if you don't want the default printer

EDIT: This example works, which confuses me, as I took this almost word for word.

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

  • Solution

Don't put the DLL in the system32 folder, you would probably need to use #RequireAdmin if you do. Also, the first parameter for _PrintDLLStart is not the path to the file, it's the variable used to hold any error message, the second parameter of that function is where you'd need to put the file name and path to the DLL. By default, that function looks for the DLL in the script's folder.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thank you BrewMan! I moved the .dll and changed the params around to let $mmssgg catch errors and a var $pathDLL to specify the path to the .dll. After that, it brought the dialog box up just as it is suppose to. :D

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...