12

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"

Ken Kin
  • 4,503
  • 3
  • 38
  • 76
DeveloperLove
  • 567
  • 2
  • 8
  • 16
  • I'm sure this question has been asked a whole bunch of times so it may be closed as a duplicate; however I did a quick google search and yielded http://www.codeproject.com/Articles/9826/How-to-create-a-DLL-library-in-C-and-then-use-it-w – Robert H Nov 20 '12 at 13:26
  • "When I try to access the method of a dll it shows an exception" It's no fun for us that we have to try and guess what the exception is. You can see it we can't. Don't conceal the information from us. – David Heffernan Nov 20 '12 at 13:28
  • The exception that I get is "System.NotSupportedException" – DeveloperLove Nov 20 '12 at 13:38
  • possible duplicate of [using a class defined in a c++ dll in c# code](http://stackoverflow.com/questions/315051/using-a-class-defined-in-a-c-dll-in-c-sharp-code) – dda Nov 20 '12 at 14:55
  • 1
    How was the DLL built? Was it built for the correct CPU architecture for what you're trying to run (ARM for device, X86 for emulator)? Is it built against Windows Phone 8 headers and libraries or against full Windows? – Paul Annetts Nov 20 '12 at 15:15
  • Not all windows dll's will work on mobile devices. They can depend on different hardware. Your error is quite clear about that.. – user613326 Feb 10 '13 at 00:41
  • Not done much with Windows 8 yet, however @Iris-Classon had a post a while back about using SQLite on Windows 8, which is C++ based. May be of use: http://www.irisclasson.com/2012/10/02/winrt-app-guide-step-10-adding-a-lightweight-database-sqlite-and-crud-support-two-way-element-binding/ – Simon Bull Feb 13 '13 at 13:04

1 Answers1

5

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.

vidstige
  • 12,492
  • 9
  • 66
  • 110