Sign in to follow this  
Followers 0
Joon

Need A Help From The Pros On Making Api Call

12 posts in this topic

I am trying make this work in AutoIt. But this DllCall is too complicate for me to figure out. I am not sure what DataType to use. I searched Forum for LPTSTR(DeviceCapabilities) and it got me more confusing.

Any help will be greatly appreciated.

Share this post


Link to post
Share on other sites



I am trying make this work in AutoIt. But this DllCall is too complicate for me to figure out. I am not sure what DataType to use. I searched Forum for LPTSTR(DeviceCapabilities) and it got me more confusing.

Any help will be greatly appreciated.

I would assume that LPTSTR = 'str'.

http://www.autoitscript.com/forum/index.ph...indpost&p=49822


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I'm stuck. :)

Const $DC_BINS = 6
Const $DC_BINNAMES = 12
Dim $lpOutput

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters =  $objWMIService.ExecQuery("Select Name, PortName from Win32_Printer")
For $objPrinter in $colInstalledPrinters
    $result = DllCall("winspool.drv", "long","DeviceCapabilitiesA","str",$objPrinter.Name ,"str",$objPrinter.PortName,"int",$DC_BINNAMES,"str",$lpOutput,"long",0)
    MsgBox(0,"",$result)
Next

DWORD DeviceCapabilities(

LPCTSTR pDevice, // printer name

LPCTSTR pPort, // port name

WORD fwCapability, // device capability

LPTSTR pOutput, // output buffer

CONST DEVMODE *pDevMode // device data buffer

);

Parameters

pDevice

[in] Pointer to a null-terminated string that contains the name of the printer. Note that this is the name of the printer, not of the printer driver.

pPort

[in] Pointer to a null-terminated string that contains the name of the port to which the device is connected, such as LPT1

pOutput

[out] Pointer to an array. The format of the array depends on the setting of the fwCapability parameter. If pOutput is NULL, DeviceCapabilities returns the number of bytes required for the output data.

pDevMode

[in] Pointer to a DEVMODE structure. If this parameter is NULL, DeviceCapabilities retrieves the current default initialization values for the specified printer driver. Otherwise, the function retrieves the values contained in the structure to which pDevMode points.

How do I pass in a null-terminated string?

How do I pass in NULL parameter in AutoIt?

Share this post


Link to post
Share on other sites

Are you getting an error?

BTW, you do realize that the DLLCall returns an array right?

I'm not the best at doing these, but let's see what you get with this:

Const $DC_BINS = 6
Const $DC_BINNAMES = 12
Dim $lpOutput

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters =  $objWMIService.ExecQuery("Select Name, PortName from Win32_Printer")
For $objPrinter in $colInstalledPrinters
    $result = DllCall("winspool.drv", "long","DeviceCapabilitiesA","str",$objPrinter.Name ,"str",$objPrinter.PortName,"int",$DC_BINNAMES,"str",$lpOutput,"long",0)
    If IsArray($result) Then
        For $i = 0 To UBound($result) - 1
            MsgBox(0, 'Info', '$result[' & $i & '] = ' & $result[$i])
        Next
    EndIf
Next

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Are you getting an error?

BTW, you do realize that the DLLCall returns an array right?

I'm not the best at doing these, but let's see what you get with this:

Const $DC_BINS = 6
Const $DC_BINNAMES = 12
Dim $lpOutput

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters =  $objWMIService.ExecQuery("Select Name, PortName from Win32_Printer")
For $objPrinter in $colInstalledPrinters
    $result = DllCall("winspool.drv", "long","DeviceCapabilitiesA","str",$objPrinter.Name ,"str",$objPrinter.PortName,"int",$DC_BINNAMES,"str",$lpOutput,"long",0)
    If IsArray($result) Then
        For $i = 0 To UBound($result) - 1
            MsgBox(0, 'Info', '$result[' & $i & '] = ' & $result[$i])
        Next
    EndIf
Next
It worked :)

I was doing IsArray($lpOutput) and I thought $return would be int.

Thanks much.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I hit another block in the wall.

nameslist = String(24 * dwbins, 0)

How do I turn above VB script to AutoIt? Trying to setup an array of string buffers to pass in during DllCall.

Retrieves the names of the printer's paper bins. The pOutput buffer receives an array of string buffers. Each string buffer is 24 characters long and contains the name of a paper bin. The return value indicates the number of entries in the array. The name strings are null-terminated unless the name is 24 characters long. If pOutput is NULL, the return value is the number of bin entries required.

For $i = 1 to (24 * $dwbins)
$namelist = $namelist & Chr(0)
Next

This give me just single NULL character.

Edited by Joon

Share this post


Link to post
Share on other sites

Somehow this get me the first Tray name but not all trays.

Const $DC_BINS = 6
Const $DC_BINNAMES = 12
Dim $BinNameList
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters =  $objWMIService.ExecQuery("Select Name, PortName from Win32_Printer")
For $objPrinter in $colInstalledPrinters
    $result = DllCall("winspool.drv", "long","DeviceCapabilitiesA","str",$objPrinter.Name ,"str",$objPrinter.PortName,"int",$DC_BINS,"str",Chr(0),"long",0)
    For $i = 1 to (24 * $result[0])
        $BinNameList = $BinNameList & Chr(0)
    Next
    $result2 = DllCall("winspool.drv", "long","DeviceCapabilitiesA","str",$objPrinter.Name ,"str",$objPrinter.PortName,"int",$DC_BINNAMES,"str",$BinNameList,"long",0)
    MsgBox(0,"BinNames",$result2[4])
Next

I not sure what I am missing. Here is another example using DeviceCapabilities. link

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

try

Const $DC_BINS = 6
Const $DC_BINNAMES = 12
Dim $BinNameList
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select Name, PortName from Win32_Printer")
For $objPrinter In $colInstalledPrinters
    $result = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_BINS, "str", Chr(0), "long", 0)
    $s_struct = ""
    For $i = 1 To $result[0]
        $s_struct = $s_struct & "char[24];"
    Next
    $s_struct = StringTrimRight($s_struct, 1)
    $struct = DllStructCreate($s_struct)
    $result2 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_BINNAMES, "ptr", DllStructGetPtr($struct), "long", 0)
    For $i = 1 To $result[0]
        MsgBox(0, "BinNames", DllStructGetData($struct, $i))
    Next
    $struct = 0
Next
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

try

Const $DC_BINS = 6
Const $DC_BINNAMES = 12
Dim $BinNameList
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select Name, PortName from Win32_Printer")
For $objPrinter In $colInstalledPrinters
    $result = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_BINS, "str", Chr(0), "long", 0)
    $s_struct = ""
    For $i = 1 To $result[0]
        $s_struct = $s_struct & "char[24];"
    Next
    $s_struct = StringTrimRight($s_struct, 1)
    $struct = DllStructCreate($s_struct)
    $result2 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_BINNAMES, "ptr", DllStructGetPtr($struct), "long", 0)
    For $i = 1 To $result[0]
        MsgBox(0, "BinNames", DllStructGetData($struct, $i))
    Next
    $struct = 0
Next
I don't have slight idea about DllStruct but it works... Thank you.

Now I need to get BinNumbers for the collected BinNames. One down and one more to go. :)

Share this post


Link to post
Share on other sites

#10 ·  Posted

With help from gafrost, Smoke, and AutoIt help, my task is done.

Thanks all. You guys are Pros :)

Share this post


Link to post
Share on other sites

Hello together,

I am a newbie and have following question.

Is the CallDll-Operation (including winspool.drv) able to operate with functions like OpenPrinterA and SetPrinterA?

If yes, is there somebody who could tell me how.

I'm looking for a posibillity to delete printjobs, pause and resume the printer in a Win98 enviroment.

Thank you in advance

Share this post


Link to post
Share on other sites

Hello gurus, am having problem getting the papernames and papersizes, see the code am using

#include <Debug.au3>
#include <String.au3>
#include <Array.au3>
Const $DC_BINS = 6
Const $DC_BINNAMES = 12
Const $DC_PAPERNAMES = 16
Const $DC_PAPERS = 2
Const $DC_PAPERSIZE = 3
Dim $BinNameList
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select Name, PortName from Win32_Printer")
For $objPrinter In $colInstalledPrinters
    $result = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERS, "str", Chr(0), "long", 0)
    $s_struct = ""
;_DebugSetup ($s_struct)
    $s_struct=_StringRepeat("0", $result[0]*64)
    ;$s_struct = StringTrimRight($s_struct, 1)
    $struct = DllStructCreate($s_struct)
    $result2 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERNAMES, "ptr", DllStructGetPtr($struct), "long", 0)
    ;_DebugOut ( $objPrinter.Name) 
    For $i = 0 To $result[0]-1
            _ArrayDisplay($result2)
        ;_DebugOut (DllStructGetData($struct, $i)) 
    Next
    $struct = 0
Next

please help me. am getting only the printer names and series of 0s which is suppoes to be the papernames

Share this post


Link to post
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
Sign in to follow this  
Followers 0