[UWP]如何使用C ++插件扩展winrt组件? [英] [UWP] How to extend a winrt component with C++ plugins ?

查看:75
本文介绍了[UWP]如何使用C ++插件扩展winrt组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我正在寻找一种能够通过C ++插件扩展组件的方法。

我找到了一种方法,但我认为它违反了WinRT组件的ABI限制,而且我使用的是Windows运行时元数据验证禁止的Platform :: IntPtr。



我知道我可以从我的组件中加载带有LoadPackagedLibrary的DLL,但是我不知道如何公开插件,因为原始指针无法通过ABI。


解决方案


Hi Tryum,


< p style ="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; background:white">



首先,要在UWP应用程序中使用现有的C ++ DLL,您需要注意"如果您只是尝试将通用Windows项目的引用添加到经典桌面库,那么
会收到错误消息表示库不兼容。对于静态库,只需将库(.lib文件)添加到链接器输入就可以链接到库,就像在传统的Win32应用程序中一样。
只有一个二进制文件可用,这是唯一的选项。静态库链接到你的应用程序的可执行文件,但你在UWP应用程序中使用的Win32 DLL必须通过将它包含在项目中并打包到应用程序中将其标记为内容。要在UWP应用程序中加载Win32
DLL,您还必须调用LoadPackagedLibrary而不是LoadLibrary或LoadLibraryEx。"
  请参考 H通过:在通用Windows平台应用程序中使用现有C ++代码获取更多
信息。



您已经知道可以尝试使用
加载DLL
LoadPackagedLibrary函数
,您可以尝试使用
GetProcAddress函数
,因为它
适用于带导出的经典DLL



如果此功能对您的方案不起作用,您可以查看此文档:

将C ++库移植到Windows运行时组件







最好的问候,





罗伊


Hello,

I'm looking for a way to give the ability to a component to be extended via C++ plugins.
I found a way of doing so, but I think it violates WinRT components ABI restrictions, and I'm using Platform::IntPtr which are forbidden by the Windows Runtime Metadata Validation.

I know I can load a DLL with LoadPackagedLibrary from within my component, but then I'm out of idea on how to expose the plugin as the raw pointer cannot pass the ABI.

解决方案

Hi Tryum,

First, to use existing C++ DLL in UWP apps, you need notice that "If you just try to add a reference from a Universal Windows Project to a classic desktop library, you get an error message that says the library is not compatible. In the case of a static library, you can link to your library simply by adding the library (.lib file) to your linker input, just as you would in a classic Win32 application. For libraries where only a binary is available, this is the only option. A static library is linked into your app's executable, but a Win32 DLL that you consume in a UWP app must be packaged into the app by including it in the project and marking it as Content. To load a Win32 DLL in a UWP app, you also have to call LoadPackagedLibrary instead of LoadLibrary or LoadLibraryEx."  Please refer How to: Use Existing C++ Code in a Universal Windows Platform App for more information.

As you have already know that you could try to load the DLL with LoadPackagedLibrary function, you could try to use GetProcAddress function as it should work for classic DLLs with exports.

If this function does not work for your scenario, you might take a look at this document: Porting a C++ Library to a Windows Runtime Component

Best regards,

Roy


这篇关于[UWP]如何使用C ++插件扩展winrt组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆