Unable to use C++ dll in the windows phone 8 application.
-
Tuesday, December 11, 2012 12:23 PM
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.
All Replies
-
Tuesday, December 11, 2012 2:20 PMModerator
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.- Proposed As Answer by Dave Hunt (ProfEclipse)Banned Tuesday, December 11, 2012 3:09 PM
-
Wednesday, December 12, 2012 6:41 AM
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 3:44 PMModerator
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).aspxDllImport 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 11:57 PM
Do you mean DllImportAttribute that is clearly listed on that page you linked to?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).aspxDllImport isn't one of them.
-
Thursday, December 13, 2012 1:34 AM
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 8:27 AMNo 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:30 AM
I can see DllImport supported in the official list pointed by the above link!!
-
Thursday, December 13, 2012 11:59 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 12:48 PMThat'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 3:12 PMModeratorYes - 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.

