Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How do you use a Native Plugin with Universal Windows Platform?

Discussion in 'Windows' started by byronIVAI, Aug 30, 2023.

  1. byronIVAI

    byronIVAI

    Joined:
    Dec 16, 2021
    Posts:
    2
    I have been working the universal windows platform and the HoloLens and I have been hoping to make use of a native plugin with the eventual goal of streaming video and audio. I originally used this tutorial:
    Working with Native Plugins - 2019.3 - Unity Learn
    Which allowed me to create a plugin which works fine on a normal windows machine. My first thought would be that you would recompile for ARM64 and have it work the same. I understand that different APIs exist, but since it was supposed to be the simplest case of adding two numbers, I was hoping it wouldn't matter. The project builds, but when the function is seems to exit as soon as it comes to the DLL code in the build. Despite visual studio being attached no exceptions seem to be thrown so I am unsure as to what the exact issue is.
    I have had a look at this:
    How to: Use existing C++ code in a Universal Windows Platform app | Microsoft Learn
    However, I can't figure out how to make use of the Giraffe example. I have made a windows runtime component, but the syntax seems to link into unity seems to be different. I have the same issue with this dll in the build, so I tried to build to x64 to test in the unity editor:

    I have tried this syntax for instance:

    [DllImport("GiraffeDll")]
    private static extern IntPtr Create();

    To call the giraffe factory function called create which is marked with the export macro in the example code.

    I get a:
    DllNotFoundException: GiraffeDll assembly:<unknown assembly> type:<unknown type> member:(null)
    UseDllGiraffe.OnEnable () (at Assets/Plugin Scripts/UseDllGiraffe.cs:38)

    Am I missing something obvious here?
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,628
    The main thing you have to make sure is when you're creating a DLL project in Visual Studio, it targets "Universal Windows Platform" instead of "Windows Desktop":

    upload_2023-8-30_9-21-21.png

    You don't need to use Windows Runtime component unless you need specific functionality from that type of project. But from what I read in your post, you don't need that.
     
  3. byronIVAI

    byronIVAI

    Joined:
    Dec 16, 2021
    Posts:
    2
    When I remade the dll project with the different template it worked as expected no giraffes required. Thanks for the quick reply.