none
Unable to use C++ dll in the windows phone 8 application.

    Question

  • Hi folks,

    I am trying to use the native c++ dll compiled for Win32 platform using PInvoke. The native dll is a simple library which is returns some dummy values of native data types. The dll is working fine with the traditional Windows Forms Applications. But when I am trying to use the same dll in the Windows Phone 8 app, I am getting a runtime exception, "An exception of type 'System.NotSupportedException' occurred in Unknown Module. but was not handled in user code".

     
    [System.Runtime.InteropServices.DllImport("win32dll.dll", EntryPoint = "Hello")]
            private static extern int Hello();

    As one can see the InteropServices classes in Windows Phone 8 sdk, the PInvoke must be supported! am I going wrong some where? Can some one give me sample windows Phone 8 app project which is using native C++ dll.

    Tuesday, December 11, 2012 12:23 PM

Answers

  • The dll is working on the following platforms except Windows Phone 8:

    • Windows Forms Application / .Net Framework
    • Windows Store Apps

    However, The unmanaged code is working now in windows phone 8 this way:

    • Compile the c++ source code as .Lib/.h files
    • Create a Window Phone Runtime Component Wrapper
    • Add the assembly to the reference in the Windows Phone Application

    I suppose one has to rely on Windows Runtime Component till the DllImport issue gets fixed in Windows Phone 8.

    • Marked as answer by Ameem Thursday, December 13, 2012 12:00 PM
    Thursday, December 13, 2012 11:59 AM

All replies

  • You can't run dlls compiled for Windows on an ARM device. 


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, December 11, 2012 2:20 PM
  • Sorry for using the confusing name of the dll.

    I already compiled the source code to the ARM architecture and generated the ARM dll. But still same exception is coming!


    • Edited by Ameem Wednesday, December 12, 2012 6:42 AM
    Wednesday, December 12, 2012 6:41 AM
  • Here's the official list of InteropServices classes supported by the phone:
    http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.runtime.interopservices(v=vs.105).aspx

    DllImport isn't one of them.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, December 12, 2012 3:44 PM
  • Here's the official list of InteropServices classes supported by the phone:
    http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.runtime.interopservices(v=vs.105).aspx

    DllImport isn't one of them.

    Do you mean DllImportAttribute that is clearly listed on that page you linked to?
    Wednesday, December 12, 2012 11:57 PM
  • Is your dll calling a Win32 API that is not in the list of Supported Win32 APIs for Windows Phone 8?

    Thursday, December 13, 2012 1:34 AM
  • No its not using any Win32 API calls. As mentioned, The native dll is a simple library which is returns some dummy values of native data types. It would be better if any one can post a link where I can download the sample Windows Phone 8 Project which is successfully able to load the unmanaged dynamic link library. I guess there are some issues with importing of unmanaged code, that is why I am not able to find even a single working project which is successfully able to interop unmanaged dll for WP8.
    Thursday, December 13, 2012 8:27 AM
  • I can see DllImport supported in the official list pointed by the above link!!

    Thursday, December 13, 2012 8:30 AM
  • The dll is working on the following platforms except Windows Phone 8:

    • Windows Forms Application / .Net Framework
    • Windows Store Apps

    However, The unmanaged code is working now in windows phone 8 this way:

    • Compile the c++ source code as .Lib/.h files
    • Create a Window Phone Runtime Component Wrapper
    • Add the assembly to the reference in the Windows Phone Application

    I suppose one has to rely on Windows Runtime Component till the DllImport issue gets fixed in Windows Phone 8.

    • Marked as answer by Ameem Thursday, December 13, 2012 12:00 PM
    Thursday, December 13, 2012 11:59 AM
  • That's right.  I remember now.  Interop is broken on Windows Phone 8.  That's why SharpDX had to create a small C++ WinPRT component to interop with DirectX.  Microsoft have admitted that interop was broken and that it will be fixed in a future release.
    Thursday, December 13, 2012 12:48 PM
  • Yes - sorry I wasn't thinking clearly that it was an attribute - I was looking for method names.  My apologies.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, December 13, 2012 3:12 PM
  • is there any progress on this ?
    or a link to the bug page so one can track its progress? 

    AbdelRahman Salah.

    Monday, June 24, 2013 4:00 PM
  • is it true, that Interop is broken ? i'm stuck with the same issue

    AbdelRahman Salah.

    Monday, June 24, 2013 4:08 PM
  • I think it has to work somehow.

    Nokia has recently published the Nokia Imaging SDK for WP8 and the core routines are C++ native code that exist in ARM for the device and x86 for the Emulator.

    Haven't looked into the details yet but Looks like what you want to do with your dll, right?

    Thomas

    Wednesday, August 28, 2013 11:59 AM