Joon Posted May 8, 2006 Share Posted May 8, 2006 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. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 8, 2006 Moderators Share Posted May 8, 2006 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 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. Link to comment Share on other sites More sharing options...
Joon Posted May 9, 2006 Author Share Posted May 9, 2006 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) NextDWORD DeviceCapabilities( LPCTSTR pDevice, // printer name LPCTSTR pPort, // port name WORD fwCapability, // device capability LPTSTR pOutput, // output buffer CONST DEVMODE *pDevMode // device data buffer);ParameterspDevice [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 LPT1pOutput [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? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 9, 2006 Moderators Share Posted May 9, 2006 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 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. Link to comment Share on other sites More sharing options...
Joon Posted May 9, 2006 Author Share Posted May 9, 2006 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. Link to comment Share on other sites More sharing options...
Joon Posted May 9, 2006 Author Share Posted May 9, 2006 (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) NextThis give me just single NULL character. Edited May 9, 2006 by Joon Link to comment Share on other sites More sharing options...
Joon Posted May 9, 2006 Author Share Posted May 9, 2006 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]) NextI not sure what I am missing. Here is another example using DeviceCapabilities. link Link to comment Share on other sites More sharing options...
GaryFrost Posted May 9, 2006 Share Posted May 9, 2006 (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 May 9, 2006 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.  Link to comment Share on other sites More sharing options...
Joon Posted May 9, 2006 Author Share Posted May 9, 2006 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. Link to comment Share on other sites More sharing options...
Joon Posted May 9, 2006 Author Share Posted May 9, 2006 With help from gafrost, Smoke, and AutoIt help, my task is done. Thanks all. You guys are Pros Link to comment Share on other sites More sharing options...
charly2024 Posted July 25, 2006 Share Posted July 25, 2006 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 Link to comment Share on other sites More sharing options...
TheCurrent Posted April 5, 2011 Share Posted April 5, 2011 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now