cancel
Showing results for 
Search instead for 
Did you mean: 

DeviceCapabilities returns no paper names

Former Member
0 Kudos

Hi,

my call for the DeviceCapabilities returns no papernames, the blob that I get back is always a sign of 0 length.

A string or string-array are also empty.

Has anyone experiences with that?

Gerwin


Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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.

Answers (1)

Answers (1)

Former Member
0 Kudos

Care to share the code you are using? Version of PB? Windows?

Former Member
0 Kudos

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 )

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

ls_name and ls_port are availble.

Yes I did.

No.

Yes.

Here is a fund on a German website. Is well documented.

http://www.dfpug.de/konf%5Ckonf_1995%5Cfrx/sessiond-prn.htm