title: FreeLibrary() causing access violation error?
body: <p>I have a wrapper class that wraps functions in an DLL.  Naturally, I use <code>LoadLibrary</code> and <code>FreeLibrary</code> to load and free the DLL. When my wrapper management object gets created, it runs a <code>Startup()</code> function:</p>
  
  <pre><code>//at the top
  #define AVTCAM_DLL_NAME (L"VimbaBridgeAPI.dll")
  
  //startup()
  void CAVTcamDllWrapper::Startup()
  {
      mAVTCamLibrary = LoadLibrary(AVTCAM_DLL_NAME);
      if(mAVTCamLibrary == NULL)
      {
          //report an error
      }
  }
  </code></pre>
  
  <p>Then, when the wrapper manager gets deleted, it calls the shutdown function in its destructor:</p>
  
  <pre><code>void CAVTcamDllWrapper::Shutdown()
  {
      if(mAVTCamLibrary != NULL)
      {
         FreeLibrary(mAVTCamLibrary);
         mAVTCamLibrary = NULL; //for extra safety
      }
  }
  </code></pre>
  
  <p><strong>Here is my problem:</strong> the camera I am working with can startup just fine.  The problem is during the shutdown, and more specifically, during the <code>FreeLibrary()</code> call.  As soon as the FreeLibrary gets called, the next line of code always fails.  </p>
  
  <p>In this case, my debugger shows that it executed FreeLibrary and it jumps to the <code>mAVTCamLibrary = NULL;</code> line, then that line will result in an <em>Access Violation Error</em>.        </p>
  
  <p>If I get rid of the <code>mAVTCamLibrary = NULL;</code> line (which I did at first because I thought this line was causing the error), then whatever my debugger jumps to after the FreeLibrary() causes an access violation error.</p>
  
  <p>I cannot figure out why I get these errors right after calling FreeLibrary().  Anyone have an idea?</p>