First published on MSDN on Sep 24, 2018
Let's use and continue the work done in the previous article
Using Windows Universal Runtime APIs from a standard Unity executable
. The context was: We are developing a game or an app using Unity and we build directly an executable (not an UWP application). How can we use the UWP APIs? I gave an answer which was:

We create a C# .NET dll that calls the UWP APIs.

We use the compiled dll as a Unity Plugin and we build the Unity project as a standard Windows executable.

:man_technologist: Modify the C# .NET dll to use others UWP APIs

C# code for Live tiles

So for the code modification inside the C# .NET dll project. You can do what you are used to do inside classic dll project on Windows. The only pre-requisite is to preced the method with a 'DllExport' in order to make this method visible from the Unity script:
[DllExport(CallingConvention.StdCall)]

Compile the C# .NET dll

The last steps on the dll project is to compile using
RELEASE
and
x64
.

Note the output folder of the dll because you will have to copy it to the Unity project's folder. Generally it is something like
\bin\x64\Release
.

:video_game: Modify the Unity app to use the updated .NET dll

Copy the new C# .NET to the Unity project

The first step is to update the C# .NET dll already in the
\Assets\Plugins
folder of the Unity project. To do this, just copy/paste the dll from the C# .NET dll project (
\bin\x64\Release
) to the Plugins folder of the Unity project (
\bin\x64\Release
).

Update the Unity script to call the new method

In order to inform Unity about the new methods available you just have to do a kind of 'copy/paste' of the method declarations with
DllImport
and
extern static
before. Especially if you use simple types for parameters. Here are examples:
[DllImport("dotNETClassLibraryUsingUWPAPIs")]
extern static string NotifyWithDelay(string toastTitle, string toastContent, int delayinMilliseconds);

And you are done! To call the method, just use them in the script:
void Update()
{
if (Input.GetKeyDown(KeyCode.S))
{
string output = NotifyWithDelay("Schedule Toast title",
"Unity toast sent at " + System.DateTime.Now.ToLongTimeString(), 5000);
}

Conclusion

Using a C# .NET dll project and exporting methods is a great and easy way to provide UWP APIs access to apps that are not UWP native apps. Take some time to create you C# .NET dll project with all "piping" and you will able to use lots of UWP Sample code!