Search Unity

Using Windows Runtime support with IL2CPP in Unity 2017

Discussion in 'Windows' started by KevinIH, May 28, 2019.

  1. KevinIH

    KevinIH

    Joined:
    May 20, 2019
    Posts:
    5
    I'm looking to use UWP API's with a DLL I develop with VS 2017 and I need to get access to
    'Windows.Foundation.UniversalApiContract' and 'Windows.Foundation.FoundationContract' winmd files.

    I found this manual page and switch my project to UW platform with latests windows 10 sdk (10.0.07763.0).
    I've set the Scripting Backend to IL2CPP, Scripting Runtime Version to Experimental (.NET 4.6) and API Compatibility Level to .NET 4.6. I'm using latest Unity 2017.4.27f1.

    But directive #if ENABLE_WINMD_SUPPORT seems actually false, even with configuration done above.
    I can't access to Windows API from my C# scripts like UnityEngine.Windows.Application.InvokeOnUIThread()

    Any hint on what could be wrong and how could I enable Windows Runtime support ? :rolleyes:
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    How do you determine that ENABLE_WINMD_SUPPORT is false? Does building player work if you do something like this?

    Code (csharp):
    1. #if ENABLE_WINMD_SUPPORT
    2. gfasdlgjaflg
    3. #endif
     
  3. KevinIH

    KevinIH

    Joined:
    May 20, 2019
    Posts:
    5
    The code between the define is greyed out... Also I can't compile project because it complains about The type or namespace name `Windows' could not be found

    My plugin needs 'Windows.Foundation.UniversalApiContract' and 'Windows.Foundation.FoundationContract' that I finally manage to link in VS 2017 project by typing a class from these assemblies and then let Intellisense complete the missing references for me but it's not working for 'Windows.winmd' and I don't know what is the clean way to add such references to my project.
     
  4. KevinIH

    KevinIH

    Joined:
    May 20, 2019
    Posts:
    5
    Ok, I finally understand by looking at this page that UWP API's won't link in Editor at all and code inside the #if ENABLE_WINMD_SUPPORT define will always stay greyed out as it's only available when builded.
    I should also switch from IL2CPP to .NET scripting backend to build without errors.

    Then the required .winmd seems to link correctly in the resulting VS project.
    Not easy to debug now but I will include an UI log tool to help.
     
    sean244 likes this.
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    It should work fine in IL2CPP scripting backend. You don't need to switch to .NET scripting backend.

    You should be able to get intellisense if you change to player project context in VS:

    upload_2019-5-29_14-14-24.png
     
    doughtmw12 likes this.
  6. HosseinArabbeigi

    HosseinArabbeigi

    Joined:
    May 7, 2014
    Posts:
    16
    Hi @KevinIH
    Can explain how did you fix namespace name `Windows' could not be found error?
     
  7. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    What exactly doesn't work for you?
     
  8. HosseinArabbeigi

    HosseinArabbeigi

    Joined:
    May 7, 2014
    Posts:
    16
    Thanks @Tautvydas-Zilys for your response, id did run app on device and there wasn't any problem.