on 04-03-2013 11:25 AM
Here's the correct API-Call:
// Declare External Functions
FUNCTION LONG DeviceCapabilities ( STRING as_device, STRING as_port, ULONG rul_output, REF STRING rs_output, LONG dev ) LIBRARY "winspool.drv" ALIAS FOR "DeviceCapabilitiesW"
FUNCTION LONG DeviceCapabilities ( STRING as_device, STRING as_port, ULONG rul_output, REF char rs_output [], LONG dev ) LIBRARY "winspool.drv" ALIAS FOR "DeviceCapabilitiesW"
// Declare variables
CONSTANT INTEGER DC_PAPERNAMES = 16
CONSTANT INTEGER NUMBEROFBYTES = 64
STRING ls_null, ls_papername, ls_printer, ls_port
STRING lsa_papernames []
INTEGER li_null
LONG ll_paper, ll_step, ll_bound_min , ll_bound_max, ll_papercount
CHAR lc_papernames []
setNull ( li_NULL )
setNull ( ls_NULL )
// for example
ls_printer = "HP LASERJET"
ls_port = "LTP:1"
// Count the papernames
ll_papercount = DeviceCapabilities ( ls_printer, ls_port, DC_PAPERNAMES, REF ls_null, li_null )
// allocate memory
lc_papernames [ll_paperCount * NUMBEROFBYTES ] = ""
// API call
DeviceCapabilities( ls_printer, ls_port, DC_PAPERNAMES, REF lc_papernames [] , 0 )
// Parse to Array
ll_bound_min = 1
FOR ll_paper = 1 to ll_papercount
ll_bound_max = ll_bound_min + NUMBEROFBYTES - 1
ls_papername =
FOR ll_step = ll_bound_min TO ll_bound_max
IF NOT isNull ( lc_papernames [ ll_step ] ) THEN ls_papername += string ( lc_papernames [ ll_step ] )
NEXT
lsa_papernames [ ll_paper ] = ls_papername
ll_bound_min = ll_bound_max + 1
NEXT
And you get a Stringarray with the papernames.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Care to share the code you are using? Version of PB? Windows?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I Used PB 12.5.1 Build 4953 and Windows 7 64-Bit.
Local External Functions:
LONG DeviceCapabilities ( STRING as_device, STRING as_port, ULONG rul_output, REF STRING rs_output[], LONG dev ) LIBRARY "winspool.drv" ALIAS FOR "DeviceCapabilitiesW"
the call:
DeviceCapabilities ( ls_printer, ls_port, DC_PAPERNAMES, REF ls_papernames [] , 0 )
What's the content of ls_name and ls_port? Is it available?
Did you test it on other machines with Windows 7 64bit?
Did you test it on machines with Windows 7/XP 32bit?
Did you try to use a string instead of array?
Did you try to allocate the output variable before getting some value? Take a look at http://www.pinvoke.net/default.aspx/Enums/DeviceCapabilities.html?diff=y it's just a pointer.
best regards
In the Remarks section of the MSDN page regarding this function it states:
"Note This is a blocking or synchronous function and might not return immediately. How quickly this function returns depends on run-time factors such as network status, print server configuration, and printer driver implementation—factors that are difficult to predict when writing an application. Calling this function from a thread that manages interaction with the user interface could make the application appear to be unresponsive."
I'm not sure if this is part of your problem.
ls_name and ls_port are availble.
Yes I did.
No.
Yes.
Here is a fund on a German website. Is well documented.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.