'Create A DLL to work on a solution targeting Master ARM64? (Hololens 2)

I develop applications targeting the Hololens 2 platform (mixed reality). The general idea of the application I am trying to build is using a point cloud registration algorithm, which targets a previously scanned model on one hand and the visible point cloud generated by the Hololens' SceneUnderstanding ability on the other.

My main problem is that all the different implementations that I found of the algorithm are using libraries (DLLs) that:

  1. Uses a lower-level language (C++) than the C# scripting language used in Unity's scripts.
  2. Are not targeting the needed configuration and architecture needed for deploying an application on the Hololens 2 (Master configuration, ARM64 architecture).

In the process of trying to generate that kind of library myself (using visual studio 2019 to build "Dynamic-Link Library with Exports [DLL]"), I created the simplest library in C++ - A single function that returns an integer (without the dependency of any other library). Obviously, when targeting the Unity Editor application it was easy to use the library's function from the C# script attached to the Unity project, but when I try to convert the solution's configuration and architecture to Master ARM64, building a Visual Studio solution and deploying the application on the Hololens 2 generates a script error: "Unable to load DLL '<dll_name>': The specified module could not be found."

I can think of two major reasons that will cause this problem:

  1. The program can not find the library needed for function execution, JUST BECAUSE the location of the library is not correct (I have NO IDEA where the library should be placed in the solution hierarchy).

  2. I am probably not using the right technique for converting the library to the correct target solution properties (in addition of the previous scenario) (and as well, I have no idea what is the correct procedure for achieving correct targeting properties)

Using: Visual Studio 2019, Unity 2019.4.1f1, Hololens 2nd generation

It would mean a lot to hear from anyone who have encountered any sort of similar problem, thank you in advance!



Solution 1:[1]

To add a custom DLL to a Unity project for HoloLens 2, you have to copy the DLL to a folder called Assets/Plugins/WSAPlayer/ARM64 in your project hierarchy in Unity. Then, you should also make sure that the correct Platform settings are specified for the Plugin in the Inspector, i.e., SDK should be set to UWP and CPU to ARM64:

enter image description here

This git repo has an example of this (DLL and Unity project).

Note that the DLL has to be compatible with Universal Windows Platform (UWP), so when creating a new library with Visual Studio, you should select either the DLL (Universal Windows) or Windows Runtime Component project templates as your starting point.

If you add any dependencies to your DLL, e.g., for point cloud registration, you will also have to build those libraries for UWP / ARM64, and add those DLLs to the same folder as well!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1