DLL unloading procedure
<p>I did solve my immediate problem at hand, but now I need to understand why it is solved. ;-)</p>

<p>So here I have couple more questions.</p>

<p>Suppose I have a class that is being exported from the DLL. Now this DLL should be loaded into the memory every time I call:</p>

<pre><code>MyExportedClass *pb = new MyExportedClass;
</code></pre>

<p>and it should stay in memory and becomes unloaded only when I call:</p>

<pre><code>delete pb;
</code></pre>

<p>Is this correct?</p>

<p>If I understood this correctly and the answer to the previous question is yes, then what should happen in the following scenario:</p>

<p>I have an interface which exported from the dll (dll1) and I have its implementation which is exported from another dll (dll2). So every time I execute:</p>

<pre><code>MyInterface *pInterface = new MyImplementation;
</code></pre>

<p>both those dlls should be loaded in memory and they should stay in memory until I call:</p>

<pre><code>delete pInterface;
</code></pre>

<p>Is this correct?</p>

<p>Now, if the answer to this question is yes - do I have a control/saying, which library will be unloaded first and which one will be second? Or the unload will always happen right after calling destructor of the appropriate class?</p>

<p>Now, is there a tool which checks if the library becomes unloaded and at which point? I can probably just use the fake DllMain() and check its process_detach case, but my impression always was: use DllMain when the library exports function and don't use DllMain when the library exports classes. I used this approach since MSVC 5/6 (following one of the books about C++).</p>

<p>Was I wrong and I can still use DLLMain in both cases?</p>

<p>Thank you.</p>