title: Access violation using a C++ function from a DLL
body: <p>I have a game engine written in C++ which I'm porting to Windows (from Mac). It uses C++11 and OpenGL, and for all intents and purposes, it runs!</p>
  
  <p>I'm using a DLL for my game engine which is linked implicitly to the game <code>.exe</code> at runtime. The problem is, when I try to use a utility class from the DLL, <code>FileSystem</code>, to find a resource file (a texture, but I don't think it's important), I get this error:</p>
  
  <p><code>First-chance exception at 0x00007FF9CF988830 (PocoFoundation64.dll) in TestEquinox.exe: 0xC0000005: Access violation reading location 0x000000136A4FF000.</code></p>
  
  <p>The problem comes when I call this method of my <code>FileSystem</code> class from the DLL (it's designed to take a filename/partial path and it looks in various places to find the full path):</p>
  
  <pre><code>Poco::Path FileSystem::Get(const std::string &amp;filename) {
  std::vector&lt;Poco::Path&gt; paths = {
          filename,
          ResourceFolder() / filename //&lt;&lt;&lt;&lt;&lt; ERROR HERE
      };
  
      for (const Poco::Path &amp;path : paths) {
          try {
              if (Poco::File(path).exists()) {
                  return path;
              }
          } catch (...) { }
      }
  
      Logger("FileSystem", std::cerr) &lt;&lt; "Could not find file '" &lt;&lt; filename &lt;&lt; "'!";
      return {};
  }
  </code></pre>
  
  <p>Visual Studio shows the error as being at the call of <code>ResourceFolder()</code>, another method from the same class, also in the DLL. This appears so:</p>
  
  <pre><code>Poco::Path FileSystem::ResourceFolder() {
      Poco::Path userData;
  
      //--SNIP-- (other OS's #ifdef'd here)
      // GAME-&gt;StartupPath is a std::string containing the exe's parent folder
      userData = (Poco::Path(GAME-&gt;StartupPath).parent() / "Resources").makeDirectory();
      //--SNIP-- (and here)
  
      try {
          if (!Poco::File(userData).exists()) {
              Poco::File(userData).createDirectories();
          }
      } catch (...) {}
  
      return userData;
  }
  </code></pre>
  
  <p>From the looks of it, it's to do with <code>Poco</code>'s data types not being instantiated properly? I've built it from source with all the same compiler settings (64-bit, multi-byte character set, VS2013), so I don't see how it could be a name mangling/data layout issue.</p>
  
  <p>One more thing to note - I copied the entire <code>FileSystem</code> class from the DLL to a class local to my game project, called <code>FileSystem2</code>. Calling <code>FileSystem2::Get</code> with the same parameters worked correctly and without crashing, despite being the same code.</p>
  
  <p>Hoping someone can point me in the right direction?!</p>