Problems referencing Facebook SDK C# WP8 from C++ Windows Phone 8 app - c#

I try to reference facebook.dll - wp8 branch - within an app of type "Windows Phone Direct3D App (Native only)" project under Visual C++ VS2012, and I get the error:
a reference to [dllname] cannot be added because the two projects
target different runtimes.
The restriction is that I cannot change the architecture of the application, so the main entry-point must be in the C++ project, and from here to call somehow the code written in C# for facebook.
Based on http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj714080(v=vs.105).aspx , I tried also to reference the C# dll indirectly through a Visual C++ "Windows Phone Runtime Component" but again I get the same error. I tried to change some project settings and nothing worked. Trying to consume C# dll in C++, in all samples and demos which I found on the web, for wp8, the main entry-point is always in C#. Only some hints regarding windows store apps seem to indicate that could be possible to consume C# from C++, but I don't find any reference saying explicitly that my scenario on wp8 is possible or impossible.
How can I use facebook SDK from my WP8 app? Or what options I have?
Thanks in advance to anybody which shares the solution or any suggestion

C++ projects can't just invoke any C# DLL in WP8. You'll have to change how the class is built. Start a new C# XAML + C++ D3D project and have a look at IDrawingSurfaceManipulationHandler and Direct3DInterop. Basically you'll have to recreate and recompile the Facebook C# SDK to use it in WP8 C++.
However, installing and using the Facebook SDK on WP8 C# projects works OK on my machine. Have you considered usign a mixed C# and C++ project? It does have a small perf hit, but as long as you use DrawingSurfaceBackgroundGrid you should still have relatively good perf.

Related

Visual Studio .Net Developer : How do I structure an android studio project

I am now starting to learn android development.
I made a small app in visual studio using xamarin (C#) and I wanted copy it to android studio so I can also learn a new language and a new IDE.
I currently have a solution (App.sln) under that I have the main project (App.csproj) and also a class library project to hold my classes (App.Model.csproj)
In android studio, do I create a new module and call it com.app.model or do I just create a new package in the main module?
If you are currently using Xamarin Native approach, the porting from C# to Android Java should be quite straight forward because most of the API is still the same name. The difference mostly is just TitleCase in C# but camelCase in Java. Also, you will need to rename Android layout file from *.axml to *.xml.
If you are using Xamarin.Forms approach, then you will not able to port to Java easily because the API is totally different compare to native Android now. Xamarin.Forms is having its own API set that mapped back to individual native platform's API.
Checking out native Android tutorial will help you to understand better. However, why you want to go back to native when you already know about Xamarin. I came from Android native background and I didn't look back into native since I started with Xamarin.

A very complicated workaround for using a C# dll with an Android app? (xamarin)

I have an proprietary Android app (created with Android Studio) and I need to add some functionality which requires to use a C# DLL.
The app is connecting wirelessly to a development board that does some sensor measurements. Normally on windows apps the dll is used to do some complex calculations of calibration coefficients for the measuring.
My problem is:
I don't have the the source code of the DLL and most likely I won't be approved to access it.
I've read that you can use xamarin to make android apps and use C# dlls but I can't rewrite the whole app for xamarin just to use the dll (also I've never used xamarin)
So far I had the idea to build a simple http server with C# that gets parameters with a GET request, runs them through the dll and returns the results. However it's not an ideal solution because it requires a separate pc to run the server and the adndroid device to have a network connection to it.
My second idea is to build a separate app with xamarin that uses the dll and make my main app start it just to calculate the coefficients and get the results. Perhaps make the second app not visible in the launcher and somehow distribute the two apps together.
Since I am not experienced with android development and especially xamarin and I don't have a lot of time to waste on this project I want to know if my idea is feasible or if there is a better alternative.
Can you suggest some useful tutorials for xamarin and using dlls with it?
===============================================
Edit
I have managed to get the source code of the dll project which is in C++ (and full of windows only stuff) and now I'm trying to use NDK to compile it and JNI with Android studio to use the native functions. Unfortunately almost every step has it's own quirks and problems and it's far from smooth :/ I wouldn't recommend it to beginners like me!
I know this answer is late, but I'm in a similar situation right now.
This project here helped me setup a native Android Studio build with an embedded C# lib:
https://github.com/royd/KotlinAppWithXamarinDependency
The only issue I'm facing right now, that I can't get the R8 obfuscation/optimization to work without breaking the app.

Consume C# dlls in C++ for Windows Phone 8

I have a windows phone 8 app created with Visual Studio 2012 - "Windows Phone Direct3D App (Native only)" project under Visual C++, and a library created with "Windows Phone Class Library" project under Visual C# group having target platform "Windows Phone OS 8.0". All I need is to consume the C# dll in the C++ code. The restriction is that I cannot change the architecture of the application, so the main entry-point must be in the C++ project, and from here to call somehow the code written in C#.
If I try to reference the C# dll in C++ app I get this error
a reference to [dllname] cannot be added because the two projects
target different runtimes.
Based on http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj714080(v=vs.105).aspx , I tried also to reference the C# dll indirectly through a Visual C++ "Windows Phone Runtime Component" but again I get the same error when I try to add reference to the runtime component. I tried to change some project settings and nothing worked.
In all samples and demos which I found on the web, for WP8, the main entry-point is always in C#. Only some hints regarding windows store apps seem to indicate that could be possible to consume C# from C++, but I don't find any reference saying explicitly that my scenario on wp8 is possible or impossible.
Thanks in advance to anybody which shares the solution or any suggestion.
Late answer, but the short story is that you can't. In Windows 8 C# WinRT dlls are full WinRT dlls that can then be consumed by any framework (WinJS, Native etc.) but not so for the phone.
On the phone C# can consume C++ WinRT objects (from C++ dlls), but not vice versa. You can create trickery by having your C# dll call into your C++ dll and pass around function pointers, but that's about it.
I've liked this: http://www.developer.nokia.com/Community/Wiki/C%2B%2B_support_from_Windows_Phone_8 . You may inject an interface into the .winmd C++ side metadata, that could be referenced and implemented in C#. Much cleaner than using delegates ... Still have to be initiated from C# ...

Could not add reference to WinRT C++ DLL project

THE SCENARIO:
I am making a [edit: native WinRT] C++ Direct X DLL project for Windows Store apps based on the "Direct3D App" Visual Studio code sample.
This must be a separate DLL project from my Windows Store App project because I will be using my XAML UserControl with Direct X renderer inside it both in the Windows 8 Metro app and a Windows Phone version of the app.
THE PROBLEM:
I cannot reference the C++ project in the C# Windows Store app project. Visual Studio refuses with the following words:
A reference to <project-name> could not be added.
I've seen suggestions to compile the C++ project using the /clr flag, but this is not compatible with:
the /ZW flag required by some API within the project
the "wrl.h" header
a multitude of other command-line flags in the project settings
So the /clr flag does not appear to be an option in this situation.
THE QUESTION:
How can I reference the C++ project so that I can use my XAML Direct X renderer within the C# Windows Store App project? Or is there a better alternative?
Thanks in advance.
I solved the problem by re-creating the C++ project as a Windows Runtime Component project. I had originally created the project from the Class Library (Windows Store apps) template. It must be that the Win RT template has some configuration settings which enable it to work.
After making this change, the project could be added as a reference in the C# project.
It is because of #user1610015's answer that I realised I was actually developing native Win RT code, not managed code, which lead me to try this solution - thanks!
The /ZW flag is for C++/CX projects. C++/CX is almost identical in syntax to managed C++ (C++/CLI), except that C++/CX is completely unmanaged. This may be what made you think you were developing managed C++, when in fact you weren't.
I haven't used C++/CX, but from what I've heard, Windows Runtime classes are COM classes. So I think you can use the TlbImp.exe tool from the Windows SDK to create a managed DLL from your unmanaged DLL, which you can then reference from your C# project. Try it and let me know if it works.
Another option is to talk to the Windows Runtime without C++/CX. While C++/CX makes Windows Runtime programming a lot easier, it's not strictly necessary. You can also use the WRL library. Since the WRL library is pure C++, it should also be usable from C++/CLI.

WinRT and DLLs: What exactly am I allowed to use?

It's not all together clear to me, so I am hoping someone here knows the answer. I am using the C# Json.Net and the C# HtmlAgilityPack both built from sources for "Any CPU". I've noticed that both of these include using directives that reference assemblies that don't seem to be available in Metro yet they both build fine.
If I reference them, does this mean my app will thunk to unmanaged code?
What exactly causes thunking to unmanged code?
Why are DLLs allowed to reference assemblies that are not available to WinRT and my app is not?
Will this fail the windows store approval process?
What are the general rules for DLLs I include with my app that I need to worry about?
Thanks in advance!
When developing apps that target WinRT, the app should only use the API's available in Windows 8 WinRT. The API's are defined in WinMD files. If the app used the desktop API's, then it will be rejected during the Windows store approval process.
Imagine this scenaio. You developed a WinRT app that uses .NET DLL's from desktop mode (client profile). The app is deployed in Windows store and user downloads it on ARM tablet. The application will crash as it does not have the desktop (client) .NET DLL's on the ARM devices.
so this brings us to the question on what .NET classes we can use while developing apps for WinRT. The article http://kishore1021.wordpress.com/2012/08/06/what-is-portable-class-library-project-in-visual-studio-2012-net-4-5/ lists the .NET classes available for WinRT application development.
Change all open source projects dependencies to target WinRT. See if some methods / classes in WinRT are missing so the code does not compile. Try to find the alternative methods/classes.
Such as List.FindAll(), change to Linq Where()

Categories