12
votes

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"

1
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 codeproject.com/Articles/9826/…Robert H
"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
The exception that I get is "System.NotSupportedException"DeveloperLove
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

1 Answers

5
votes

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.