Search code examples
c++dlluwpdllimportxbox

LoadPackagedLibrary failes with ERROR_MOD_NOT_FOUND on XBox


i'm currently trying to load a self-written dynamic link module (Compiled with /ZW /EHsc) in an UWP app using the LoadPackagedLibrary(...) function. It is required to load all libraries dynamically due to the way the libs are build. I have included the DLL within the project and enabled it as content (Also verified: it at least gets copied to the XBox like expected).

In case I run my application on Windows everything works fine as expected. But as soon as I launch my application on the XBox LoadPackagedLibrary(...) failed with ERROR_MOD_NOT_FOUND. In the Visual Studio output window, I can see that the XBox is loading my DLL with no problems but directly discards it after loading it:

"DAServerUWP.exe" (Win32): "D:\DevelopmentFiles\<<MYAPP>>\SampleDAClient.dll" geladen. Symbole wurden geladen.
"DAServerUWP.exe" (Win32): "D:\DevelopmentFiles\<<MYAPP>>\SampleDAClient.dll" wurde entladen.

I suspect it has something to do with the Package.appxmanifest not properly (or currently not at all) specifying the DLL. But I didn’t find that much information online nor did any of the proposed solutions work.

Edit: Here are the lines how the DLL is defined in the .vcxproj:

<ItemGroup>
   <None Include="SampleDAClient.dll">
      <DeploymentContent>true</DeploymentContent>
   </None>
</ItemGroup>

Edit2: Probably it has something to do with dll dependencys. Theses are my libs dependencys:

Desktop_To_UWP_dll

which look totaly different when compared to an native UWP dll:

Native_UWP_dll


Solution

  • To compile a UWP DLL you need to pass these arguments to the compiler:

    /D__WRL_NO_DEFAULT_LIB__ /DWINAPI_FAMILY=WINAPI_FAMILY_APP /MD
    

    And these linker flags:

    /APPCONTAINER /NODEFAULTLIB:ole32.lib /NODEFAULTLIB:kernel32.lib /NODEFAULTLIB:user32.lib /NODEFAULTLIB:msvcrt.lib windowsapp.lib
    

    Furthermore, you need to specify a different LIBPATH to the linker. Instead of this:

    /LIBPATH:<VSDIR>\VC\Tools\MSVC\<MSVC_VERSION>\lib\x64
    

    You need to use pass this LIBPATH to the linker:

    /LIBPATH:<VSDIR>\VC\Tools\MSVC\<MSVC_VERSION>\lib\x64\store