简体   繁体   中英

Including a third-party DLL in a UWP application - step by step?

I'm trying to include a third-party DLL in a Universal Windows Platform app in Visual Studio 2017. Specifically, I downloaded the Autodesk FBX SDK (Visual Studio 2015 UAP version from: http://usa.autodesk.com/adsk/servlet/pc/item?id=24746731&siteID=123112 ), which contains .lib and .dll files for my platform.

I add the relevant .lib (x86/release or x86/debug) to my Additional Dependencies in Visual Studio but am unsure how to make the app aware of the DLL. Building an app package fails and trying to run the program directly fails at run-time presumably when the DLL fails to load.

I've spent a lot of time reading about UWP but I'm completely baffled by its complexity and opacity. I'm assuming I need to somehow:

  1. Copy the DLL into my Visual Studio project directory. But where? And how do I get Visual Studio to acknowledge it? I can add it as Content of type Document in the Solution Explorer but it doesn't seem to get picked up by the build.

  2. I've been told by MS support ( https://social.msdn.microsoft.com/Forums/windowsapps/en-US/26013e5e-3ff1-44a0-8797-0474dabd12d0/including-dlls-in-a-uwp-application-in-visual-studio?forum=wpdevelop ) that I need to add it as a package dependency to the Package.appxmanifest file, but I can't find any example of how exactly to do this.

And just to be clear: I don't have the source code for this DLL. Pretty sure it's a UWP-built DLL. I just want it to be recognized by my project and exported to the app package when I create it. Yes, there is a static library I can link against that works but sooner or later, I am going to need a DLL-only library and will have to learn to get this right. I would think there is a guide at MSDN for how to do this but hours of searching have yielded nothing :(

Thank you,

Bart

Aman Sharma: Thank you. But adding references doesn't appear to work (it doesn't like DLL files). I did however manage to get it working as follows:

  1. "Add -> Existing item..." to the project root.
  2. Right click on the dll file, select Properties, and mark the file as content by setting Content to True.

That's it. Strangely, the FBX SDK docs claim that FBXSDK_DLL must be defined but doing that will cause compilation to fail.

Also, somewhat annoyingly, the DLL file must be in the project root. It cannot be moved to a sub folder (say, Assets/ or DLL/ or whatever). Maybe there is a way to specify the path in the manifest?

Either way, simply adding it and marking it as content does not create a dependency in the manifest file, as I was told was needed on an MSDN forum.

I edited project file(*.vcxproj) directly like the following. That works for me.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  ... other settings ...

  <ItemGroup>
    <Content Include="..\Path\To\$(PlatformTarget)-$(Configuration)\some.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

</Project>

See also Referencing C Dlls from Windows 10 Universal App Across CPU Architectures

Just figured it out myself, when you add some 3rd party project (dll, say TreeViewControl) in your solution.

You need to right click on your project -> Add -> Reference, go to Projects , Solution, check the box left of name of the 3rd party project (TreeViewControl in this example) and recompile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM