Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>Memory never passes the DLL barrier</p> </blockquote> <p>But, it does. Many times in fact. Your application created the storage for the class object, in this case on the stack. And then passes a pointer to the methods in the library. Starting with the constructor call. That pointer is <em>this</em> inside the library code.</p> <p>What goes wrong in a scenario like this one is that it didn't create the correct amount of storage. You got the VS2012 compiler to look at your class declaration. It uses the VS2012 implementation of std::map. Your library however was compiled with VS2010, it uses a <strong>completely</strong> different implementation of std::map. With an entirely different size. Huge changes thanks to C++11.</p> <p>This is just complete memory corruption at work, code in your application that writes stack variables will corrupt the std::map. And the other way around.</p> <p>Exposing C++ classes across module boundaries are filled with traps like that. Only ever consider it when you can guarantee that everything is compiled with the exact same compiler version and the exact same settings. No shortcuts on that, you can't mix Debug and Release build code either. Crafting the library so <em>no</em> implementation details are exposed is certainly possible, you have to abide by these rules:</p> <ul> <li>Only expose pure interfaces with virtual methods, argument types must be simple types or interface pointers.</li> <li>Use a class factory to create the interface instance</li> <li>Use reference counting for memory management so it is always the library that releases.</li> <li>Nail down core details like packing and calling convention with hard rules. </li> <li>Never allow exceptions to cross the module boundary, only use error codes. </li> </ul> <p>You'd be well on you way to write COM code by then, also the style you see used in for example DirectX.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload