1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

    Jun 23, 2019
    Likes Received:
    Trophy Points:

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

    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.

Share This Page