微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

silverlight – 使用Windows 8 / WinRT的Metro应用程序中的PInvoke

我在Silverlight 5浏览器中有一个简单的FM收音机调谐器应用程序,它使用PInvoke从我的USB FM接收器调用来自Native C DLL的代码.此应用程序在Windows 8中使用Silverlight5非常好.

现在我正在尝试使用WinRT将其移植到Metro App.

从Silverlight迁移到XAML UI非常简单且运行良好.使用命名空间System.Runtime.InteropServices和DLLImport属性检测到PInvoke签名和属性.

问题是,当我运行应用程序并从PInvoked本机DLL中调用任何方法时,我在SL5应用程序中工作(即使在Windows8上也能正常工作),我有以下异常:

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有什么问题?由于它在带有SL5应用程序的Windows8上运行良好,我没有看到任何与WinRT / Metro应用程序有问题的原因.

解决方法

根据 Pavel Minaev对Chris Pietschmann回答的回复

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).

正如Morten Frederiksen指出的那样,CarTFTFM.dll可能包含WinRT的Win32 API表面不受支持的部分:

Only a subset of Win32 and COM API is supported: 07002

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐