Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5974871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:00:10+00:00 2026-05-22T21:00:10+00:00

Question I have a third-party DLL that throws an unhandled exception when attempting to

  • 0

Question

I have a third-party DLL that throws an unhandled exception when attempting to unload it from my native C application. This results in the call to FreeLibrary failing, and the module remaining loaded in my process.

Are there any options to forceably unload the library?

What do you do when the FreeLibrary calls?

Additional Background

When using load-time dynamic linking this is annoying enough, but ultimately the application gets torn down by the OS. The problem comes when using run-time dynamic linking. I load up this DLL, use it, and then in some instances I need to unload it from my process’s virtual address space and then continue running. When I call FreeLibrary on the third-party library, it does some cleanup work (i.e. in DllMain when DLL_PROCESS_DETACH is called). While it’s doing it’s cleanup, it causes an exception to be thrown which it doesn’t handle, and bubbles up as an unhandled exception to FreeLibrary. This results in the call failing and the module remaining loaded.

I’ve put a ticket in with the vendor so hopefully I can get a fix which will allow this specific library to unload successfully. In case I don’t however, and for the general case of this issue, I’m curious as to what the options are.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:00:11+00:00Added an answer on May 22, 2026 at 9:00 pm

    If you are after only unloading dll from the memory you can use

    UnmapViewOfFile

    providing bases address of your loaded dll as an argument.

    Example:

    HINSTANCE hInst = LoadLibrary( "path_to_dll" );
    
    if( !FreeLibrary( hInst ) )
    {
       fprintf( stderr, "Couldn't unload library. Error Code: %02X\n. Attempting to unmap...", GetLastError() );
       if( !UnmapViewOfFile( hInst ) )
       { 
         fprintf( stderr, "Couldn't unmap the file! Error Code: %02X\n", GetLastError( ) );
       }
    }
    

    Or if it’s a library that you didn’t explicitly load (e.g. a library dependency that was loaded by a library that you loaded) and you don’t have the handle, then use GetModuleHandle:

    HINSTANCE hInst = GetModuleHandle( "dllname_you_didn't_load" );
    if( hInst != NULL )
    {
       if( !UnmapViewOfFile( hInst ) )
       { 
         fprintf( stderr, "Couldn't unmap the file! Error Code: %02X\n", GetLastError( ) );
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this strange issue with some third party DLL's. The third party provider
Question: I have a question that is apparently not answered by this already-asked Bash
From a previous question I have seen that the CLR has workstation and server
I have a Windows Mobile program that accesses an attached device through a third-party
Hi Everybody, I have a third party library that contains an error. When I
The responses I've got to this question have solved the problem I had in
Question I have an application written in Java. It is designed to run on
Question We have a large number of xml configuration files that we want merged
This is a question I have wondered about for quite some time, yet I
Another basic Rails question: I have a database table that needs to contain references

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.