我在Silverlight 5中有一个简单的FM收音机调谐器应用程序,它使用PInvoke从我的USB FM接收器调用本机C++ DLL中的代码。此应用程序在Windows 8和Silverlight5中运行得非常好。使用Windows 8/WinRT在Metro应用程序中启用
现在我试图使用WinRT将它移植到Metro应用程序。
从Silverlight到XAML UI的迁移非常简单,并且运行良好。使用命名空间System.Runtime.InteropServices和DLLImport属性可以很好地检测到PInvoke签名和属性。
的问题是,当我运行应用程序并调用从使用在我的SL5的应用程序(甚至在Windows8中正常工作)工作PInvoked本地DLL的任何方法,我有这样的例外:
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:
所以,我的问题是,这个PInvoke有什么问题?由于它适用于Windows8和SL5应用程序,因此我没有看到任何有关WinRT/Metro应用程序出现问题的原因。
包声明中缺少声音,如DLL。当前的文档太模糊,无法提供良好的链接。 – 2012-01-16 15:09:45
看看这个问题:http://stackoverflow.com/questions/7807361/how-to-p-invoke-to-a-native-dll-from-metro – 2012-01-16 15:26:30
声音相似,但仍然没有成功... – 2012-01-16 15:50:54