Visual Studio 2013/2015:
I have a blank C++ Windows Store App and the simplest possible DLL in the same solution only exporting void foo() {}
.
Using this DLL in e.g. a Win32 console application works as intended with the DLL's header included and the *.lib file added to the linkers dependencies.
However trying to use this DLL in the Windows Store App gives me an exception at program start, the message box Unhandled exception at 0x77F0E052 (ntdll.dll) in App5.exe: 0xC0000135: Unable to Locate DLL.
and the following output in the Debug console:
'App5.exe' (Win32): Loaded 'C:\Users\naitsirhc\Documents\Visual Studio 2015\Projects\App5\Debug\App5\AppX\App5.exe'. Symbols loaded.
'App5.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'App5.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'App5.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
First-chance exception at 0x77F0E052 (ntdll.dll) in App5.exe: 0xC0000135: Unable to Locate DLL.
Unhandled exception at 0x77F0E052 (ntdll.dll) in App5.exe: 0xC0000135: Unable to Locate DLL.
The program '[4168] App5.exe' has exited with code 0 (0x0).
Now, if I simply add the DLL as reference to the Windows Store App (via Properties -> Common Properties -> References) then it works.
I compared the command lines for the compiler and the linker and they were identical.
What am I missing? There are a number of examples on the web but all but one simply added the *.lib file to the linker's dependencies and that is what I would prefer to do too.
You need to include the DLL as content in the appxpackage. Adding it as a reference will do so automatically, but you can also explicitly set it as content. Add the DLL to the project so it shows up in Solution Explorer. Right click on the DLL in solution explorer and select properties. In the properties pane set the DLL's Content to "True":
This is a deployment setting not a build or link setting, so it won't affect the arguments to the compiler or the linker. The project file will be updated to include something like:
<ItemGroup>
<None Include="Foo.dll">
<DeploymentContent>true</DeploymentContent>
</None>
</ItemGroup>
And that will cause the DLL to be included in the deployment appxpackage.