FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index Bugs report & fixes / Informe de errores y arreglos Bug in TPrinter
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Bug in TPrinter
Posted: Sun Aug 10, 2025 01:38 PM
The metafiles are not deleted from the user's temp directory after closing the preview:
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:
#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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Bug in TPrinter
Posted: Sun Aug 10, 2025 02:47 PM

Dear Enrico,

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

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

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Bug in TPrinter
Posted: Sun Aug 10, 2025 02:55 PM
Antonio Linares wrote: Dear Enrico,

How do you know that ferase() returns -1 ?
I put a MsgInfo() here:
Aeval(::aMeta,{|val| MsgInfo(ferase(val)) })
Antonio Linares wrote:If the files are there, why can't they be erased ?
Probably they are still opened.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Bug in TPrinter
Posted: Sun Aug 10, 2025 04:19 PM
This may help:

In Class TPrinter add this method:

DESTRUCTOR Destroy()
PROCEDURE Destroy() CLASS TPrinter

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

return
And remove this from METHOD End():
         Aeval(::aMeta,{|val| ferase(val) })
         ::aMeta  := {}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Bug in TPrinter
Posted: Sun Aug 10, 2025 05:34 PM
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. :-(
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Bug in TPrinter
Posted: Mon Aug 11, 2025 08:29 AM
Found!
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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Bug in TPrinter
Posted: Mon Aug 11, 2025 10:50 AM

Dear Enrico,

Have you tried to use both ?

CloseEnhMetafile( hEMF ) // EMG

DeleteEnhMetafile( hEMF ) // EMG

many thanks

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Bug in TPrinter
Posted: Mon Aug 11, 2025 01:05 PM
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/windows/win32/api/wingdi/nf-wingdi-getenhmetafilea
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Bug in TPrinter
Posted: Tue Aug 19, 2025 05:38 PM

Maestro Enrico, ¿qué versión de FWH tiene este ERROR?

Master Enrico, which version of FWH has this BUG?

Gracias, tks.

Regards, saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Bug in TPrinter
Posted: Tue Aug 19, 2025 06:08 PM

I'm not sure but I think it is always been there.

Continue the discussion