Search Unity

How do I Call MainPage.xaml.cpp function from Unity C# script [UWP]

Discussion in 'Windows' started by StarGamingNetwork, Oct 1, 2020.

  1. StarGamingNetwork

    StarGamingNetwork

    Joined:
    Feb 2, 2015
    Posts:
    16
    How would I call a function defined in MainPage.xaml.cpp from a script in Unity with il2cpp for UWP?

    Such as...



    bool TheBool = false;

    bool MainPage::GetBool()
    {
    return TheBool;
    }


    I believe I need a cpp file in the plugins folder. I just have no idea what would go in it.

    I have in my script:

    [DllImport("__Internal")]
    private static extern bool GetBool();


    And in MainPage.xaml.cpp:



    bool TheBool = false;

    extern "C" __declspec(dllexport)
    bool __stdcall MainPage::GetBool()
    {
    return TheBool;
    }




    Any help would be appreciated.
     
    Last edited: Oct 2, 2020