Bug in TPrinter

Post Reply
User avatar
Enrico Maria Giordano
Posts: 9053
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 43 times
Contact:

Bug in TPrinter

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 44508
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 717 times
Been thanked: 311 times
Contact:

Re: Bug in TPrinter

Post by Antonio Linares »

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
User avatar
Enrico Maria Giordano
Posts: 9053
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 43 times
Contact:

Re: Bug in TPrinter

Post 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.
User avatar
Antonio Linares
Site Admin
Posts: 44508
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 717 times
Been thanked: 311 times
Contact:

Re: Bug in TPrinter

Post 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  := {}
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Enrico Maria Giordano
Posts: 9053
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 43 times
Contact:

Re: Bug in TPrinter

Post 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. :-(
User avatar
Enrico Maria Giordano
Posts: 9053
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 43 times
Contact:

Re: Bug in TPrinter

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 44508
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 717 times
Been thanked: 311 times
Contact:

Re: Bug in TPrinter

Post by Antonio Linares »

Dear Enrico,

Have you tried to use both ?

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

many thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Enrico Maria Giordano
Posts: 9053
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 43 times
Contact:

Re: Bug in TPrinter

Post 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
User avatar
karinha
Posts: 8716
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Has thanked: 33 times
Been thanked: 51 times
Contact:

Re: Bug in TPrinter

Post 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.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
Enrico Maria Giordano
Posts: 9053
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 43 times
Contact:

Re: Bug in TPrinter

Post by Enrico Maria Giordano »

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