gpt4 book ai didi

silverlight - 使用 Windows 8/WinRT 在 Metro 应用中 PInvoke

转载 作者:行者123 更新时间:2023-12-02 21:50:06 26 4
gpt4 key购买 nike

我在 Silverlight 5 浏览器外有一个简单的 FM radio 应用程序,它使用 PInvoke 从我的 USB FM 接收器调用来自 native C++ DLL 的代码。该应用程序在带有 Silverlight5 的 Windows 8 中运行得非常好。

现在我正在尝试使用 WinRT 将其移植到 Metro 应用程序。

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

问题是,当我运行应用程序并调用曾经在我的 SL5 应用程序中工作的 PInvoked native DLL 中的任何方法(即使在 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: msdn.microsoft.com/en-us/library/windows/apps/br205757

关于silverlight - 使用 Windows 8/WinRT 在 Metro 应用中 PInvoke,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8881335/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com