I have an simple FM Radio Tuner App in Silverlight 5 Out-of-browser that calls code from a Native C++ DLL from my USB FM Receiver using PInvoke. This application works very fine in Windows 8 with Silverlight5.
Now I'm trying to port it to a Metro App using WinRT.
The migration from Silverlight to XAML UI is pretty easy and worked well. The PInvoke signatures and attributes was detected fine with the namespace System.Runtime.InteropServices and the DLLImport attribute.
The problem is that when I'm running the App and call any method from the PInvoked native DLL that used to work in my SL5 app(that works fine even on Windows8), I have this exception:
System.DllNotFoundException was unhandled by user code Message=Unable to load DLL 'CarTFTFM.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) Source=metroradio TypeName="" StackTrace: at MetroRadio.FMRadio.HWInit2(Int32 port, Int32 initVolume) at MetroRadio.MediaService.InitializeRadio() in c:\Users\Gutemberg\Documents\Visual Studio 11\Projects\MetroRadio\MetroRadio\MediaService.cs:line 160 at MetroRadio.MainPage.radio_Click(Object sender, RoutedEventArgs e) in c:\Users\Gutemberg\Documents\Visual Studio 11\Projects\MetroRadio\MetroRadio\MainPage.xaml.cs:line 43 InnerException: So, my question is, what is the problem on this PInvoke? Since it Works well on Windows8 with a SL5 app, I dont see any reasons to have problems with WinRT/Metro Apps.
Answer: 1
Windows 8 Metro / WinRT applications run inside a sandboxed environment that does not have access to PInvoke or the Win32 API. This is a purposefull limitation of the platform for security reasons. This way they can "guarentee" the the security of apps distributed through the app store just the same as Google and Apple do on their platforms.
by : Chris Pietschmannhttp://stackoverflow.com/users/7831Answer: 2
As per Pavel Minaev's reply to Chris Pietschmann's answer:
P/Invoke and COM Interop are most certainly supported for .NET Metro apps. Win32 API is also supported, and can be called through the above technologies, though it is limited to those functions that are available to Metro apps (i.e. if a C++ Metro app can't call it, neither can a .NET app).
As Morten Frederiksen points out, it is however likely that CarTFTFM.dll contains an unsupported part of the Win32 API surface for WinRT:
by : David Cucciahttp://stackoverflow.com/users/22528Only a subset of Win32 and COM API is supported: msdn.microsoft.com/en-us/library/windows/apps/br205757
Answer: 3
Unless it is a system DLL or otherwise locatable through the system path, you need to make sure that your DLL is copied to the same folder as your Metro application is deployed in.
I solved the problem by adding the native DLL to my Metro application project, ensuring that Build Action is set to Content and that Copy to Output Directory is set to Copy Always or Copy if Newer.
by : Anders Gustafssonhttp://stackoverflow.com/users/650012
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog