1. Vijay Kumar Natarajan
  2. PowerBuilder
  3. Wednesday, 14 February 2024 21:12 PM UTC

Hi,

We are trying to upgrade the application from PB12.5 to PB 2022 R2. Currently we are encountering the Label printing issue.

In PB12.5, the declared external function signature is working well. But in PB2022 R2 Version the same signature is not working.

Application uses winspool.drv External Function to Open, StartDoc, WritePrinter and ClosePrinter to print to the Label printer (Honeywell).

I am getting the handle when opening the Printer, but commands which are set to WritePrinter is not printed in the printer. Basically no response from the printer.

 

Please kindly provide how the signature of this external function needs to be modified.

 

External Function Declarations:

FUNCTION Boolean OpenPrinter( &
String PrinterName, &
REF ULong hPrinter, &
Long NULL) LIBRARY "winspool.drv" ALIAS FOR "OpenPrinterW"
FUNCTION Long StartDocPrinter( &
Long hPrinter, &
Long Level, &
Str_DocInfo pDocInfo) LIBRARY "winspool.drv" ALIAS FOR "StartDocPrinterW"
FUNCTION Long StartPagePrinter( &
Long hPrinter) LIBRARY "winspool.drv"
FUNCTION Long WritePrinter( &
Long hPrinter, &
String pBuf, &
Long cdBuf, &
REF Long pcWritten) LIBRARY "winspool.drv" ALIAS FOR "WritePrinter;Ansi"
FUNCTION Long EndPagePrinter( &
Long hPrinter) LIBRARY "winspool.drv"
FUNCTION Long EndDocPrinter( &
Long hPrinter) LIBRARY "winspool.drv"
FUNCTION Boolean ClosePrinter(Long hPrinter) LIBRARY "winspool.drv"

 

Thank you,

Vijay

 

 

 

 

 

 

 

John Fauss Accepted Answer Pending Moderation
  1. Thursday, 15 February 2024 02:11 AM UTC
  2. PowerBuilder
  3. # 1

Vijay -

I've looked up the documentation for the various API functions you listed. One major issue I see from what you provided is that many of those API functions reside in spoolss.dll, not in winspool.drv. Another difference is that many of the API functions return a Boolean value.

Here are the external function declarations I would use if I were coding this:

FUNCTION Boolean OpenPrinter ( &
   String      pPrinterName, &
   REF Longptr phPrinter, &
   Longptr pDefault &
   ) LIBRARY "winspool.drv" ALIAS FOR "OpenPrinterW"

FUNCTION UnsignedLong StartDocPrinter ( &
   Longptr         hPrinter, &
   UnsignedLong    Level, &
   REF str_docinfo pDocInfo &
   ) LIBRARY "winspool.drv" ALIAS FOR "StartDocPrinterW"

FUNCTION Boolean StartPagePrinter ( &
   Longptr hPrinter &
   ) LIBRARY "spoolss.dll"

FUNCTION Boolean WritePrinter ( &
   Longptr          hPrinter, &
   String           pBuf, &
   UnsignedLong     cbBuf, &
   REF UnsignedLong pcWritten &
   ) LIBRARY "spoolss.dll" ALIAS FOR "WritePrinter;ansi"

FUNCTION Boolean EndPagePrinter ( &
   Longptr hPrinter &
   ) LIBRARY "spoolss.dll"

FUNCTION Boolean EndDocPrinter ( &
   Longptr hPrinter &
   ) LIBRARY "spoolss.dll"

FUNCTION Boolean ClosePrinter ( &
   Longptr hPrinter &
   ) LIBRARY "spoolss.dll"

To help ensure these declarations will work in 64-bit, I have specified Longptr as the datatype for any parameter that holds a Windows handle. You should use the Longptr datatype in your code for these values.

Here is the URL I used for the OpenPrinterW API function documentation:

    https://learn.microsoft.com/en-us/windows/win32/printdocs/openprinter

All of the documentation for the other printer API functions you are using are accessible via the sidebar on the web page listed above. In each case, the name of the DLL that contains the API function is listed near the end of the function's documentation page in a table.

I suggest you check the return value from each API function call to check for error conditions... that's always a good idea as it should help you determine which function(s) are not performing as intended.

Best regards, John

 

Comment
  1. Vijay Kumar Natarajan
  2. Thursday, 15 February 2024 17:20 PM UTC
Hi John,



Thank you so much for your review and comments.

Let me try this option and update if this works.



Thank you,Vijay
  1. Helpful
  1. Vijay Kumar Natarajan
  2. Thursday, 15 February 2024 21:58 PM UTC
Hi John,



I tested by using this external function declarations and could successfully print the label to the printer.

Thank you so much!



For your earlier question, we would like to deploy this application as 64 bit. Do you see any issues on building the application as 64bit?



Thank you,

Vijay





  1. Helpful
  1. John Fauss
  2. Friday, 16 February 2024 04:07 AM UTC
This is terrific news, Vijay!

The external function declarations I supplied SHOULD work in 64-bit, but I have way to verify. As for the rest of your application, I have no idea if you will encounter any additional issues. However, I have two recommendations:

1. Upgrade your PFC libraries. They are available for free download on Github: https://github.com/OpenSourcePFCLibraries

2. Thoroughly review the entire contents of the "Migrating 32-bit Applications to 64-bit" publication and follow all of the instructions:

https://docs.appeon.com/pb2022r3/migrating_32bit_applications_to_64bit/index.html



Would you please mark this question/issue as resolved? Many thanks.
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Wednesday, 14 February 2024 22:13 PM UTC
  2. PowerBuilder
  3. # 2

Hi, Vijay -

1. Are you running the app in PB 2022 R2 in 32-bit or 64-bit? If you are attempting to migrate to 64-bit, try 32-bit first.

2. What version of the PFC libraries are you using?

3. Is the code that calls these API functions part of the PFC objects and if so, which PFC objects, or is this code in locally-developed objects?

Best regards, John

Comment
  1. Vijay Kumar Natarajan
  2. Wednesday, 14 February 2024 22:57 PM UTC
Hi John Fauss,



Thank you for your review on this request.



My final target is to upgrade the application(PB12.5 with PFC) to PB 2022. But now I am currently testing only the label printer basic functionality to get a printed result. For this use case, I have created a simple new application in PB2022 and copied the required function to test this label printing.



In my current testing scenario, I have not added the PFC objects at all. I declared the required local external functions (winspool.drv) and then testing the communication with printer from PB2022 Version.



Please let me know if I am on correct direction for this testing.
  1. Helpful
  1. John Fauss
  2. Thursday, 15 February 2024 00:54 AM UTC
Thanks for the answers! You did not answer one very important question: Are you currently or will you eventually be running the app with this printing functionality in 64-bit?
  1. Helpful
There are no comments made yet.
Vijay Kumar Natarajan Accepted Answer Pending Moderation
  1. Wednesday, 14 February 2024 21:46 PM UTC
  2. PowerBuilder
  3. # 3

Hi Chris,

Yes, the application uses PFC Framework.

I understand this issue should not be because of PFC Framework. But can you please confirm.

Thanks.

Comment
  1. Chris Pollach @Appeon
  2. Wednesday, 14 February 2024 22:16 PM UTC
HI Vijay;

Thanks .. yes, I was suspicious as I seem to remember that this code once existed but was removed in newer releases of the PFC. I am not a PFC expert - so maybe one of the PFC guys can confirm this?

FYI: https://github.com/OpenSourcePFCLibraries

Of course, you can always download the current PFC for PB 2022 and do a quick search for this code to confirm. If that code is no longer there, then you need to upgrade your old PFC framework. HTH

Regards .. Chris
  1. Helpful
  1. John Fauss
  2. Wednesday, 14 February 2024 22:33 PM UTC
I do not see any of these external function declarations in the 2022 version of the PFC libraries. If Vijay will answer the questions in my separate response post, I can quickly confirm that.
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 14 February 2024 21:24 PM UTC
  2. PowerBuilder
  3. # 4

HI Vijay;

  Is your App(s) using the PFC Framework?  I ask this because this sounds like old PFC code.

Regards .. Chris

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.