title: Using DLLs wrapping Windows PackageManager in MinGW
body: <p>In an attempt to incorporate a windows platform feature into an otherwise crossplatform application, I've made a one-function VC++ DLL in visual studio that uses Windows.Management.Deployment.PackageManager to get some details on all installed windows store apps.</p>
  
  <p>The function works fine as a standalone application, and I can successfully build the DLL with MSVC that links properly with my MinGW main application (I can happily return primitive data from the dll, etc) - but any attempt to execute a function from the dll containing code relating to PackageManager crashes my application in runtime with the unhelpful code -529697949.</p>
  
  <p>Here's some minimal code blocks that replicate:</p>
  
  <p>main.cpp in the main application:</p>
  
  <pre><code>#include &lt;QCoreApplication&gt;
  #include "mylib/WindowsAppsLib.h"
  #include &lt;QDebug&gt;
  
  int main(int argc, char *argv[])
  {
      QCoreApplication a(argc, argv);
      auto hi = (Helpers::sayHi());
  
      qDebug() &lt;&lt; (hi);
  
      return a.exec();
  }
  </code></pre>
  
  <p>dll header:</p>
  
  <pre><code>#pragma once
  #define WINDOWSAPPSLIB_API __declspec(dllexport)
  
  namespace Helpers
  { 
  extern "C" WINDOWSAPPSLIB_API const char* sayHi();
  }
  </code></pre>
  
  <p>dll source:</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;sddl.h&gt;
  #include &lt;collection.h&gt;
  #include "WindowsAppsLib.h"
  #include &lt;windows.h&gt;
  
  #using &lt;Windows.winmd&gt;
  using namespace Platform;
  using namespace Windows::Foundation;
  using namespace Windows::Foundation::Collections;
  using namespace std;
  
  const char* Helpers::sayHi()
  {
      auto packageManager = ref new Windows::Management::Deployment::PackageManager();
      auto packages = packageManager-&gt;FindPackages();
  
      return "Hi!";
  }
  </code></pre>
  
  <p>Without the two lines relating to packagemanger, the program runs fine and prints "Hi!".  When included, the program crashes with code -529697949 as soon as sayHi() is called.  The two lines in themselves have their dependencies available and don't cause exceptions.</p>
  
  <p>Any clues on how I might proceed to investigate this?  Nothing I've been able to get out of this system is getting me closer to identifying the problem.  Is this the sensible way to access Windows.Management.Deployment.PackageManager from within a plain C++ MinGW application to begin with?</p>