Jump to content

MSDN OpenPrinter Function - how to use this


Go to solution Solved by Danyfirex,

Recommended Posts

Posted

http://msdn.microsoft.com/en-us/library/windows/desktop/dd162751(v=vs.85).aspx

Anybody can show me a way how to use this function in AutoIt ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Solution
Posted

Hi mLipok. You can do something like this:

Local $hwinspool = DllOpen("winspool.drv")


Local $bRet = DllCall($hwinspool, "bool", "GetDefaultPrinterW", "ptr", 0, "dword*", 0)
Local $pcchBuffer = $bRet[2]


Local $tBuffer = DllStructCreate("wchar[" & $pcchBuffer & "]")
Local $pBuffer = DllStructGetPtr($tBuffer, 1)

$bRet = DllCall($hwinspool, "bool", "GetDefaultPrinterW", "ptr", $pBuffer, "dword*", $pcchBuffer)


Local $sPrinter = DllStructGetData($tBuffer, 1)

MsgBox(0, $pcchBuffer, "Default Printer Name: " & $sPrinter)


$bRet = DllCall($hwinspool, "bool", "OpenPrinterW", "wstr", $sPrinter, "handle*", 0, "ptr", 0)
Local $hPrinter = $bRet[2]

MsgBox(0, "Printer Handle:", $hPrinter)


$bRet = DllCall($hwinspool, "bool", "ClosePrinter", "handle", $hPrinter)

DllClose($hwinspool)

Saludos

Posted

Muchas gracias

mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...