CreateFont / DeleteObject leaves font file locked on application exit

Discussion in 'Win32' started by Peter Dell, Jun 24, 2019.

  1. Peter Dell

    Peter Dell New Member

    Joined:
    Jun 23, 2019
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Hello,

    I use the CreateFont/DeleteObject functions to load/create and release a customer font in my Win32 Application.

    Code:
    hFont = CreateFont(fontHeight, 0, 0, 0, 0, 0, 0, 0, OEM_CHARSET, 0, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXED_PITCH, szFontName);
    ...
    if (hFont != NULL) {
    
            BOOL bResult = DeleteObject(hFont);
    
            hFont = NULL;
    
            if (!bResult) {
    
                throw new std::runtime_error("Cannot delete font");
    
            }
    
        }
    
    The DeleteObject correctly returns "1 = success", but even after the WinMain() of the application has ended and the application is terminated, the font file (in a subdirectory besides the .exe) remains locked and causes problem when the next build tries to overwrite it.

    Do you have any ideas why or what I could do differently to fix this?

    Best regards, Peter.
     
  2. sarasara

    sarasara New Member

    Joined:
    Jan 19, 2021
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Female
    Location:
    tehran
    Home Page:
    https://www.mmsiz.com/
    I have same problem and I like to find solution
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice