How to add a C++ DLL in Windows Phone 8 (C#) Framework

DeveloperLove picture DeveloperLove · Nov 20, 2012 · Viewed 9.2k times · Source

I am trying to add a C++ DLL to Windows Phone 8 framework in Visual Studio Express 2012.

I have tried following ways

  1. Import and invoke through PInvoke

    [DllImport("WP8DLL.dll", CallingConvention = CallingConvention.Cdecl)]

    public static extern int functionReturningInteger();

    Result: This way though there were no compile errors, but when I try to access the method of the DLL it throws System.NotSupportedException.

  2. Adding reference in the project properties

    Result: I get the message "A reference to a higher version or incompatible assembly cannot be added to the project"

Answer

vidstige picture vidstige · Feb 13, 2013

You cannot add a reference from a Managed Windows Phone 8 Project directly to a native static or native dynamic library. You will need to create a Windows Phone Runtime Component. Those can be referenced by you UI project and also it can reference C++ projects, etc.

See for example this link for more information.