Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Implementing Facebook for UWP. (Or How To Use This DLL/winmd?)

Discussion in 'Windows' started by GarthSmith, Dec 13, 2015.

  1. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    Has anyone done it? I'm attempting to use Microsoft's Windows SDK for Facebook.
    https://github.com/Microsoft/winsdkfb (using develop branch)

    That C++ project gives me a native (not managed) .dll and a managed .winmd. I have the .winmd set to load for Windows Store only, and for it's Mono placeholder the only option I have was the associated .dll.

    Building in Unity 5.2.3p3 gives me this error:

    A couple of questions:
    • Does anyone know how in VS I can build to a single managed DLL instead of this native DLL & managed .winmd? I'm not really familiar with .winmds.
    • I might need to make a dummy plugin for Mono compilation. Is there any way I can tell which classes and functions I need to make dummies for?
    Any help would be greatly appreciated!
     
    Last edited: Dec 13, 2015
  2. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    Some screenshots. Nothing else is in this project.
    Facebookwinmd.png facedll.png faceerror.png
     
  3. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    Going to try sticking my own plugin between Unity and WinSdkFb so Unity doesn't need to know about WinSdkFb at all.
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,464
    If you updated to 5.3, you wouldn't need a placeholder - you'd be able to call into that winmd directly from your scripts wrapper in #if NETFX_CORE/#endif.

    It's fairly complicated to make a placeholder for a winmd, I wouldn't advice going through that.

    If you can't update to 5.3, your best bet is indeed use it through your own managed plugin.
     
  5. kujo

    kujo

    Joined:
    Aug 19, 2013
    Posts:
    106
    Been trying to do this myself with the same Facebook SDK for Windows with little joy. I was getting somewhere building my own managed wrappers around everything and got quite a long way with it. The problem I've found with that SDK is that you can't build for Any CPU, you have to build for each one separately, which is fine. In my 5.2 version I specified the CPU level for each of the wrapping DLLs, and set their CPU accordingly. Since changing to 5.3, changing the CPU isn't an option any more (its greyed out) and so forces it to Any CPU. When I try to build out my project, I then get an error:

    Code (csharp):
    1. Plugin 'FacebookWin81.dll' is used from several locations:
    2. Assets/Plugins/WSA/ARM/FacebookWin81.dll would be copied to <PluginPath>/Plugins/SDK81/FacebookWin81.dll
    3. Assets/Plugins/WSA/x86/FacebookWin81.dll would be copied to <PluginPath>/Plugins/SDK81/FacebookWin81.dll
    4. Plugin 'FacebookWP81.dll' is used from several locations:
    5. Assets/Plugins/WSA/ARM/FacebookWP81.dll would be copied to <PluginPath>/Plugins/PhoneSDK81/FacebookWP81.dll
    6. Assets/Plugins/WSA/x86/FacebookWP81.dll would be copied to <PluginPath>/Plugins/PhoneSDK81/FacebookWP81.dll
    7. Please fix plugin settings and try again.
    I don't really know much about .winmds or how to use them inside the NETFX_CORE wrapper you mentioned, but if I could get the CPU part working again, I'm probably ok?
     
  6. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    I'm in Unity 5.2.3p3 so I haven't had a chance to try 5.3 yet.

    I tried making 3 plugins. For arm, x86, and x64. You can set what architecture the plugin is for in the inspector.
    I tried to make 1 stub dll for Mono to sub in for those. Then three stubs, one for each architecture.

    I wasn't able to get it to work. :(

    I did go through the source and see how the plugin works and have almost implemented it in C# (can authorize and get an access token) but it was difficult and time consuming so Facebook got delayed to our next update.

    As for wrapping code in NETFX_CORE, it's like this.
    Code (csharp):
    1. #if NETFX_CORE
    2. using Some.Plugin.Namespace;
    3. #endif
    4.  
    5. public class SomeClass
    6. {
    7.   public void Connect()
    8.   {
    9. #if NETFX_CORE
    10.     // do stuff using plugin;
    11. #else
    12.     // just pretend to do stuff. don't use plugin;
    13. #endif
    14.   }
    15. }
     
    Last edited: Dec 16, 2015
  7. kujo

    kujo

    Joined:
    Aug 19, 2013
    Posts:
    106
    I was in 5.2 when i got my code working as well and was able to produce the separate binaries for the different architectures, but it's not available in 5.3 annoyingly. Can't figure out what to do. I'll have a look at the netfx stuff tomorrow and see if I can get anything working
     
  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,464
    You have to set the actual ".dll" files to x86/x64/ARM, but the WinMD will always be set to AnyCPU: they're identical for each platform anyway, and only one can be referenced by a C# compiler.

    @Garth Smith: I believe there were some issues in consuming WinMD directly from C# scripts in 5.2. However, if you compiled "SomeClass" into a DLL, it should work.
     
  9. kujo

    kujo

    Joined:
    Aug 19, 2013
    Posts:
    106
     
  10. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,464
    If your DLLs are C#, then they must be AnyCPU and you will not be able to set them to x86/x64/arm. This is because C# compiler can only reference one C# DLL or WinMD file with the same name at a time, so having multiple of them may lead to errors if they differ. The only thing you have to do now is build one instead of 3 DLLs, put it in your project and it should work on any cpu architecture.

    If your DLL is written in C++, you'll have both a WinMD and a DLL file. In this case, WinMD will be set to AnyCPU, because that's what gets referenced by your C# scripts, while the DLL is native code and thus must be CPU architecture specific.
     
  11. kujo

    kujo

    Joined:
    Aug 19, 2013
    Posts:
    106
    Ah - makes sense. I have a C# wrapper for the C++ DLL that Garth mentioned above, but currently I can't build that for Any CPU, because the C++ DLL doesn't allow for it... but, I was using a project reference to the DLL. I guess I can apply that WinMD logic to a normal C# class library? and then build the whole thing for Any CPU?
     
  12. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,464