Page 1 of 1

Bug in TPrinter

Posted: Sun Aug 10, 2025 1:38 pm
by Enrico Maria Giordano
The metafiles are not deleted from the user's temp directory after closing the preview:

Code: Select all | Expand

METHOD End() CLASS TPrinter

   if ::hDC != 0
      DeleteDC( ::hDC )
      if ! ::lMeta
         if ::lStarted
            EndDoc(::hDC)
         endif
      else
         Aeval(::aMeta,{|val| ferase(val) })
The function ferase() returns -1 (ie. error). This is a little sample showing the problem:

Code: Select all | Expand

#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oPrn, oFnt

    PRINT oPrn NAME "Test" PREVIEW
        DEFINE FONT oFnt NAME "Arial" SIZE 0, -12 OF oPrn

        PAGE
            oPrn:Say( 100, 100, "This is a test", oFnt )
        ENDPAGE
    ENDPRINT

    RELEASE FONT oFnt

    RETURN NIL

Re: Bug in TPrinter

Posted: Sun Aug 10, 2025 2:47 pm
by Antonio Linares
Dear Enrico,

How do you know that ferase() returns -1 ?

If the files are there, why can't they be erased ?

Re: Bug in TPrinter

Posted: Sun Aug 10, 2025 2:55 pm
by Enrico Maria Giordano
Antonio Linares wrote: Sun Aug 10, 2025 2:47 pm Dear Enrico,

How do you know that ferase() returns -1 ?
I put a MsgInfo() here:

Code: Select all | Expand

Aeval(::aMeta,{|val| MsgInfo(ferase(val)) })
Antonio Linares wrote: Sun Aug 10, 2025 2:47 pmIf the files are there, why can't they be erased ?
Probably they are still opened.

Re: Bug in TPrinter

Posted: Sun Aug 10, 2025 4:19 pm
by Antonio Linares
This may help:

In Class TPrinter add this method:

DESTRUCTOR Destroy()

Code: Select all | Expand

PROCEDURE Destroy() CLASS TPrinter

   AEval( ::aMeta, {|val| ferase( val ) } )
   ::aMeta = {}

return  
And remove this from METHOD End():

Code: Select all | Expand

         Aeval(::aMeta,{|val| ferase(val) })
         ::aMeta  := {}

Re: Bug in TPrinter

Posted: Sun Aug 10, 2025 4:29 pm
by Enrico Maria Giordano
Same result. :-(

Re: Bug in TPrinter

Posted: Sun Aug 10, 2025 5:34 pm
by Enrico Maria Giordano
And the problem is not the temp directory either. I just tried to create the metafiles in the current directory and got the same error. :-(

Re: Bug in TPrinter

Posted: Mon Aug 11, 2025 8:29 am
by Enrico Maria Giordano
Found!

Code: Select all | Expand

static function PageBitmap( cEMF, nWidth, nHeight )

   local hDC1 := GetDC( GetDesktopWindow() )
   local hDC2 := CreateCompatibleDC( hDC1 )
   local hBmp := CreateCompatibleBitmap( hDC1, nWidth, nHeight )
   local hOldBmp := SelectObject( hDC2, hBmp )
   local hEMF := GetEnhMetaFile( cEmf )

   Rectangle( hDC2, 0, 0, nHeight, nWidth )
   XPlayEnhMetaFile( hDC2, hEMF, 0, 0, nHeight, nWidth )
//   CloseEnhMetafile( hEMF ) // EMG
   DeleteEnhMetafile( hEMF )  // EMG

   SelectObject( hDC2, hOldBmp )
   DeleteDC( hDC2 )
   ReleaseDC( hDC1 )

   AlphaFill( hBmp, 0 )

return hBmp

Re: Bug in TPrinter

Posted: Mon Aug 11, 2025 10:50 am
by Antonio Linares
Dear Enrico,

Have you tried to use both ?

CloseEnhMetafile( hEMF ) // EMG
DeleteEnhMetafile( hEMF ) // EMG

many thanks

Re: Bug in TPrinter

Posted: Mon Aug 11, 2025 1:05 pm
by Enrico Maria Giordano
No, only the second is needed:
When the application no longer needs an enhanced-metafile handle, it should delete the handle by calling the DeleteEnhMetaFile function.
From https://learn.microsoft.com/en-us/windo ... hmetafilea

Re: Bug in TPrinter

Posted: Tue Aug 19, 2025 5:38 pm
by karinha
Maestro Enrico, ¿qué versión de FWH tiene este ERROR?

Master Enrico, which version of FWH has this BUG?

Gracias, tks.

Regards, saludos.

Re: Bug in TPrinter

Posted: Tue Aug 19, 2025 6:08 pm
by Enrico Maria Giordano
I'm not sure but I think it is always been there.